@@ -105,6 +105,10 @@ instance HasMeta OrgParserState where
105 deleteMeta field st =
105 deleteMeta field st =
106 st{ orgStateMeta = deleteMeta field $ orgStateMeta st }
106 st{ orgStateMeta = deleteMeta field $ orgStateMeta st }
108+instance HasLastStrPosition OrgParserState where
109+ getLastStrPos = orgStateLastStrPos
110+ setLastStrPos pos st = st{ orgStateLastStrPos = Just pos }
108instance Default OrgParserState where
112instance Default OrgParserState where
109 def = defaultOrgParserState
113 def = defaultOrgParserState
@@ -865,6 +869,7 @@ inline :: OrgParser (F Inlines)
866 choice [ whitespace
870 choice [ whitespace
867 , linebreak
871 , linebreak
868 , footnote
873 , footnote
869 , linkOrImage
874 , linkOrImage
@@ -929,6 +934,51 @@ endline = try $ do
929 updateLastPreCharPos
934 updateLastPreCharPos
930 return . return $ B.space
935 return . return $ B.space
937+cite :: OrgParser (F Inlines)
939+ guardEnabled Ext_citations
940+ (cs, raw) <- withRaw normalCite
941+ return $ (flip B.cite (B.text raw)) <$> cs
943+normalCite :: OrgParser (F [Citation])
944+normalCite = try $ char '['
950+citeList :: OrgParser (F [Citation])
951+citeList = sequence <$> sepBy1 citation (try $ char ';' *> skipSpaces)
953+citation :: OrgParser (F Citation)
956+ (suppress_author, key) <- citeKey
961+ return $ Citation{ citationId = key
962+ , citationPrefix = B.toList x
963+ , citationSuffix = B.toList y
964+ , citationMode = if suppress_author
967+ , citationNoteNum = 0
971+ prefix = trimInlinesF . mconcat <$>
972+ manyTill inline (char ']' <|> (']' <$ lookAhead citeKey))
974+ hasSpace <- option False (notFollowedBy nonspaceChar >> return True)
976+ rest <- trimInlinesF . mconcat <$>
977+ many (notFollowedBy (oneOf ";]") *> inline)
978+ return $ if hasSpace
979+ then (B.space <>) <$> rest
932footnote :: OrgParser (F Inlines)
982footnote :: OrgParser (F Inlines)
933footnote = try $ inlineNote <|> referencedNote
983footnote = try $ inlineNote <|> referencedNote
@@ -1003,7 +1053,7 @@ selfTarget :: OrgParser String
1003selfTarget = try $ char '[' *> linkTarget <* char ']'
1053selfTarget = try $ char '[' *> linkTarget <* char ']'
1005linkTarget :: OrgParser String
1055linkTarget :: OrgParser String
1006−linkTarget = enclosed (char '[') (char ']') (noneOf "\n\r[]")
1056+linkTarget = enclosedByPair '[' ']' (noneOf "\n\r[]")
1008applyCustomLinkFormat :: String -> OrgParser (F String)
1058applyCustomLinkFormat :: String -> OrgParser (F String)
1009applyCustomLinkFormat link = do
1059applyCustomLinkFormat link = do
@@ -1079,7 +1129,12 @@ inlineCodeBlock = try $ do
1079 let attrClasses = [translateLang lang, rundocBlockClass]
1129 let attrClasses = [translateLang lang, rundocBlockClass]
1080 let attrKeyVal = map toRundocAttrib (("language", lang) : opts)
1130 let attrKeyVal = map toRundocAttrib (("language", lang) : opts)
1081 returnF $ B.codeWith ("", attrClasses, attrKeyVal) inlineCode
1131 returnF $ B.codeWith ("", attrClasses, attrKeyVal) inlineCode
1133+enclosedByPair :: Char -- ^ opening char
1134+ -> Char -- ^ closing char
1135+ -> OrgParser a -- ^ parser
1082− where enclosedByPair s e p = char s *> many1Till p (char e)
1137+enclosedByPair s e p = char s *> many1Till p (char e)
1084emph :: OrgParser (F Inlines)
1139emph :: OrgParser (F Inlines)
1085emph = fmap B.emph <$> emphasisBetween '/'
1140emph = fmap B.emph <$> emphasisBetween '/'
@@ -1274,13 +1329,6 @@ afterEmphasisPreChar = do
1274 lastPrePos <- orgStateLastPreCharPos <$> getState
1329 lastPrePos <- orgStateLastPreCharPos <$> getState
1275 return . fromMaybe True $ (== pos) <$> lastPrePos
1330 return . fromMaybe True $ (== pos) <$> lastPrePos
1277−-- | Whether we are right after the end of a string
1278−notAfterString :: OrgParser Bool
1281− lastStrPos <- orgStateLastStrPos <$> getState
1282− return $ lastStrPos /= Just pos
1284-- | Whether the parser is right after a forbidden border char
1332-- | Whether the parser is right after a forbidden border char
1285notAfterForbiddenBorderChar :: OrgParser Bool
1333notAfterForbiddenBorderChar :: OrgParser Bool
1286notAfterForbiddenBorderChar = do
1334notAfterForbiddenBorderChar = do