git.iko.soy/typeable/pandoc
on master help sign in
Changed Meta author and date types to Inline lists instead of Strings.

Meta [Inline] [[Inline]] [Inline] rather than Meta [Inline] [String] String. This is a breaking change for libraries that use pandoc and manipulate the metadata. Changed .native files in test suite for new Meta format. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1699 788f1e2b-df1e-0410-8736-df70ead52e1b

commit3ec8772daff7d76097d7435c4e8da1df5ee4cc6a authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateThu 31 Dec 2009, 01:12 (17 years ago) parent1a16698
21 files changed+76−67
src/Text/Pandoc/Definition.hs+3−3 src/Text/Pandoc/Readers/HTML.hs+4−4 src/Text/Pandoc/Readers/LaTeX.hs+5−5 src/Text/Pandoc/Readers/Markdown.hs+9−10 src/Text/Pandoc/Readers/RST.hs+7−5 src/Text/Pandoc/Shared.hs+2−2 src/Text/Pandoc/Writers/LaTeX.hs+5−5 src/Text/Pandoc/Writers/Man.hs+6−4 src/Text/Pandoc/Writers/Markdown.hs+12−9 src/Text/Pandoc/Writers/RST.hs+7−4 src/Text/Pandoc/Writers/RTF.hs+3−3 src/Text/Pandoc/Writers/S5.hs+4−4 tests/html-reader.native+1−1 tests/latex-reader.native+1−1 tests/lhs-test.native+1−1 tests/markdown-reader-more.native+1−1 tests/rst-reader.native+1−1 tests/s5.native+1−1 tests/tables.native+1−1 tests/testsuite.native+1−1 tests/writer.native+1−1
src/Text/Pandoc/Definition.hs+3−3
@@ -37,9 +37,9 @@ data Pandoc = Pandoc Meta [Block] deriving (Eq, Read, Show, Typeable, Data)
3737
3838-- | Bibliographic information for the document: title (list of 'Inline'),
3939-- authors (list of strings), date (string).
40−data Meta = Meta [Inline] -- title
41− [String] -- authors
42− String -- date
40+data Meta = Meta [Inline] -- title
41+ [[Inline]] -- authors
42+ [Inline] -- date
4343 deriving (Eq, Show, Read, Typeable, Data)
4444
4545-- | Alignment of a table column.
src/Text/Pandoc/Readers/HTML.hs+4−4
@@ -382,7 +382,7 @@ parseTitle = try $ do
382382 return contents
383383
384384-- parse header and return meta-information (for now, just title)
385−parseHead :: GenParser Char ParserState ([Inline], [a], [Char])
385+parseHead :: GenParser Char ParserState Meta
386386parseHead = try $ do
387387 htmlTag "head"
388388 spaces
@@ -390,7 +390,7 @@ parseHead = try $ do
390390 contents <- option [] parseTitle
391391 skipMany nonTitleNonHead
392392 htmlEndTag "head"
393− return (contents, [], "")
393+ return $ Meta contents [] []
394394
395395skipHtmlTag :: String -> GenParser Char ParserState ()
396396skipHtmlTag tag = optional (htmlTag tag)
@@ -409,7 +409,7 @@ parseHtml = do
409409 sepEndBy (choice [xmlDec, definition, htmlComment]) spaces
410410 skipHtmlTag "html"
411411 spaces
412− (title, authors, date) <- option ([], [], "") parseHead
412+ meta <- option (Meta [] [] []) parseHead
413413 spaces
414414 skipHtmlTag "body"
415415 spaces
@@ -420,7 +420,7 @@ parseHtml = do
420420 spaces
421421 optional (htmlEndTag "html" >> many anyChar) -- ignore anything after </html>
422422 eof
423− return $ Pandoc (Meta title authors date) blocks
423+ return $ Pandoc meta blocks
424424
425425--
426426-- parsing blocks
src/Text/Pandoc/Readers/LaTeX.hs+5−5
@@ -317,19 +317,19 @@ title = try $ do
317317authors :: GenParser Char ParserState Block
318318authors = try $ do
319319 string "\\author{"
320− authors' <- manyTill anyChar (char '}')
320+ authors' <- sepBy (many1 (notFollowedBy (oneOf "};,") >> inline)) (oneOf ",;")
321+ char '}'
321322 spaces
322− let authors'' = map removeLeadingTrailingSpace $ lines $
323− substitute "\\\\" "\n" authors'
323+ let authors'' = map normalizeSpaces authors'
324324 updateState (\s -> s { stateAuthors = authors'' })
325325 return Null
326326
327327date :: GenParser Char ParserState Block
328328date = try $ do
329329 string "\\date{"
330− date' <- manyTill anyChar (char '}')
330+ date' <- manyTill inline (char '}')
331331 spaces
332− updateState (\state -> state { stateDate = date' })
332+ updateState (\state -> state { stateDate = normalizeSpaces date' })
333333 return Null
334334
335335--
src/Text/Pandoc/Readers/Markdown.hs+9−10
@@ -132,28 +132,27 @@ inlinesInBalancedBrackets parser = try $ do
132132titleLine :: GenParser Char ParserState [Inline]
133133titleLine = try $ char '%' >> skipSpaces >> manyTill inline newline
134134
135−authorsLine :: GenParser Char st [String]
135+authorsLine :: GenParser Char ParserState [[Inline]]
136136authorsLine = try $ do
137137 char '%'
138138 skipSpaces
139− authors <- sepEndBy (many1 (noneOf ",;\n")) (oneOf ",;")
139+ authors <- sepEndBy (many1 (notFollowedBy (oneOf ",;\n") >> inline)) (oneOf ",;")
140140 newline
141− return $ map (decodeCharacterReferences . removeLeadingTrailingSpace) authors
141+ return $ map normalizeSpaces authors
142142
143−dateLine :: GenParser Char st String
143+dateLine :: GenParser Char ParserState [Inline]
144144dateLine = try $ do
145145 char '%'
146146 skipSpaces
147− date <- many (noneOf "\n")
148− newline
149− return $ decodeCharacterReferences $ removeTrailingSpace date
147+ date <- manyTill inline newline
148+ return $ normalizeSpaces date
150149
151−titleBlock :: GenParser Char ParserState ([Inline], [String], [Char])
150+titleBlock :: GenParser Char ParserState ([Inline], [[Inline]], [Inline])
152151titleBlock = try $ do
153152 failIfStrict
154153 title <- option [] titleLine
155154 author <- option [] authorsLine
156− date <- option "" dateLine
155+ date <- option [] dateLine
157156 optional blanklines
158157 return (title, author, date)
159158
@@ -175,7 +174,7 @@ parseMarkdown = do
175174 let reversedNotes = stateNotes st'
176175 updateState $ \s -> s { stateNotes = reverse reversedNotes }
177176 -- now parse it for real...
178− (title, author, date) <- option ([],[],"") titleBlock
177+ (title, author, date) <- option ([],[],[]) titleBlock
179178 blocks <- parseBlocks
180179 return $ Pandoc (Meta title author date) $ filter (/= Null) blocks
181180
src/Text/Pandoc/Readers/RST.hs+7−5
@@ -33,7 +33,7 @@ module Text.Pandoc.Readers.RST (
3333import Text.Pandoc.Definition
3434import Text.Pandoc.Shared
3535import Text.ParserCombinators.Parsec
36−import Control.Monad ( when )
36+import Control.Monad ( when, unless )
3737import Data.List ( findIndex, delete, intercalate )
3838
3939-- | Parse reStructuredText string and return Pandoc document.
@@ -157,11 +157,13 @@ fieldList = try $ do
157157 let authors = case lookup "Authors" items of
158158 Just auth -> [auth]
159159 Nothing -> map snd (filter (\(x,_) -> x == "Author") items)
160− if null authors
161− then return ()
162− else updateState $ \st -> st {stateAuthors = authors}
160+ unless (null authors) $ do
161+ authors' <- mapM (parseFromString (many inline)) authors
162+ updateState $ \st -> st {stateAuthors = map normalizeSpaces authors'}
163163 case (lookup "Date" items) of
164− Just dat -> updateState $ \st -> st {stateDate = dat}
164+ Just dat -> do
165+ dat' <- parseFromString (many inline) dat
166+ updateState $ \st -> st{ stateDate = normalizeSpaces dat' }
165167 Nothing -> return ()
166168 case (lookup "Title" items) of
167169 Just tit -> parseFromString (many inline) tit >>=
src/Text/Pandoc/Shared.hs+2−2
@@ -667,8 +667,8 @@ data ParserState = ParserState
667667 stateTabStop :: Int, -- ^ Tab stop
668668 stateStandalone :: Bool, -- ^ Parse bibliographic info?
669669 stateTitle :: [Inline], -- ^ Title of document
670− stateAuthors :: [String], -- ^ Authors of document
671− stateDate :: String, -- ^ Date of document
670+ stateAuthors :: [[Inline]], -- ^ Authors of document
671+ stateDate :: [Inline], -- ^ Date of document
672672 stateStrict :: Bool, -- ^ Use strict markdown syntax?
673673 stateSmart :: Bool, -- ^ Use smart typography?
674674 stateLiterateHaskell :: Bool, -- ^ Treat input as literate haskell
src/Text/Pandoc/Writers/LaTeX.hs+5−5
@@ -53,15 +53,15 @@ writeLaTeX options document =
5353pandocToLaTeX :: WriterOptions -> Pandoc -> State WriterState String
5454pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do
5555 main <- liftM render $ blockListToLaTeX blocks
56− titletext <- if null title
57− then return ""
58− else liftM render $ inlineListToLaTeX title
56+ titletext <- liftM render $ inlineListToLaTeX title
57+ authorsText <- mapM (liftM render . inlineListToLaTeX) authors
58+ dateText <- liftM render $ inlineListToLaTeX date
5959 let context = writerVariables options ++
6060 [ ("toc", if writerTableOfContents options then "yes" else "")
6161 , ("body", main)
6262 , ("title", titletext)
63− , ("authors", intercalate "\\\\" $ map stringToLaTeX authors)
64− , ("date", stringToLaTeX date) ]
63+ , ("authors", intercalate "\\\\" authorsText)
64+ , ("date", dateText) ]
6565 return $ renderTemplate context $ writerTemplate options
6666
6767-- escape things as needed for LaTeX
src/Text/Pandoc/Writers/Man.hs+6−4
@@ -68,6 +68,8 @@ metaToMan :: WriterOptions -- ^ Options, including Man header
6868 -> State WriterState (Doc, Doc)
6969metaToMan options (Meta title authors date) = do
7070 titleText <- inlineListToMan options title
71+ authorsText <- mapM (inlineListToMan options) authors
72+ dateText <- inlineListToMan options date
7173 let (cmdName, rest) = break (== ' ') $ render titleText
7274 let (title', section) = case reverse cmdName of
7375 (')':d:'(':xs) | d `elem` ['0'..'9'] ->
@@ -76,11 +78,11 @@ metaToMan options (Meta title authors date) = do
7678 let extras = map (doubleQuotes . text . removeLeadingTrailingSpace) $
7779 splitBy '|' rest
7880 let head' = (text ".TH") <+> title' <+> section <+>
79− doubleQuotes (text date) <+> hsep extras
80− let foot = case length authors of
81+ doubleQuotes dateText <+> hsep extras
82+ let foot = case length authorsText of
8183 0 -> empty
82− 1 -> text ".SH AUTHOR" $$ (text $ intercalate ", " authors)
83− _ -> text ".SH AUTHORS" $$ (text $ intercalate ", " authors)
84+ 1 -> text ".SH AUTHOR" $$ (hcat $ intersperse (text ", ") authorsText)
85+ _ -> text ".SH AUTHORS" $$ (hcat $ intersperse (text ", ") authorsText)
8486 return $ if writerStandalone options
8587 then (head', foot)
8688 else (empty, empty)
src/Text/Pandoc/Writers/Markdown.hs+12−9
@@ -109,8 +109,8 @@ metaToMarkdown :: WriterOptions -> Meta -> State WriterState Doc
109109metaToMarkdown _ (Meta [] [] []) = return empty
110110metaToMarkdown opts (Meta title authors date) = do
111111 title' <- titleToMarkdown opts title
112− authors' <- authorsToMarkdown authors
113− date' <- dateToMarkdown date
112+ authors' <- authorsToMarkdown opts authors
113+ date' <- dateToMarkdown opts date
114114 return $ title' $+$ authors' $+$ date' $+$ text ""
115115
116116titleToMarkdown :: WriterOptions -> [Inline] -> State WriterState Doc
@@ -119,14 +119,17 @@ titleToMarkdown opts lst = do
119119 contents <- inlineListToMarkdown opts lst
120120 return $ text "% " <> contents
121121
122−authorsToMarkdown :: [String] -> State WriterState Doc
123−authorsToMarkdown [] = return empty
124−authorsToMarkdown lst = return $
125− text "% " <> text (intercalate ", " (map escapeString lst))
122+authorsToMarkdown :: WriterOptions -> [[Inline]] -> State WriterState Doc
123+authorsToMarkdown opts [] = return empty
124+authorsToMarkdown opts lst = do
125+ authors <- mapM (inlineListToMarkdown opts) lst
126+ return $ text "% " <> (hcat $ intersperse (text ", ") authors)
126127
127−dateToMarkdown :: String -> State WriterState Doc
128−dateToMarkdown [] = return empty
129−dateToMarkdown str = return $ text "% " <> text (escapeString str)
128+dateToMarkdown :: WriterOptions -> [Inline] -> State WriterState Doc
129+dateToMarkdown opts [] = return empty
130+dateToMarkdown opts str = do
131+ date <- inlineListToMarkdown opts str
132+ return $ text "% " <> date
130133
131134-- | Construct table of contents from list of header blocks.
132135tableOfContents :: WriterOptions -> [Block] -> Doc
src/Text/Pandoc/Writers/RST.hs+7−4
@@ -150,15 +150,18 @@ titleToRST lst = do
150150 let border = text (replicate titleLength '=')
151151 return $ border $+$ contents $+$ border <> text "\n"
152152
153−authorsToRST :: [String] -> State WriterState Doc
153+authorsToRST :: [[Inline]] -> State WriterState Doc
154154authorsToRST [] = return empty
155155authorsToRST (first:rest) = do
156156 rest' <- authorsToRST rest
157− return $ (text ":Author: " <> text first) $+$ rest'
157+ first' <- inlineListToRST first
158+ return $ (text ":Author: " <> first') $+$ rest'
158159
159−dateToRST :: String -> State WriterState Doc
160+dateToRST :: [Inline] -> State WriterState Doc
160161dateToRST [] = return empty
161−dateToRST str = return $ text ":Date: " <> text (escapeString str)
162+dateToRST str = do
163+ date <- inlineListToRST str
164+ return $ text ":Date: " <> date
162165
163166-- | Convert Pandoc block element to RST.
164167blockToRST :: Block -- ^ Block element
src/Text/Pandoc/Writers/RTF.hs+3−3
@@ -152,10 +152,10 @@ rtfHeader headerText (Meta title authors date) =
152152 authorstext = if null authors
153153 then ""
154154 else rtfPar 0 0 AlignCenter (" " ++ (intercalate "\\" $
155− map stringToRTF authors))
156− datetext = if date == ""
155+ map inlineListToRTF authors))
156+ datetext = if null date
157157 then ""
158− else rtfPar 0 0 AlignCenter (" " ++ stringToRTF date) in
158+ else rtfPar 0 0 AlignCenter (" " ++ inlineListToRTF date) in
159159 let spacer = if null (titletext ++ authorstext ++ datetext)
160160 then ""
161161 else rtfPar 0 0 AlignDefault "" in
src/Text/Pandoc/Writers/S5.hs+4−4
@@ -85,9 +85,9 @@ writeS5String options = (writeHtmlString options) . insertS5Structure
8585
8686-- | Inserts HTML needed for an S5 presentation (e.g. around slides).
8787layoutDiv :: [Inline] -- ^ Title of document (for header or footer)
88− -> String -- ^ Date of document (for header or footer)
88+ -> [Inline] -- ^ Date of document (for header or footer)
8989 -> [Block] -- ^ List of block elements returned
90−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")]
90+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")]
9191
9292presentationStart :: Block
9393presentationStart = RawHtml "<div class=\"presentation\">\n\n"
@@ -130,8 +130,8 @@ insertS5Structure (Pandoc (Meta title' authors date) blocks) =
130130 let slides = insertSlides True blocks
131131 firstSlide = if not (null title')
132132 then [slideStart, (Header 1 title'),
133− (Header 3 [Str (intercalate ", " authors)]),
134− (Header 4 [Str date]), slideEnd]
133+ (Header 3 (intercalate [Str ",", Space] authors)),
134+ (Header 4 date), slideEnd]
135135 else []
136136 newBlocks = (layoutDiv title' date) ++ presentationStart:firstSlide ++
137137 slides ++ [presentationEnd]
tests/html-reader.native+1−1
@@ -1,4 +1,4 @@
1−Pandoc (Meta [Str "Pandoc",Space,Str "Test",Space,Str "Suite"] [] "")
1+Pandoc (Meta [Str "Pandoc",Space,Str "Test",Space,Str "Suite"] [] [])
22[ Para [Str "This",Space,Str "is",Space,Str "a",Space,Str "set",Space,Str "of",Space,Str "tests",Space,Str "for",Space,Str "pandoc.",Space,Str "Most",Space,Str "of",Space,Str "them",Space,Str "are",Space,Str "adapted",Space,Str "from",Space,Str "John",Space,Str "Gruber's",Space,Str "markdown",Space,Str "test",Space,Str "suite."]
33, HorizontalRule
44, Header 1 [Str "Headers"]
tests/latex-reader.native+1−1
@@ -1,4 +1,4 @@
1−Pandoc (Meta [Str "Pandoc",Space,Str "Test",Space,Str "Suite"] ["John MacFarlane","Anonymous"] "July 17, 2006")
1+Pandoc (Meta [Str "Pandoc",Space,Str "Test",Space,Str "Suite"] [[Str "John",Space,Str "MacFarlane"],[Str "Anonymous"]] [Str "July",Space,Str "17,",Space,Str "2006"])
22[ Para [Str "This",Space,Str "is",Space,Str "a",Space,Str "set",Space,Str "of",Space,Str "tests",Space,Str "for",Space,Str "pandoc.",Space,Str "Most",Space,Str "of",Space,Str "them",Space,Str "are",Space,Str "adapted",Space,Str "from",Space,Str "John",Space,Str "Gruber",Apostrophe,Str "s",Space,Str "markdown",Space,Str "test",Space,Str "suite."]
33, HorizontalRule
44, Header 1 [Str "Headers"]
tests/lhs-test.native+1−1
@@ -1,4 +1,4 @@
1−Pandoc (Meta [] [] "")
1+Pandoc (Meta [] [] [])
22[ Header 1 [Str "lhs",Space,Str "test"]
33, Para [Code "unsplit",Space,Str "is",Space,Str "an",Space,Str "arrow",Space,Str "that",Space,Str "takes",Space,Str "a",Space,Str "pair",Space,Str "of",Space,Str "values",Space,Str "and",Space,Str "combines",Space,Str "them",Space,Str "to",Space,Str "return",Space,Str "a",Space,Str "single",Space,Str "value:"]
44, CodeBlock ("",["sourceCode","literate","haskell"],[]) "unsplit :: (Arrow a) => (b -> c -> d) -> a (b, c) d\nunsplit = arr . uncurry \n -- arr (\\op (x,y) -> x `op` y) "
tests/markdown-reader-more.native+1−1
@@ -1,4 +1,4 @@
1−Pandoc (Meta [] [] "")
1+Pandoc (Meta [] [] [])
22[ Header 1 [Str "Additional",Space,Str "markdown",Space,Str "reader",Space,Str "tests"]
33, Header 2 [Str "Blank",Space,Str "line",Space,Str "before",Space,Str "URL",Space,Str "in",Space,Str "link",Space,Str "reference"]
44, Para [Link [Str "foo"] ("/url",""),Space,Str "and",Space,Link [Str "bar"] ("/url","title")]
tests/rst-reader.native+1−1
@@ -1,4 +1,4 @@
1−Pandoc (Meta [Str "Pandoc",Space,Str "Test",Space,Str "Suite",Str ":",Space,Str "Subtitle"] ["John MacFarlane","Anonymous"] "July 17, 2006")
1+Pandoc (Meta [Str "Pandoc",Space,Str "Test",Space,Str "Suite",Str ":",Space,Str "Subtitle"] [[Str "John",Space,Str "MacFarlane"],[Str "Anonymous"]] [Str "July",Space,Str "17,",Space,Str "2006"])
22[ DefinitionList
33 [ ([Str "Revision"],
44 [ [ Plain [Str "3"] ]
tests/s5.native+1−1
@@ -1,4 +1,4 @@
1−Pandoc (Meta [Str "My",Space,Str "S5",Space,Str "Document"] ["Sam Smith","Jen Jones"] "July 15, 2006")
1+Pandoc (Meta [Str "My",Space,Str "S5",Space,Str "Document"] [[Str "Sam",Space,Str "Smith"],[Str "Jen",Space,Str "Jones"]] [Str "July",Space,Str "15,",Space,Str "2006"])
22[ Header 1 [Str "First",Space,Str "slide"]
33, BulletList
44 [ [ Plain [Str "first",Space,Str "bullet"] ]
tests/tables.native+1−1
@@ -1,4 +1,4 @@
1−Pandoc (Meta [] [] "")
1+Pandoc (Meta [] [] [])
22[ Para [Str "Simple",Space,Str "table",Space,Str "with",Space,Str "caption:"]
33, Table [Str "Demonstration",Space,Str "of",Space,Str "simple",Space,Str "table",Space,Str "syntax",Str "."] [AlignRight,AlignLeft,AlignCenter,AlignDefault] [0.0,0.0,0.0,0.0]
44 [ [ Plain [Str "Right"] ]
tests/testsuite.native+1−1
@@ -1,4 +1,4 @@
1−Pandoc (Meta [Str "Pandoc",Space,Str "Test",Space,Str "Suite"] ["John MacFarlane","Anonymous"] "July 17, 2006")
1+Pandoc (Meta [Str "Pandoc",Space,Str "Test",Space,Str "Suite"] [[Str "John",Space,Str "MacFarlane"],[Str "Anonymous"]] [Str "July",Space,Str "17,",Space,Str "2006"])
22[ Para [Str "This",Space,Str "is",Space,Str "a",Space,Str "set",Space,Str "of",Space,Str "tests",Space,Str "for",Space,Str "pandoc",Str ".",Space,Str "Most",Space,Str "of",Space,Str "them",Space,Str "are",Space,Str "adapted",Space,Str "from",Space,Str "John",Space,Str "Gruber",Apostrophe,Str "s",Space,Str "markdown",Space,Str "test",Space,Str "suite",Str "."]
33, HorizontalRule
44, Header 1 [Str "Headers"]
tests/writer.native+1−1
@@ -1,4 +1,4 @@
1−Pandoc (Meta [Str "Pandoc",Space,Str "Test",Space,Str "Suite"] ["John MacFarlane","Anonymous"] "July 17, 2006")
1+Pandoc (Meta [Str "Pandoc",Space,Str "Test",Space,Str "Suite"] [[Str "John",Space,Str "MacFarlane"],[Str "Anonymous"]] [Str "July",Space,Str "17,",Space,Str "2006"])
22[ Para [Str "This",Space,Str "is",Space,Str "a",Space,Str "set",Space,Str "of",Space,Str "tests",Space,Str "for",Space,Str "pandoc",Str ".",Space,Str "Most",Space,Str "of",Space,Str "them",Space,Str "are",Space,Str "adapted",Space,Str "from",Space,Str "John",Space,Str "Gruber",Apostrophe,Str "s",Space,Str "markdown",Space,Str "test",Space,Str "suite",Str "."]
33, HorizontalRule
44, Header 1 [Str "Headers"]