diff options
| author | John MacFarlane <[email protected]> | 2024-12-17 22:45:51 -0800 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2024-12-17 23:07:04 -0800 |
| commit | 484b337b2bc8fd9d8aa65e6ecb909eec1092b58f (patch) | |
| tree | b36c1f8560a2d5d9990631136381eb35b4b6b8cd | |
| parent | 9acff9924fb7e4c7f53e41f38d4b05361c3708af (diff) | |
Textile reader: improve parsing of spans.issue9878
The span needs to be separated from its surroundings by spaces.
Also, a span can have attributes, which we now attach.
Closes #9878.
| -rw-r--r-- | src/Text/Pandoc/Readers/Textile.hs | 21 | ||||
| -rw-r--r-- | test/command/9878.md | 6 |
2 files changed, 23 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Readers/Textile.hs b/src/Text/Pandoc/Readers/Textile.hs index 4395495bc..f6a73d641 100644 --- a/src/Text/Pandoc/Readers/Textile.hs +++ b/src/Text/Pandoc/Readers/Textile.hs @@ -501,6 +501,7 @@ inlineParsers = [ str , endline , code , escapedInline + , spanGroup , inlineMarkup , groupedInlineMarkup , rawHtmlInline @@ -525,9 +526,21 @@ inlineMarkup = choice [ simpleInline (string "??") (B.cite []) , simpleInline (char '-' <* notFollowedBy (char '-')) B.strikeout , simpleInline (char '^') B.superscript , simpleInline (char '~') B.subscript - , simpleInline (char '%') id ] +-- "The <span> tag is created by percent % signs between whitespaces." +-- e.g. My mother has %{color:green;}green% eyes. +spanGroup :: PandocMonad m => TextileParser m Inlines +spanGroup = try $ do + notAfterString >>= guard + char '%' *> notFollowedBy whitespace + attr <- option nullAttr attributes + contents <- mconcat <$> manyTill + (try (((B.space <>) <$> try (whitespace *> notFollowedBy newline *> inline)) + <|> try (notFollowedBy newline *> inline))) + (try (char '%' <* lookAhead (newline <|> ' ' <$ whitespace))) + pure $ B.spanWith attr contents + -- | Trademark, registered, copyright mark :: PandocMonad m => TextileParser m Inlines mark = try $ char '(' >> (try tm <|> try reg <|> copy) @@ -778,14 +791,14 @@ simpleInline :: PandocMonad m -> (Inlines -> Inlines) -- ^ Inline constructor -> TextileParser m Inlines -- ^ content parser (to be used repeatedly) simpleInline border construct = try $ do - notAfterString + notAfterString >>= guard border *> notFollowedBy (oneOf " \t\n\r") attr <- attributes body <- trimInlines . mconcat <$> withQuoteContext InSingleQuote (manyTill (((B.space <>) <$> - (whitespace *> notFollowedBy newline >> inline)) - <|> (notFollowedBy newline >> inline)) + try (whitespace *> notFollowedBy newline >> inline)) + <|> try (notFollowedBy newline >> inline)) (try border <* notFollowedBy alphaNum)) return $ construct $ if attr == nullAttr diff --git a/test/command/9878.md b/test/command/9878.md index 2e1e8263e..da7bf9927 100644 --- a/test/command/9878.md +++ b/test/command/9878.md @@ -4,3 +4,9 @@ ^D [ Para [ Str "15%" , Space , Str "50%" ] ] ``` +``` +% pandoc -f textile -t native +15%. 70% +^D +[ Para [ Str "15%." , Space , Str "70%" ] ] +``` |
