git.iko.soy/typeable/pandoc
on master help sign in
Textile reader: Better support for attributes.

Instead of being ignored, attributes are now parsed and included in Span inlines. The output will be a bit different from stock textile: e.g. for `*(foo)hi*`, we'll get `<em><span class="foo">hi</span></em>` instead of `<em class="foo">hi</em>`. But at least the data is not lost.

commit24f438aa5f230464d510fae034c94644c0e181ca authorJohn MacFarlane <fiddlosopher@gmail.com> dateSat 5 Apr 2014, 21:02 (13 years ago) parent060a76a
2 files changed+13−10
src/Text/Pandoc/Readers/Textile.hs+12−9 tests/textile-reader.native+1−1
src/Text/Pandoc/Readers/Textile.hs+12−9
@@ -604,15 +604,18 @@ ungroupedSimpleInline border construct = try $ do
604604 guard $ (stateQuoteContext st /= NoQuote)
605605 || (sourceColumn pos == 1)
606606 || isWhitespace
607− body <- surrounded border inlineWithAttribute
608− lookAhead (notFollowedBy alphaNum)
609− let result = construct $ mconcat body
610− return $ if isWhitespace then B.space <> result
611− else result
612− where
613− inlineWithAttribute = (try $ optional attributes) >> notFollowedBy (string "\n\n")
614− >> (withQuoteContext InSingleQuote inline)
615−
607+ border *> notFollowedBy (oneOf " \t\n\r")
608+ attr <- attributes
609+ body <- trimInlines . mconcat <$>
610+ withQuoteContext InSingleQuote
611+ (manyTill inline (try border <* notFollowedBy alphaNum))
612+ let result = construct $
613+ if attr == nullAttr
614+ then body
615+ else B.spanWith attr body
616+ return $ if isWhitespace
617+ then B.space <> result
618+ else result
616619
617620groupedSimpleInline :: Parser [Char] ParserState t
618621 -> (Inlines -> Inlines)
tests/textile-reader.native+1−1
@@ -124,7 +124,7 @@ Pandoc (Meta {unMeta = fromList []})
124124,Para [Str "Textile",Space,Str "inline",Space,Str "image",Space,Str "syntax,",Space,Str "like",LineBreak,Str "here",Space,Image [Str "this is the alt text"] ("this_is_an_image.png","this is the alt text"),LineBreak,Str "and",Space,Str "here",Space,Image [Str ""] ("this_is_an_image.png",""),Str "."]
125125,Header 1 ("attributes",[],[]) [Str "Attributes"]
126126,Header 2 ("ident",["bar","foo"],[("style","color:red"),("lang","en")]) [Str "HTML",Space,Str "and",Space,Str "CSS",Space,Str "attributes",Space,Str "are",Space,Str "parsed",Space,Str "in",Space,Str "headers."]
127−,Para [Str "as",Space,Str "well",Space,Str "as",Space,Strong [Str "inline",Space,Str "attributes"],Space,Str "of",Space,Str "all",Space,Str "kind"]
127+,Para [Str "as",Space,Str "well",Space,Str "as",Space,Strong [Span ("",["foo"],[]) [Str "inline",Space,Str "attributes"]],Space,Str "of",Space,Span ("",[],[("style","color:red")]) [Str "all",Space,Str "kind"]]
128128,Para [Str "and",Space,Str "paragraph",Space,Str "attributes,",Space,Str "and",Space,Str "table",Space,Str "attributes."]
129129,Table [] [AlignDefault,AlignDefault,AlignDefault] [0.0,0.0,0.0]
130130 []