aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2010-02-28 11:21:19 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2010-02-28 11:21:19 +0000
commit77ba3429e2616a95535706f5c79fe7bc85e5b4b1 (patch)
treef10dfe6046364abbf205b9d4ec6df4f1aaaa9c3e
parent36675bd20612fc75df97dda3a3c0d2a5b694f83c (diff)
downloadpandoc-77ba3429e2616a95535706f5c79fe7bc85e5b4b1.tar.gz
Allow multi-line titles and authors in meta block.
Based on a patch by Justin Bogner. Titles may span multiple lines, provided continuation lines begin with a space character. Separate authors may be put on multiple lines, provided each line after the first begins with a space character. Each author must fit on one line. Multiple authors on a single line may still be separated by a semicolon. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1854 788f1e2b-df1e-0410-8736-df70ead52e1b
-rw-r--r--README68
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs14
-rw-r--r--tests/markdown-reader-more.native2
-rw-r--r--tests/markdown-reader-more.txt6
4 files changed, 64 insertions, 26 deletions
diff --git a/README b/README
index bd01c25aa..ae397232b 100644
--- a/README
+++ b/README
@@ -905,32 +905,56 @@ Title blocks
If the file begins with a title block
- % title
- % author(s) (separated by semicolons)
- % date
+ % title
+ % author(s) (separated by semicolons)
+ % date
it will be parsed as bibliographic information, not regular text. (It
will be used, for example, in the title of standalone LaTeX or HTML
output.) The block may contain just a title, a title and an author,
-or all three lines. Each must begin with a % and fit on one line.
-The title may contain standard inline formatting. If you want to
-include an author but no title, or a title and a date but no author,
-you need a blank line:
-
- % My title
- %
- % June 15, 2006
-
-Titles will be written only when the `--standalone` (`-s`) option is
-chosen. In HTML output, titles will appear twice: once in the
-document head -- this is the title that will appear at the top of the
-window in a browser -- and once at the beginning of the document body.
-The title in the document head can have an optional prefix attached
-(`--title-prefix` or `-T` option). The title in the body appears as
-an H1 element with class "title", so it can be suppressed or
-reformatted with CSS. If a title prefix is specified with `-T` and no
-title block appears in the document, the title prefix will be used by
-itself as the HTML title.
+or all three elements. If you want to include an author but no
+title, or a title and a date but no author, you need a blank line:
+
+ %
+ % Author
+
+ % My title
+ %
+ % June 15, 2006
+
+The title may occupy multiple lines, but continuation lines must
+begin with leading space, thus:
+
+ % My title
+ on multiple lines
+
+If a document has multiple authors, the authors may be put on
+separate lines with leading space, or separated by semicolons, or
+both. So, all of the following are equivalent:
+
+ % Author One
+ Author Two
+
+ % Author One; Author Two
+
+ % Author One;
+ Author Two
+
+The date must fit on one line.
+
+All three metadata fields may contain standard inline formatting
+(italics, links, footnotes, etc.).
+
+Title blocks will always be parsed, but they will affect the output only
+when the `--standalone` (`-s`) option is chosen. In HTML output, titles
+will appear twice: once in the document head -- this is the title that
+will appear at the top of the window in a browser -- and once at the
+beginning of the document body. The title in the document head can have
+an optional prefix attached (`--title-prefix` or `-T` option). The title
+in the body appears as an H1 element with class "title", so it can be
+suppressed or reformatted with CSS. If a title prefix is specified with
+`-T` and no title block appears in the document, the title prefix will
+be used by itself as the HTML title.
The man page writer extracts a title, man page section number, and
other header and footer information from the title line. The title
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index e0cc39ecc..029b40101 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -133,15 +133,23 @@ inlinesInBalancedBrackets parser = try $ do
--
titleLine :: GenParser Char ParserState [Inline]
-titleLine = try $ char '%' >> skipSpaces >> manyTill inline newline
+titleLine = try $ do
+ char '%'
+ skipSpaces
+ res <- many $ (notFollowedBy newline >> inline)
+ <|> try (endline >> whitespace)
+ newline
+ return $ normalizeSpaces res
authorsLine :: GenParser Char ParserState [[Inline]]
authorsLine = try $ do
char '%'
skipSpaces
- authors <- sepEndBy (many1 (notFollowedBy (oneOf ";\n") >> inline)) (oneOf ";")
+ authors <- sepEndBy (many (notFollowedBy (oneOf ";\n") >> inline))
+ (char ';' <|>
+ try (newline >> notFollowedBy blankline >> spaceChar))
newline
- return $ map normalizeSpaces authors
+ return $ filter (not . null) $ map normalizeSpaces authors
dateLine :: GenParser Char ParserState [Inline]
dateLine = try $ do
diff --git a/tests/markdown-reader-more.native b/tests/markdown-reader-more.native
index 1db191c16..a39965970 100644
--- a/tests/markdown-reader-more.native
+++ b/tests/markdown-reader-more.native
@@ -1,4 +1,4 @@
-Pandoc (Meta {docTitle = [], docAuthors = [], docDate = []})
+Pandoc (Meta {docTitle = [Str "Title",Space,Str "spanning",Space,Str "multiple",Space,Str "lines"], docAuthors = [[Str "Author",Space,Str "One"],[Str "Author",Space,Str "Two"],[Str "Author",Space,Str "Three"],[Str "Author",Space,Str "Four"]], docDate = []})
[ Header 1 [Str "Additional",Space,Str "markdown",Space,Str "reader",Space,Str "tests"]
, Header 2 [Str "Blank",Space,Str "line",Space,Str "before",Space,Str "URL",Space,Str "in",Space,Str "link",Space,Str "reference"]
, Para [Link [Str "foo"] ("/url",""),Space,Str "and",Space,Link [Str "bar"] ("/url","title")]
diff --git a/tests/markdown-reader-more.txt b/tests/markdown-reader-more.txt
index 4689ee84a..de80d740b 100644
--- a/tests/markdown-reader-more.txt
+++ b/tests/markdown-reader-more.txt
@@ -1,3 +1,9 @@
+% Title
+ spanning multiple lines
+% Author One
+ Author Two; Author Three;
+ Author Four
+
# Additional markdown reader tests
## Blank line before URL in link reference