diff options
author | John MacFarlane <jgm@berkeley.edu> | 2016-01-25 09:34:49 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2016-01-25 09:34:49 -0800 |
commit | a1021bdda6a1ca2c91d80b5e562a1fb6206bbbcf (patch) | |
tree | 0a4c9acfb2322177588b84ca350996f6e87c76c4 /src | |
parent | 11c5831a1ff8f71e2ff850e83f012ea57cc14243 (diff) | |
download | pandoc-a1021bdda6a1ca2c91d80b5e562a1fb6206bbbcf.tar.gz |
Textile reader: Support `>`, `<`, `=`, `<>` text alignment attributes.
Closes #2674.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Readers/Textile.hs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Readers/Textile.hs b/src/Text/Pandoc/Readers/Textile.hs index dd1d289a3..6f64540f8 100644 --- a/src/Text/Pandoc/Readers/Textile.hs +++ b/src/Text/Pandoc/Readers/Textile.hs @@ -583,7 +583,18 @@ code2 = do -- | Html / CSS attributes attributes :: Parser [Char] ParserState Attr -attributes = (foldl (flip ($)) ("",[],[])) `fmap` many attribute +attributes = (foldl (flip ($)) ("",[],[])) <$> + try (do special <- option id specialAttribute + attrs <- many attribute + return (special : attrs)) + +specialAttribute :: Parser [Char] ParserState (Attr -> Attr) +specialAttribute = do + alignStr <- ("center" <$ char '=') <|> + ("justify" <$ try (string "<>")) <|> + ("right" <$ char '>') <|> + ("left" <$ char '<') + return $ addStyle ("text-align:" ++ alignStr) attribute :: Parser [Char] ParserState (Attr -> Attr) attribute = classIdAttr <|> styleAttr <|> langAttr @@ -602,7 +613,13 @@ classIdAttr = try $ do -- (class class #id) styleAttr :: Parser [Char] ParserState (Attr -> Attr) styleAttr = do style <- try $ enclosed (char '{') (char '}') anyChar' - return $ \(id',classes,keyvals) -> (id',classes,("style",style):keyvals) + return $ addStyle style + +addStyle :: String -> Attr -> Attr +addStyle style (id',classes,keyvals) = + (id',classes,keyvals') + where keyvals' = ("style", style') : [(k,v) | (k,v) <- keyvals, k /= "style"] + style' = style ++ ";" ++ concat [v | ("style",v) <- keyvals] langAttr :: Parser [Char] ParserState (Attr -> Attr) langAttr = do |