diff options
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Definition.hs | 6 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/HTML.hs | 8 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/LaTeX.hs | 10 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 19 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/RST.hs | 12 | ||||
-rw-r--r-- | src/Text/Pandoc/Shared.hs | 4 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/LaTeX.hs | 10 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/Man.hs | 10 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/Markdown.hs | 21 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/RST.hs | 11 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/RTF.hs | 6 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/S5.hs | 8 |
12 files changed, 67 insertions, 58 deletions
diff --git a/src/Text/Pandoc/Definition.hs b/src/Text/Pandoc/Definition.hs index 94183c500..18af11b7f 100644 --- a/src/Text/Pandoc/Definition.hs +++ b/src/Text/Pandoc/Definition.hs @@ -37,9 +37,9 @@ data Pandoc = Pandoc Meta [Block] deriving (Eq, Read, Show, Typeable, Data) -- | Bibliographic information for the document: title (list of 'Inline'), -- authors (list of strings), date (string). -data Meta = Meta [Inline] -- title - [String] -- authors - String -- date +data Meta = Meta [Inline] -- title + [[Inline]] -- authors + [Inline] -- date deriving (Eq, Show, Read, Typeable, Data) -- | Alignment of a table column. diff --git a/src/Text/Pandoc/Readers/HTML.hs b/src/Text/Pandoc/Readers/HTML.hs index e6ca05d87..94cde2d8d 100644 --- a/src/Text/Pandoc/Readers/HTML.hs +++ b/src/Text/Pandoc/Readers/HTML.hs @@ -382,7 +382,7 @@ parseTitle = try $ do return contents -- parse header and return meta-information (for now, just title) -parseHead :: GenParser Char ParserState ([Inline], [a], [Char]) +parseHead :: GenParser Char ParserState Meta parseHead = try $ do htmlTag "head" spaces @@ -390,7 +390,7 @@ parseHead = try $ do contents <- option [] parseTitle skipMany nonTitleNonHead htmlEndTag "head" - return (contents, [], "") + return $ Meta contents [] [] skipHtmlTag :: String -> GenParser Char ParserState () skipHtmlTag tag = optional (htmlTag tag) @@ -409,7 +409,7 @@ parseHtml = do sepEndBy (choice [xmlDec, definition, htmlComment]) spaces skipHtmlTag "html" spaces - (title, authors, date) <- option ([], [], "") parseHead + meta <- option (Meta [] [] []) parseHead spaces skipHtmlTag "body" spaces @@ -420,7 +420,7 @@ parseHtml = do spaces optional (htmlEndTag "html" >> many anyChar) -- ignore anything after </html> eof - return $ Pandoc (Meta title authors date) blocks + return $ Pandoc meta blocks -- -- parsing blocks diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index b4c01fe19..cd1312966 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -317,19 +317,19 @@ title = try $ do authors :: GenParser Char ParserState Block authors = try $ do string "\\author{" - authors' <- manyTill anyChar (char '}') + authors' <- sepBy (many1 (notFollowedBy (oneOf "};,") >> inline)) (oneOf ",;") + char '}' spaces - let authors'' = map removeLeadingTrailingSpace $ lines $ - substitute "\\\\" "\n" authors' + let authors'' = map normalizeSpaces authors' updateState (\s -> s { stateAuthors = authors'' }) return Null date :: GenParser Char ParserState Block date = try $ do string "\\date{" - date' <- manyTill anyChar (char '}') + date' <- manyTill inline (char '}') spaces - updateState (\state -> state { stateDate = date' }) + updateState (\state -> state { stateDate = normalizeSpaces date' }) return Null -- diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 0de700537..8a09b191c 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -132,28 +132,27 @@ inlinesInBalancedBrackets parser = try $ do titleLine :: GenParser Char ParserState [Inline] titleLine = try $ char '%' >> skipSpaces >> manyTill inline newline -authorsLine :: GenParser Char st [String] +authorsLine :: GenParser Char ParserState [[Inline]] authorsLine = try $ do char '%' skipSpaces - authors <- sepEndBy (many1 (noneOf ",;\n")) (oneOf ",;") + authors <- sepEndBy (many1 (notFollowedBy (oneOf ",;\n") >> inline)) (oneOf ",;") newline - return $ map (decodeCharacterReferences . removeLeadingTrailingSpace) authors + return $ map normalizeSpaces authors -dateLine :: GenParser Char st String +dateLine :: GenParser Char ParserState [Inline] dateLine = try $ do char '%' skipSpaces - date <- many (noneOf "\n") - newline - return $ decodeCharacterReferences $ removeTrailingSpace date + date <- manyTill inline newline + return $ normalizeSpaces date -titleBlock :: GenParser Char ParserState ([Inline], [String], [Char]) +titleBlock :: GenParser Char ParserState ([Inline], [[Inline]], [Inline]) titleBlock = try $ do failIfStrict title <- option [] titleLine author <- option [] authorsLine - date <- option "" dateLine + date <- option [] dateLine optional blanklines return (title, author, date) @@ -175,7 +174,7 @@ parseMarkdown = do let reversedNotes = stateNotes st' updateState $ \s -> s { stateNotes = reverse reversedNotes } -- now parse it for real... - (title, author, date) <- option ([],[],"") titleBlock + (title, author, date) <- option ([],[],[]) titleBlock blocks <- parseBlocks return $ Pandoc (Meta title author date) $ filter (/= Null) blocks diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs index fd6127cae..2f9282584 100644 --- a/src/Text/Pandoc/Readers/RST.hs +++ b/src/Text/Pandoc/Readers/RST.hs @@ -33,7 +33,7 @@ module Text.Pandoc.Readers.RST ( import Text.Pandoc.Definition import Text.Pandoc.Shared import Text.ParserCombinators.Parsec -import Control.Monad ( when ) +import Control.Monad ( when, unless ) import Data.List ( findIndex, delete, intercalate ) -- | Parse reStructuredText string and return Pandoc document. @@ -157,11 +157,13 @@ fieldList = try $ do let authors = case lookup "Authors" items of Just auth -> [auth] Nothing -> map snd (filter (\(x,_) -> x == "Author") items) - if null authors - then return () - else updateState $ \st -> st {stateAuthors = authors} + unless (null authors) $ do + authors' <- mapM (parseFromString (many inline)) authors + updateState $ \st -> st {stateAuthors = map normalizeSpaces authors'} case (lookup "Date" items) of - Just dat -> updateState $ \st -> st {stateDate = dat} + Just dat -> do + dat' <- parseFromString (many inline) dat + updateState $ \st -> st{ stateDate = normalizeSpaces dat' } Nothing -> return () case (lookup "Title" items) of Just tit -> parseFromString (many inline) tit >>= diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index ddce396fb..ae14937d5 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -667,8 +667,8 @@ data ParserState = ParserState stateTabStop :: Int, -- ^ Tab stop stateStandalone :: Bool, -- ^ Parse bibliographic info? stateTitle :: [Inline], -- ^ Title of document - stateAuthors :: [String], -- ^ Authors of document - stateDate :: String, -- ^ Date of document + stateAuthors :: [[Inline]], -- ^ Authors of document + stateDate :: [Inline], -- ^ Date of document stateStrict :: Bool, -- ^ Use strict markdown syntax? stateSmart :: Bool, -- ^ Use smart typography? stateLiterateHaskell :: Bool, -- ^ Treat input as literate haskell diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index 92bf65b0a..f119598a6 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -53,15 +53,15 @@ writeLaTeX options document = pandocToLaTeX :: WriterOptions -> Pandoc -> State WriterState String pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do main <- liftM render $ blockListToLaTeX blocks - titletext <- if null title - then return "" - else liftM render $ inlineListToLaTeX title + titletext <- liftM render $ inlineListToLaTeX title + authorsText <- mapM (liftM render . inlineListToLaTeX) authors + dateText <- liftM render $ inlineListToLaTeX date let context = writerVariables options ++ [ ("toc", if writerTableOfContents options then "yes" else "") , ("body", main) , ("title", titletext) - , ("authors", intercalate "\\\\" $ map stringToLaTeX authors) - , ("date", stringToLaTeX date) ] + , ("authors", intercalate "\\\\" authorsText) + , ("date", dateText) ] return $ renderTemplate context $ writerTemplate options -- escape things as needed for LaTeX diff --git a/src/Text/Pandoc/Writers/Man.hs b/src/Text/Pandoc/Writers/Man.hs index 7a04e38c4..64fd24ad0 100644 --- a/src/Text/Pandoc/Writers/Man.hs +++ b/src/Text/Pandoc/Writers/Man.hs @@ -68,6 +68,8 @@ metaToMan :: WriterOptions -- ^ Options, including Man header -> State WriterState (Doc, Doc) metaToMan options (Meta title authors date) = do titleText <- inlineListToMan options title + authorsText <- mapM (inlineListToMan options) authors + dateText <- inlineListToMan options date let (cmdName, rest) = break (== ' ') $ render titleText let (title', section) = case reverse cmdName of (')':d:'(':xs) | d `elem` ['0'..'9'] -> @@ -76,11 +78,11 @@ metaToMan options (Meta title authors date) = do let extras = map (doubleQuotes . text . removeLeadingTrailingSpace) $ splitBy '|' rest let head' = (text ".TH") <+> title' <+> section <+> - doubleQuotes (text date) <+> hsep extras - let foot = case length authors of + doubleQuotes dateText <+> hsep extras + let foot = case length authorsText of 0 -> empty - 1 -> text ".SH AUTHOR" $$ (text $ intercalate ", " authors) - _ -> text ".SH AUTHORS" $$ (text $ intercalate ", " authors) + 1 -> text ".SH AUTHOR" $$ (hcat $ intersperse (text ", ") authorsText) + _ -> text ".SH AUTHORS" $$ (hcat $ intersperse (text ", ") authorsText) return $ if writerStandalone options then (head', foot) else (empty, empty) diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs index a72116376..266336968 100644 --- a/src/Text/Pandoc/Writers/Markdown.hs +++ b/src/Text/Pandoc/Writers/Markdown.hs @@ -109,8 +109,8 @@ metaToMarkdown :: WriterOptions -> Meta -> State WriterState Doc metaToMarkdown _ (Meta [] [] []) = return empty metaToMarkdown opts (Meta title authors date) = do title' <- titleToMarkdown opts title - authors' <- authorsToMarkdown authors - date' <- dateToMarkdown date + authors' <- authorsToMarkdown opts authors + date' <- dateToMarkdown opts date return $ title' $+$ authors' $+$ date' $+$ text "" titleToMarkdown :: WriterOptions -> [Inline] -> State WriterState Doc @@ -119,14 +119,17 @@ titleToMarkdown opts lst = do contents <- inlineListToMarkdown opts lst return $ text "% " <> contents -authorsToMarkdown :: [String] -> State WriterState Doc -authorsToMarkdown [] = return empty -authorsToMarkdown lst = return $ - text "% " <> text (intercalate ", " (map escapeString lst)) +authorsToMarkdown :: WriterOptions -> [[Inline]] -> State WriterState Doc +authorsToMarkdown opts [] = return empty +authorsToMarkdown opts lst = do + authors <- mapM (inlineListToMarkdown opts) lst + return $ text "% " <> (hcat $ intersperse (text ", ") authors) -dateToMarkdown :: String -> State WriterState Doc -dateToMarkdown [] = return empty -dateToMarkdown str = return $ text "% " <> text (escapeString str) +dateToMarkdown :: WriterOptions -> [Inline] -> State WriterState Doc +dateToMarkdown opts [] = return empty +dateToMarkdown opts str = do + date <- inlineListToMarkdown opts str + return $ text "% " <> date -- | Construct table of contents from list of header blocks. tableOfContents :: WriterOptions -> [Block] -> Doc diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs index a1c847385..2e01bb62e 100644 --- a/src/Text/Pandoc/Writers/RST.hs +++ b/src/Text/Pandoc/Writers/RST.hs @@ -150,15 +150,18 @@ titleToRST lst = do let border = text (replicate titleLength '=') return $ border $+$ contents $+$ border <> text "\n" -authorsToRST :: [String] -> State WriterState Doc +authorsToRST :: [[Inline]] -> State WriterState Doc authorsToRST [] = return empty authorsToRST (first:rest) = do rest' <- authorsToRST rest - return $ (text ":Author: " <> text first) $+$ rest' + first' <- inlineListToRST first + return $ (text ":Author: " <> first') $+$ rest' -dateToRST :: String -> State WriterState Doc +dateToRST :: [Inline] -> State WriterState Doc dateToRST [] = return empty -dateToRST str = return $ text ":Date: " <> text (escapeString str) +dateToRST str = do + date <- inlineListToRST str + return $ text ":Date: " <> date -- | Convert Pandoc block element to RST. blockToRST :: Block -- ^ Block element diff --git a/src/Text/Pandoc/Writers/RTF.hs b/src/Text/Pandoc/Writers/RTF.hs index a146d2133..3830be705 100644 --- a/src/Text/Pandoc/Writers/RTF.hs +++ b/src/Text/Pandoc/Writers/RTF.hs @@ -152,10 +152,10 @@ rtfHeader headerText (Meta title authors date) = authorstext = if null authors then "" else rtfPar 0 0 AlignCenter (" " ++ (intercalate "\\" $ - map stringToRTF authors)) - datetext = if date == "" + map inlineListToRTF authors)) + datetext = if null date then "" - else rtfPar 0 0 AlignCenter (" " ++ stringToRTF date) in + else rtfPar 0 0 AlignCenter (" " ++ inlineListToRTF date) in let spacer = if null (titletext ++ authorstext ++ datetext) then "" else rtfPar 0 0 AlignDefault "" in diff --git a/src/Text/Pandoc/Writers/S5.hs b/src/Text/Pandoc/Writers/S5.hs index 67ff673c2..c3acbfe71 100644 --- a/src/Text/Pandoc/Writers/S5.hs +++ b/src/Text/Pandoc/Writers/S5.hs @@ -85,9 +85,9 @@ writeS5String options = (writeHtmlString options) . insertS5Structure -- | Inserts HTML needed for an S5 presentation (e.g. around slides). layoutDiv :: [Inline] -- ^ Title of document (for header or footer) - -> String -- ^ Date of document (for header or footer) + -> [Inline] -- ^ Date of document (for header or footer) -> [Block] -- ^ List of block elements returned -layoutDiv title' date = [(RawHtml "<div class=\"layout\">\n<div id=\"controls\"></div>\n<div id=\"currentSlide\"></div>\n<div id=\"header\"></div>\n<div id=\"footer\">\n"), (Header 1 [Str date]), (Header 2 title'), (RawHtml "</div>\n</div>\n")] +layoutDiv title' date = [(RawHtml "<div class=\"layout\">\n<div id=\"controls\"></div>\n<div id=\"currentSlide\"></div>\n<div id=\"header\"></div>\n<div id=\"footer\">\n"), (Header 1 date), (Header 2 title'), (RawHtml "</div>\n</div>\n")] presentationStart :: Block presentationStart = RawHtml "<div class=\"presentation\">\n\n" @@ -130,8 +130,8 @@ insertS5Structure (Pandoc (Meta title' authors date) blocks) = let slides = insertSlides True blocks firstSlide = if not (null title') then [slideStart, (Header 1 title'), - (Header 3 [Str (intercalate ", " authors)]), - (Header 4 [Str date]), slideEnd] + (Header 3 (intercalate [Str ",", Space] authors)), + (Header 4 date), slideEnd] else [] newBlocks = (layoutDiv title' date) ++ presentationStart:firstSlide ++ slides ++ [presentationEnd] |