git.iko.soy/typeable/pandoc
on master help sign in
Textile reader: Support `>`, `<`, `=`, `<>` text alignment attributes.

Closes #2674.

commita1021bdda6a1ca2c91d80b5e562a1fb6206bbbcf authorJohn MacFarlane <jgm@berkeley.edu> dateMon 25 Jan 2016, 09:34 (11 years ago) parent11c5831
3 files changed+30−4
src/Text/Pandoc/Readers/Textile.hs+19−2 tests/textile-reader.native+5−2 tests/textile-reader.textile+6
src/Text/Pandoc/Readers/Textile.hs+19−2
@@ -583,7 +583,18 @@ code2 = do
583583
584584-- | Html / CSS attributes
585585attributes :: Parser [Char] ParserState Attr
586−attributes = (foldl (flip ($)) ("",[],[])) `fmap` many attribute
586+attributes = (foldl (flip ($)) ("",[],[])) <$>
587+ try (do special <- option id specialAttribute
588+ attrs <- many attribute
589+ return (special : attrs))
590+
591+specialAttribute :: Parser [Char] ParserState (Attr -> Attr)
592+specialAttribute = do
593+ alignStr <- ("center" <$ char '=') <|>
594+ ("justify" <$ try (string "<>")) <|>
595+ ("right" <$ char '>') <|>
596+ ("left" <$ char '<')
597+ return $ addStyle ("text-align:" ++ alignStr)
587598
588599attribute :: Parser [Char] ParserState (Attr -> Attr)
589600attribute = classIdAttr <|> styleAttr <|> langAttr
@@ -602,7 +613,13 @@ classIdAttr = try $ do -- (class class #id)
602613styleAttr :: Parser [Char] ParserState (Attr -> Attr)
603614styleAttr = do
604615 style <- try $ enclosed (char '{') (char '}') anyChar'
605− return $ \(id',classes,keyvals) -> (id',classes,("style",style):keyvals)
616+ return $ addStyle style
617+
618+addStyle :: String -> Attr -> Attr
619+addStyle style (id',classes,keyvals) =
620+ (id',classes,keyvals')
621+ where keyvals' = ("style", style') : [(k,v) | (k,v) <- keyvals, k /= "style"]
622+ style' = style ++ ";" ++ concat [v | ("style",v) <- keyvals]
606623
607624langAttr :: Parser [Char] ParserState (Attr -> Attr)
608625langAttr = do
tests/textile-reader.native+5−2
@@ -132,8 +132,11 @@ Pandoc (Meta {unMeta = fromList []})
132132,Header 1 ("images",[],[]) [Str "Images"]
133133,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 "."]
134134,Header 1 ("attributes",[],[]) [Str "Attributes"]
135−,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."]
136−,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"]]
135+,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."]
136+,Header 2 ("centered",[],[("style","text-align:center;")]) [Str "Centered"]
137+,Header 2 ("right",[],[("style","text-align:right;")]) [Str "Right"]
138+,Header 2 ("justified",[],[("lang","en"),("style","color:blue;text-align:justify;")]) [Str "Justified"]
139+,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"]]
137140,Para [Str "and",Space,Str "paragraph",Space,Str "attributes,",Space,Str "and",Space,Str "table",Space,Str "attributes."]
138141,Table [] [AlignDefault,AlignDefault,AlignDefault] [0.0,0.0,0.0]
139142 []
tests/textile-reader.textile+6
@@ -207,6 +207,12 @@ h1. Attributes
207207
208208h2[en]{color:red}(foo bar #ident). HTML and CSS attributes are parsed in headers.
209209
210+h2=. Centered
211+
212+h2>. Right
213+
214+h2<>{color:blue}[en]. Justified
215+
210216as well as *(foo)inline attributes* of %{color:red} all kind%
211217
212218p{color:green}. and paragraph attributes, and table attributes.