diff --git a/doc/org.md b/doc/org.md index d117d09dc..17b994f19 100644 --- a/doc/org.md +++ b/doc/org.md @@ -53,9 +53,10 @@ occur. the description. In contrast, the Org-mode HTML exporter treats the description as plain text. -- LATEX_HEADER: arbitrary lines to add to the document's preamble. - Contrary to Org-mode, these lines are not inserted before the - hyperref settings, but close to the end of the preamble. +- LATEX\_HEADER and LATEX_HEADER_EXTRA: arbitrary lines to add to + the document's preamble. Contrary to Org-mode, these lines are + not inserted before the hyperref settings, but close to the end + of the preamble. The contents of this option are stored as a list of raw LaTeX lines in the `header-includes` metadata field. @@ -77,10 +78,10 @@ occur. The content of this option is stored as inlines in the `subtitle` metadata field. -- HTML_HEAD: arbitrary lines to add to the HTML document's head; - fully supported. +- HTML\_HEAD and HTML\_HEAD\_EXTRA: arbitrary lines to add to the + HTML document's head; fully supported. - The contents of this option are stored as a list of raw HTML + The contents of these options are stored as a list of raw HTML lines in the `header-includes` metadata field. Pandoc-specific options diff --git a/src/Text/Pandoc/Readers/Org/Meta.hs b/src/Text/Pandoc/Readers/Org/Meta.hs index c922403df..ae323f189 100644 --- a/src/Text/Pandoc/Readers/Org/Meta.hs +++ b/src/Text/Pandoc/Readers/Org/Meta.hs @@ -82,14 +82,18 @@ exportSettingHandlers = Map.fromList , ("subtitle" , lineOfInlines `parseThen` collectLines "subtitle") , ("title" , lineOfInlines `parseThen` collectLines "title") -- LaTeX - , ("latex_class", fmap pure anyLine `parseThen` setField "documentclass") + , ("latex_class" , fmap pure anyLine `parseThen` setField "documentclass") , ("latex_class_options", (pure . T.filter (`notElem` ("[]" :: String)) <$> anyLine) `parseThen` setField "classoption") - , ("latex_header", metaExportSnippet "latex" `parseThen` - collectAsList "header-includes") + , ("latex_header" , metaExportSnippet "latex" `parseThen` + collectAsList "header-includes") + , ("latex_header_extra", metaExportSnippet "latex" `parseThen` + collectAsList "header-includes") -- HTML - , ("html_head" , metaExportSnippet "html" `parseThen` - collectAsList "header-includes") + , ("html_head" , metaExportSnippet "html" `parseThen` + collectAsList "header-includes") + , ("html_head_extra", metaExportSnippet "html" `parseThen` + collectAsList "header-includes") -- pandoc-specific , ("nocite" , lineOfInlines `parseThen` collectLines "nocite") , ("header-includes", lineOfInlines `parseThen` collectLines "header-includes") diff --git a/test/Tests/Readers/Org/Meta.hs b/test/Tests/Readers/Org/Meta.hs index 89cd35b26..dd51cbd48 100644 --- a/test/Tests/Readers/Org/Meta.hs +++ b/test/Tests/Readers/Org/Meta.hs @@ -108,42 +108,62 @@ tests = meta = setMeta "keywords" (MetaInlines keywords) nullMeta in Pandoc meta mempty - , "LaTeX_headers options are translated to header-includes" =: - "#+LaTeX_header: \\usepackage{tikz}" =?> - let latexInlines = rawInline "latex" "\\usepackage{tikz}" - inclList = MetaList [MetaInlines (toList latexInlines)] - meta = setMeta "header-includes" inclList nullMeta - in Pandoc meta mempty - - , testGroup "LaTeX_CLASS" - [ "LaTeX_class option is translated to documentclass" =: - "#+LATEX_CLASS: article" =?> - let meta = setMeta "documentclass" (MetaString "article") nullMeta - in Pandoc meta mempty - - , "last definition takes precedence" =: - T.unlines [ "#+LATEX_CLASS: this will not be used" - , "#+LATEX_CLASS: report" - ] =?> - let meta = setMeta "documentclass" (MetaString "report") nullMeta - in Pandoc meta mempty - ] - - , "LaTeX_class_options is translated to classoption" =: - "#+LATEX_CLASS_OPTIONS: [a4paper]" =?> - let meta = setMeta "classoption" (MetaString "a4paper") nullMeta - in Pandoc meta mempty - - , "LaTeX_class_options is translated to classoption" =: - "#+html_head: <meta/>" =?> - let html = rawInline "html" "<meta/>" - inclList = MetaList [MetaInlines (toList html)] - meta = setMeta "header-includes" inclList nullMeta - in Pandoc meta mempty - , "Institute" =: "#+INSTITUTE: ACME Inc." =?> Pandoc (setMeta "institute" ("ACME Inc." :: Inlines) nullMeta) mempty + + , testGroup "LaTeX" + [ "LaTeX_headers options are translated to header-includes" =: + "#+LaTeX_header: \\usepackage{tikz}" =?> + let latexInlines = rawInline "latex" "\\usepackage{tikz}" + inclList = MetaList [MetaInlines (toList latexInlines)] + meta = setMeta "header-includes" inclList nullMeta + in Pandoc meta mempty + + , "LATEX_HEADER_EXTRA values are translated to header-includes" =: + "#+LATEX_HEADER_EXTRA: \\usepackage{calc}" =?> + let latexInlines = rawInline "latex" "\\usepackage{calc}" + inclList = toMetaValue [latexInlines] + in Pandoc (setMeta "header-includes" inclList nullMeta) mempty + + , testGroup "LaTeX_CLASS" + [ "LaTeX_class option is translated to documentclass" =: + "#+LATEX_CLASS: article" =?> + let meta = setMeta "documentclass" (MetaString "article") nullMeta + in Pandoc meta mempty + + , "last definition takes precedence" =: + T.unlines [ "#+LATEX_CLASS: this will not be used" + , "#+LATEX_CLASS: report" + ] =?> + let meta = setMeta "documentclass" (MetaString "report") nullMeta + in Pandoc meta mempty + ] + + , "LaTeX_class_options is translated to classoption" =: + "#+LATEX_CLASS_OPTIONS: [a4paper]" =?> + let meta = setMeta "classoption" (MetaString "a4paper") nullMeta + in Pandoc meta mempty + ] + + , testGroup "HTML" + [ "HTML_HEAD values are added to header-includes" =: + "#+html_head: <meta/>" =?> + let html = rawInline "html" "<meta/>" + inclList = MetaList [MetaInlines (toList html)] + meta = setMeta "header-includes" inclList nullMeta + in Pandoc meta mempty + + , "HTML_HEAD_EXTRA behaves like HTML_HEAD" =: + T.unlines [ "#+HTML_HEAD: <meta name=\"generator\" content=\"pandoc\">" + , "#+HTML_HEAD_EXTRA: <meta charset=\"utf-8\">" + ] =?> + let generator = rawInline "html" + "<meta name=\"generator\" content=\"pandoc\">" + charset = rawInline "html" "<meta charset=\"utf-8\">" + inclList = toMetaValue [generator, charset] + in Pandoc (setMeta "header-includes" inclList nullMeta) mempty + ] ] , "Properties drawer" =: