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.
This commit is contained in:
parent
060a76a38e
commit
24f438aa5f
2 changed files with 13 additions and 10 deletions
|
@ -604,15 +604,18 @@ ungroupedSimpleInline border construct = try $ do
|
|||
guard $ (stateQuoteContext st /= NoQuote)
|
||||
|| (sourceColumn pos == 1)
|
||||
|| isWhitespace
|
||||
body <- surrounded border inlineWithAttribute
|
||||
lookAhead (notFollowedBy alphaNum)
|
||||
let result = construct $ mconcat body
|
||||
return $ if isWhitespace then B.space <> result
|
||||
else result
|
||||
where
|
||||
inlineWithAttribute = (try $ optional attributes) >> notFollowedBy (string "\n\n")
|
||||
>> (withQuoteContext InSingleQuote inline)
|
||||
|
||||
border *> notFollowedBy (oneOf " \t\n\r")
|
||||
attr <- attributes
|
||||
body <- trimInlines . mconcat <$>
|
||||
withQuoteContext InSingleQuote
|
||||
(manyTill inline (try border <* notFollowedBy alphaNum))
|
||||
let result = construct $
|
||||
if attr == nullAttr
|
||||
then body
|
||||
else B.spanWith attr body
|
||||
return $ if isWhitespace
|
||||
then B.space <> result
|
||||
else result
|
||||
|
||||
groupedSimpleInline :: Parser [Char] ParserState t
|
||||
-> (Inlines -> Inlines)
|
||||
|
|
|
@ -124,7 +124,7 @@ Pandoc (Meta {unMeta = fromList []})
|
|||
,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 "."]
|
||||
,Header 1 ("attributes",[],[]) [Str "Attributes"]
|
||||
,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."]
|
||||
,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"]
|
||||
,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"]]
|
||||
,Para [Str "and",Space,Str "paragraph",Space,Str "attributes,",Space,Str "and",Space,Str "table",Space,Str "attributes."]
|
||||
,Table [] [AlignDefault,AlignDefault,AlignDefault] [0.0,0.0,0.0]
|
||||
[]
|
||||
|
|
Loading…
Reference in a new issue