git.iko.soy/typeable/pandoc
on master help sign in
Org reader: support LATEX_HEADER_EXTRA and HTML_HEAD_EXTRA settings

These export settings are treated like their non-extra counterparts, i.e., the values are added to the `header-includes` metadata list.

commit1480606174260657e27a0f02f8f44f1fca14b005 authorAlbert Krewinkel <albert@zeitkraut.de> dateMon 29 Jun 2020, 17:00 (6 years ago) parentd17b257
3 files changed+65−40
doc/org.md+7−6 src/Text/Pandoc/Readers/Org/Meta.hs+9−5 test/Tests/Readers/Org/Meta.hs+49−29
doc/org.md+7−6
@@ -53,9 +53,10 @@ occur.
5353 the description. In contrast, the Org-mode HTML exporter treats
5454 the description as plain text.
5555
56−- LATEX_HEADER: arbitrary lines to add to the document's preamble.
57− Contrary to Org-mode, these lines are not inserted before the
58− hyperref settings, but close to the end of the preamble.
56+- LATEX\_HEADER and LATEX_HEADER_EXTRA: arbitrary lines to add to
57+ the document's preamble. Contrary to Org-mode, these lines are
58+ not inserted before the hyperref settings, but close to the end
59+ of the preamble.
5960
6061 The contents of this option are stored as a list of raw LaTeX
6162 lines in the `header-includes` metadata field.
@@ -77,10 +78,10 @@ occur.
7778 The content of this option is stored as inlines in the
7879 `subtitle` metadata field.
7980
80−- HTML_HEAD: arbitrary lines to add to the HTML document's head;
81− fully supported.
81+- HTML\_HEAD and HTML\_HEAD\_EXTRA: arbitrary lines to add to the
82+ HTML document's head; fully supported.
8283
83− The contents of this option are stored as a list of raw HTML
84+ The contents of these options are stored as a list of raw HTML
8485 lines in the `header-includes` metadata field.
8586
8687Pandoc-specific options
src/Text/Pandoc/Readers/Org/Meta.hs+9−5
@@ -82,14 +82,18 @@ exportSettingHandlers = Map.fromList
8282 , ("subtitle" , lineOfInlines `parseThen` collectLines "subtitle")
8383 , ("title" , lineOfInlines `parseThen` collectLines "title")
8484 -- LaTeX
85− , ("latex_class", fmap pure anyLine `parseThen` setField "documentclass")
85+ , ("latex_class" , fmap pure anyLine `parseThen` setField "documentclass")
8686 , ("latex_class_options", (pure . T.filter (`notElem` ("[]" :: String)) <$> anyLine)
8787 `parseThen` setField "classoption")
88− , ("latex_header", metaExportSnippet "latex" `parseThen`
89− collectAsList "header-includes")
88+ , ("latex_header" , metaExportSnippet "latex" `parseThen`
89+ collectAsList "header-includes")
90+ , ("latex_header_extra", metaExportSnippet "latex" `parseThen`
91+ collectAsList "header-includes")
9092 -- HTML
91− , ("html_head" , metaExportSnippet "html" `parseThen`
92− collectAsList "header-includes")
93+ , ("html_head" , metaExportSnippet "html" `parseThen`
94+ collectAsList "header-includes")
95+ , ("html_head_extra", metaExportSnippet "html" `parseThen`
96+ collectAsList "header-includes")
9397 -- pandoc-specific
9498 , ("nocite" , lineOfInlines `parseThen` collectLines "nocite")
9599 , ("header-includes", lineOfInlines `parseThen` collectLines "header-includes")
test/Tests/Readers/Org/Meta.hs+49−29
@@ -108,42 +108,62 @@ tests =
108108 meta = setMeta "keywords" (MetaInlines keywords) nullMeta
109109 in Pandoc meta mempty
110110
111− , "LaTeX_headers options are translated to header-includes" =:
112− "#+LaTeX_header: \\usepackage{tikz}" =?>
113− let latexInlines = rawInline "latex" "\\usepackage{tikz}"
114− inclList = MetaList [MetaInlines (toList latexInlines)]
115− meta = setMeta "header-includes" inclList nullMeta
116− in Pandoc meta mempty
111+ , "Institute" =:
112+ "#+INSTITUTE: ACME Inc." =?>
113+ Pandoc (setMeta "institute" ("ACME Inc." :: Inlines) nullMeta) mempty
117114
118− , testGroup "LaTeX_CLASS"
119− [ "LaTeX_class option is translated to documentclass" =:
120− "#+LATEX_CLASS: article" =?>
121− let meta = setMeta "documentclass" (MetaString "article") nullMeta
115+ , testGroup "LaTeX"
116+ [ "LaTeX_headers options are translated to header-includes" =:
117+ "#+LaTeX_header: \\usepackage{tikz}" =?>
118+ let latexInlines = rawInline "latex" "\\usepackage{tikz}"
119+ inclList = MetaList [MetaInlines (toList latexInlines)]
120+ meta = setMeta "header-includes" inclList nullMeta
122121 in Pandoc meta mempty
123122
124− , "last definition takes precedence" =:
125− T.unlines [ "#+LATEX_CLASS: this will not be used"
126− , "#+LATEX_CLASS: report"
127− ] =?>
128− let meta = setMeta "documentclass" (MetaString "report") nullMeta
123+ , "LATEX_HEADER_EXTRA values are translated to header-includes" =:
124+ "#+LATEX_HEADER_EXTRA: \\usepackage{calc}" =?>
125+ let latexInlines = rawInline "latex" "\\usepackage{calc}"
126+ inclList = toMetaValue [latexInlines]
127+ in Pandoc (setMeta "header-includes" inclList nullMeta) mempty
128+
129+ , testGroup "LaTeX_CLASS"
130+ [ "LaTeX_class option is translated to documentclass" =:
131+ "#+LATEX_CLASS: article" =?>
132+ let meta = setMeta "documentclass" (MetaString "article") nullMeta
133+ in Pandoc meta mempty
134+
135+ , "last definition takes precedence" =:
136+ T.unlines [ "#+LATEX_CLASS: this will not be used"
137+ , "#+LATEX_CLASS: report"
138+ ] =?>
139+ let meta = setMeta "documentclass" (MetaString "report") nullMeta
140+ in Pandoc meta mempty
141+ ]
142+
143+ , "LaTeX_class_options is translated to classoption" =:
144+ "#+LATEX_CLASS_OPTIONS: [a4paper]" =?>
145+ let meta = setMeta "classoption" (MetaString "a4paper") nullMeta
129146 in Pandoc meta mempty
130147 ]
131148
132− , "LaTeX_class_options is translated to classoption" =:
133− "#+LATEX_CLASS_OPTIONS: [a4paper]" =?>
134− let meta = setMeta "classoption" (MetaString "a4paper") nullMeta
135− in Pandoc meta mempty
136−
137− , "LaTeX_class_options is translated to classoption" =:
138− "#+html_head: <meta/>" =?>
139− let html = rawInline "html" "<meta/>"
140− inclList = MetaList [MetaInlines (toList html)]
141− meta = setMeta "header-includes" inclList nullMeta
142− in Pandoc meta mempty
149+ , testGroup "HTML"
150+ [ "HTML_HEAD values are added to header-includes" =:
151+ "#+html_head: <meta/>" =?>
152+ let html = rawInline "html" "<meta/>"
153+ inclList = MetaList [MetaInlines (toList html)]
154+ meta = setMeta "header-includes" inclList nullMeta
155+ in Pandoc meta mempty
143156
144− , "Institute" =:
145− "#+INSTITUTE: ACME Inc." =?>
146− Pandoc (setMeta "institute" ("ACME Inc." :: Inlines) nullMeta) mempty
157+ , "HTML_HEAD_EXTRA behaves like HTML_HEAD" =:
158+ T.unlines [ "#+HTML_HEAD: <meta name=\"generator\" content=\"pandoc\">"
159+ , "#+HTML_HEAD_EXTRA: <meta charset=\"utf-8\">"
160+ ] =?>
161+ let generator = rawInline "html"
162+ "<meta name=\"generator\" content=\"pandoc\">"
163+ charset = rawInline "html" "<meta charset=\"utf-8\">"
164+ inclList = toMetaValue [generator, charset]
165+ in Pandoc (setMeta "header-includes" inclList nullMeta) mempty
166+ ]
147167 ]
148168
149169 , "Properties drawer" =: