Skip to content

Commit d5c9fe7

Browse files
committed
Textile reader: improve parsing of spans.
The span needs to be separated from its surroundings by spaces. Also, a span can have attributes, which we now attach. Closes #9878.
1 parent 9acff99 commit d5c9fe7

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/Text/Pandoc/Readers/Textile.hs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ inlineParsers = [ str
501501
, endline
502502
, code
503503
, escapedInline
504+
, spanGroup
504505
, inlineMarkup
505506
, groupedInlineMarkup
506507
, rawHtmlInline
@@ -525,9 +526,21 @@ inlineMarkup = choice [ simpleInline (string "??") (B.cite [])
525526
, simpleInline (char '-' <* notFollowedBy (char '-')) B.strikeout
526527
, simpleInline (char '^') B.superscript
527528
, simpleInline (char '~') B.subscript
528-
, simpleInline (char '%') id
529529
]
530530

531+
-- "The <span> tag is created by percent % signs between whitespaces."
532+
-- e.g. My mother has %{color:green;}green% eyes.
533+
spanGroup :: PandocMonad m => TextileParser m Inlines
534+
spanGroup = try $ do
535+
notAfterString >>= guard
536+
char '%' *> notFollowedBy whitespace
537+
attr <- option nullAttr attributes
538+
contents <- mconcat <$> manyTill
539+
(try (((B.space <>) <$> try (whitespace *> notFollowedBy newline *> inline))
540+
<|> try (notFollowedBy newline *> inline)))
541+
(try (char '%' <* lookAhead (newline <|> ' ' <$ whitespace)))
542+
pure $ B.spanWith attr contents
543+
531544
-- | Trademark, registered, copyright
532545
mark :: PandocMonad m => TextileParser m Inlines
533546
mark = try $ char '(' >> (try tm <|> try reg <|> copy)
@@ -778,14 +791,14 @@ simpleInline :: PandocMonad m
778791
-> (Inlines -> Inlines) -- ^ Inline constructor
779792
-> TextileParser m Inlines -- ^ content parser (to be used repeatedly)
780793
simpleInline border construct = try $ do
781-
notAfterString
794+
notAfterString >>= guard
782795
border *> notFollowedBy (oneOf " \t\n\r")
783796
attr <- attributes
784797
body <- trimInlines . mconcat <$>
785798
withQuoteContext InSingleQuote
786799
(manyTill (((B.space <>) <$>
787-
(whitespace *> notFollowedBy newline >> inline))
788-
<|> (notFollowedBy newline >> inline))
800+
try (whitespace *> notFollowedBy newline >> inline))
801+
<|> try (notFollowedBy newline >> inline))
789802
(try border <* notFollowedBy alphaNum))
790803
return $ construct $
791804
if attr == nullAttr

test/command/9878.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@
44
^D
55
[ Para [ Str "15%" , Space , Str "50%" ] ]
66
```
7+
```
8+
% pandoc -f textile -t native
9+
15%. 70%
10+
^D
11+
[ Para [ Str "15%." , Space , Str "70%" ] ]
12+
```

0 commit comments

Comments
 (0)