diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2023-09-06 20:08:18 -0700 |
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2023-09-06 20:08:18 -0700 |
| commit | a4725671159b8e79f855c6fd0cdc9eb7cb2d1f7d (patch) | |
| tree | f7833d1b7807007fad43bc5774e03051ac7c5c10 /src | |
| parent | b7e1ce422c9a76dffe763a4d31e0952e415775cc (diff) | |
Org reader: factor out orgAnchor -> Org.Parsing.
A purely internal change. We will use this both in inline
and block parsing.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Readers/Org/Inlines.hs | 14 | ||||
| -rw-r--r-- | src/Text/Pandoc/Readers/Org/Parsing.hs | 14 |
2 files changed, 16 insertions, 12 deletions
diff --git a/src/Text/Pandoc/Readers/Org/Inlines.hs b/src/Text/Pandoc/Readers/Org/Inlines.hs index 1cb945c1e..c8ee80201 100644 --- a/src/Text/Pandoc/Readers/Org/Inlines.hs +++ b/src/Text/Pandoc/Readers/Org/Inlines.hs @@ -42,10 +42,6 @@ import qualified Data.Text as T -- -- Functions acting on the parser state -- -recordAnchorId :: PandocMonad m => Text -> OrgParser m () -recordAnchorId i = updateState $ \s -> - s{ orgStateAnchorIds = i : orgStateAnchorIds s } - pushToInlineCharStack :: PandocMonad m => Char -> OrgParser m () pushToInlineCharStack c = updateState $ \s -> s{ orgStateEmphasisCharStack = c:orgStateEmphasisCharStack s } @@ -513,15 +509,9 @@ internalLink link title = do -- @anchor-id@ contains spaces, we are more restrictive in what is accepted as -- an anchor. anchor :: PandocMonad m => OrgParser m (F Inlines) -anchor = try $ do - anchorId <- parseAnchor - recordAnchorId anchorId +anchor = do + anchorId <- orgAnchor returnF $ B.spanWith (solidify anchorId, [], []) mempty - where - parseAnchor = string "<<" - *> many1Char (noneOf "\t\n\r<>\"' ") - <* string ">>" - <* skipSpaces -- | Replace every char but [a-zA-Z0-9_.-:] with a hyphen '-'. This mirrors -- the org function @org-export-solidify-link-text@. diff --git a/src/Text/Pandoc/Readers/Org/Parsing.hs b/src/Text/Pandoc/Readers/Org/Parsing.hs index 2e4b12fae..f1ed9d22d 100644 --- a/src/Text/Pandoc/Readers/Org/Parsing.hs +++ b/src/Text/Pandoc/Readers/Org/Parsing.hs @@ -29,6 +29,7 @@ module Text.Pandoc.Readers.Org.Parsing , orgArgWordChar , orgTagWord , orgTagWordChar + , orgAnchor -- * Re-exports from Text.Pandoc.Parser , ParserContext (..) , textStr @@ -216,3 +217,16 @@ orgTagWord = many1Char orgTagWordChar orgTagWordChar :: Monad m => OrgParser m Char orgTagWordChar = alphaNum <|> oneOf "@%#_" + +orgAnchor :: Monad m => OrgParser m Text +orgAnchor = try $ do + string "<<" + anchorId <- many1Char (noneOf "\t\n\r<>\"' ") + string ">>" + skipSpaces + recordAnchorId anchorId + return anchorId + +recordAnchorId :: Monad m => Text -> OrgParser m () +recordAnchorId i = updateState $ \s -> + s{ orgStateAnchorIds = i : orgStateAnchorIds s } |
