diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2024-03-18 11:26:32 -0700 |
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2024-03-18 11:26:32 -0700 |
| commit | eca2c82abd9782b61b31093fb6cfa848cab57d96 (patch) | |
| tree | 522b022b9423f62c77a7ccbe2a58e80f072aa3aa /src/Text | |
| parent | c5c7022ac537ff98f625432fe70bcd5b491d1d96 (diff) | |
Export `isOrderedListMarker` from T.P.Writers.Shared.
[API change]
This was formerly in T.P.Writers.Markdown.Inline, but we need
to use it in the Typst writer too.
Diffstat (limited to 'src/Text')
| -rw-r--r-- | src/Text/Pandoc/Writers/Markdown/Inline.hs | 8 | ||||
| -rw-r--r-- | src/Text/Pandoc/Writers/Shared.hs | 10 |
2 files changed, 10 insertions, 8 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown/Inline.hs b/src/Text/Pandoc/Writers/Markdown/Inline.hs index 2091db842..05047a968 100644 --- a/src/Text/Pandoc/Writers/Markdown/Inline.hs +++ b/src/Text/Pandoc/Writers/Markdown/Inline.hs @@ -332,14 +332,6 @@ avoidBadWraps inListItem = go . toList toList (Concat a b) = a : toList b toList x = [x] -isOrderedListMarker :: Text -> Bool -isOrderedListMarker xs = not (T.null xs) && (T.last xs `elem` ['.',')']) && - isRight (runParser (anyOrderedListMarker >> eof) - defaultParserState "" xs) - where - isRight (Right _) = True - isRight (Left _) = False - -- | Convert Pandoc inline element to markdown. inlineToMarkdown :: PandocMonad m => WriterOptions -> Inline -> MD m (Doc Text) inlineToMarkdown opts (Span ("",["emoji"],kvs) [Str s]) = diff --git a/src/Text/Pandoc/Writers/Shared.hs b/src/Text/Pandoc/Writers/Shared.hs index 6e6e084f2..5675dabe3 100644 --- a/src/Text/Pandoc/Writers/Shared.hs +++ b/src/Text/Pandoc/Writers/Shared.hs @@ -44,11 +44,13 @@ module Text.Pandoc.Writers.Shared ( , splitSentences , ensureValidXmlIdentifiers , setupTranslations + , isOrderedListMarker ) where import Safe (lastMay) import qualified Data.ByteString.Lazy as BL import Control.Monad (zipWithM) +import Data.Either (isRight) import Data.Aeson (ToJSON (..), encode) import Data.Char (chr, ord, isSpace, isLetter, isUpper) import Data.List (groupBy, intersperse, transpose, foldl') @@ -61,6 +63,8 @@ import qualified Text.Pandoc.Builder as Builder import Text.Pandoc.CSS (cssAttributes) import Text.Pandoc.Definition import Text.Pandoc.Options +import Text.Pandoc.Parsing (runParser, eof, defaultParserState, + anyOrderedListMarker) import Text.DocLayout import Text.Pandoc.Shared (stringify, makeSections, blocksToInlines) import Text.Pandoc.Walk (Walkable(..)) @@ -626,3 +630,9 @@ setupTranslations meta = do "" -> pure defLang s -> fromMaybe defLang <$> toLang (Just s) setTranslations lang + +-- True if the string would count as a Markdown ordered list marker. +isOrderedListMarker :: Text -> Bool +isOrderedListMarker xs = not (T.null xs) && (T.last xs `elem` ['.',')']) && + isRight (runParser (anyOrderedListMarker >> eof) + defaultParserState "" xs) |
