git.iko.soy/typeable/pandoc
on 4eff607 help sign in
446 lines 21 kB history raw
1{-# LANGUAGE DeriveDataTypeable, DeriveGeneric #-}
2{-
3Copyright (C) 2012-2016 John MacFarlane <jgm@berkeley.edu>
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation; either version 2 of the License, or
8(at your option) any later version.
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18-}
20{- |
21 Module : Text.Pandoc.Options
22 Copyright : Copyright (C) 2012-2016 John MacFarlane
23 License : GNU GPL, version 2 or above
25 Maintainer : John MacFarlane <jgm@berkeley.edu>
26 Stability : alpha
27 Portability : portable
29Data structures and functions for representing parser and writer
30options.
31-}
32module Text.Pandoc.Options ( Extension(..)
33 , pandocExtensions
34 , plainExtensions
35 , strictExtensions
36 , phpMarkdownExtraExtensions
37 , githubMarkdownExtensions
38 , multimarkdownExtensions
39 , ReaderOptions(..)
40 , HTMLMathMethod (..)
41 , CiteMethod (..)
42 , ObfuscationMethod (..)
43 , HTMLSlideVariant (..)
44 , EPUBVersion (..)
45 , WrapOption (..)
46 , WriterOptions (..)
47 , TrackChanges (..)
48 , ReferenceLocation (..)
49 , def
50 , isEnabled
51 ) where
52import Data.Set (Set)
53import qualified Data.Set as Set
54import Data.Default
55import Text.Pandoc.Highlighting (Style, pygments)
56import Text.Pandoc.MediaBag (MediaBag)
57import Data.Data (Data)
58import Data.Typeable (Typeable)
59import GHC.Generics (Generic)
61-- | Individually selectable syntax extensions.
62data Extension =
63 Ext_footnotes -- ^ Pandoc/PHP/MMD style footnotes
64 | Ext_inline_notes -- ^ Pandoc-style inline notes
65 | Ext_pandoc_title_block -- ^ Pandoc title block
66 | Ext_yaml_metadata_block -- ^ YAML metadata block
67 | Ext_mmd_title_block -- ^ Multimarkdown metadata block
68 | Ext_table_captions -- ^ Pandoc-style table captions
69 | Ext_implicit_figures -- ^ A paragraph with just an image is a figure
70 | Ext_simple_tables -- ^ Pandoc-style simple tables
71 | Ext_multiline_tables -- ^ Pandoc-style multiline tables
72 | Ext_grid_tables -- ^ Grid tables (pandoc, reST)
73 | Ext_pipe_tables -- ^ Pipe tables (as in PHP markdown extra)
74 | Ext_citations -- ^ Pandoc/citeproc citations
75 | Ext_raw_tex -- ^ Allow raw TeX (other than math)
76 | Ext_raw_html -- ^ Allow raw HTML
77 | Ext_tex_math_dollars -- ^ TeX math between $..$ or $$..$$
78 | Ext_tex_math_single_backslash -- ^ TeX math btw \(..\) \[..\]
79 | Ext_tex_math_double_backslash -- ^ TeX math btw \\(..\\) \\[..\\]
80 | Ext_latex_macros -- ^ Parse LaTeX macro definitions (for math only)
81 | Ext_fenced_code_blocks -- ^ Parse fenced code blocks
82 | Ext_fenced_code_attributes -- ^ Allow attributes on fenced code blocks
83 | Ext_backtick_code_blocks -- ^ GitHub style ``` code blocks
84 | Ext_inline_code_attributes -- ^ Allow attributes on inline code
85 | Ext_markdown_in_html_blocks -- ^ Interpret as markdown inside HTML blocks
86 | Ext_native_divs -- ^ Use Div blocks for contents of <div> tags
87 | Ext_native_spans -- ^ Use Span inlines for contents of <span>
88 | Ext_bracketed_spans -- ^ Bracketed spans with attributes
89 | Ext_markdown_attribute -- ^ Interpret text inside HTML as markdown
90 -- iff container has attribute 'markdown'
91 | Ext_escaped_line_breaks -- ^ Treat a backslash at EOL as linebreak
92 | Ext_link_attributes -- ^ link and image attributes
93 | Ext_mmd_link_attributes -- ^ MMD style reference link attributes
94 | Ext_autolink_bare_uris -- ^ Make all absolute URIs into links
95 | Ext_fancy_lists -- ^ Enable fancy list numbers and delimiters
96 | Ext_lists_without_preceding_blankline -- ^ Allow lists without preceding blank
97 | Ext_startnum -- ^ Make start number of ordered list significant
98 | Ext_definition_lists -- ^ Definition lists as in pandoc, mmd, php
99 | Ext_compact_definition_lists -- ^ Definition lists without
100 -- space between items, and disallow laziness
101 | Ext_example_lists -- ^ Markdown-style numbered examples
102 | Ext_all_symbols_escapable -- ^ Make all non-alphanumerics escapable
103 | Ext_intraword_underscores -- ^ Treat underscore inside word as literal
104 | Ext_blank_before_blockquote -- ^ Require blank line before a blockquote
105 | Ext_blank_before_header -- ^ Require blank line before a header
106 | Ext_strikeout -- ^ Strikeout using ~~this~~ syntax
107 | Ext_superscript -- ^ Superscript using ^this^ syntax
108 | Ext_subscript -- ^ Subscript using ~this~ syntax
109 | Ext_hard_line_breaks -- ^ All newlines become hard line breaks
110 | Ext_ignore_line_breaks -- ^ Newlines in paragraphs are ignored
111 | Ext_east_asian_line_breaks -- ^ Newlines in paragraphs are ignored between
112 -- East Asian wide characters
113 | Ext_literate_haskell -- ^ Enable literate Haskell conventions
114 | Ext_abbreviations -- ^ PHP markdown extra abbreviation definitions
115 | Ext_emoji -- ^ Support emoji like :smile:
116 | Ext_auto_identifiers -- ^ Automatic identifiers for headers
117 | Ext_ascii_identifiers -- ^ ascii-only identifiers for headers
118 | Ext_header_attributes -- ^ Explicit header attributes {#id .class k=v}
119 | Ext_mmd_header_identifiers -- ^ Multimarkdown style header identifiers [myid]
120 | Ext_implicit_header_references -- ^ Implicit reference links for headers
121 | Ext_line_blocks -- ^ RST style line blocks
122 | Ext_epub_html_exts -- ^ Recognise the EPUB extended version of HTML
123 | Ext_shortcut_reference_links -- ^ Shortcut reference links
124 deriving (Show, Read, Enum, Eq, Ord, Bounded, Data, Typeable, Generic)
126pandocExtensions :: Set Extension
127pandocExtensions = Set.fromList
128 [ Ext_footnotes
129 , Ext_inline_notes
130 , Ext_pandoc_title_block
131 , Ext_yaml_metadata_block
132 , Ext_table_captions
133 , Ext_implicit_figures
134 , Ext_simple_tables
135 , Ext_multiline_tables
136 , Ext_grid_tables
137 , Ext_pipe_tables
138 , Ext_citations
139 , Ext_raw_tex
140 , Ext_raw_html
141 , Ext_tex_math_dollars
142 , Ext_latex_macros
143 , Ext_fenced_code_blocks
144 , Ext_fenced_code_attributes
145 , Ext_backtick_code_blocks
146 , Ext_inline_code_attributes
147 , Ext_markdown_in_html_blocks
148 , Ext_native_divs
149 , Ext_native_spans
150 , Ext_bracketed_spans
151 , Ext_escaped_line_breaks
152 , Ext_fancy_lists
153 , Ext_startnum
154 , Ext_definition_lists
155 , Ext_example_lists
156 , Ext_all_symbols_escapable
157 , Ext_intraword_underscores
158 , Ext_blank_before_blockquote
159 , Ext_blank_before_header
160 , Ext_strikeout
161 , Ext_superscript
162 , Ext_subscript
163 , Ext_auto_identifiers
164 , Ext_header_attributes
165 , Ext_link_attributes
166 , Ext_implicit_header_references
167 , Ext_line_blocks
168 , Ext_shortcut_reference_links
169 ]
171plainExtensions :: Set Extension
172plainExtensions = Set.fromList
173 [ Ext_table_captions
174 , Ext_implicit_figures
175 , Ext_simple_tables
176 , Ext_multiline_tables
177 , Ext_grid_tables
178 , Ext_latex_macros
179 , Ext_fancy_lists
180 , Ext_startnum
181 , Ext_definition_lists
182 , Ext_example_lists
183 , Ext_intraword_underscores
184 , Ext_blank_before_blockquote
185 , Ext_blank_before_header
186 , Ext_strikeout
187 ]
189phpMarkdownExtraExtensions :: Set Extension
190phpMarkdownExtraExtensions = Set.fromList
191 [ Ext_footnotes
192 , Ext_pipe_tables
193 , Ext_raw_html
194 , Ext_markdown_attribute
195 , Ext_fenced_code_blocks
196 , Ext_definition_lists
197 , Ext_intraword_underscores
198 , Ext_header_attributes
199 , Ext_link_attributes
200 , Ext_abbreviations
201 , Ext_shortcut_reference_links
202 ]
204githubMarkdownExtensions :: Set Extension
205githubMarkdownExtensions = Set.fromList
206 [ Ext_pipe_tables
207 , Ext_raw_html
208 , Ext_fenced_code_blocks
209 , Ext_auto_identifiers
210 , Ext_ascii_identifiers
211 , Ext_backtick_code_blocks
212 , Ext_autolink_bare_uris
213 , Ext_intraword_underscores
214 , Ext_strikeout
215 , Ext_hard_line_breaks
216 , Ext_emoji
217 , Ext_lists_without_preceding_blankline
218 , Ext_shortcut_reference_links
219 ]
221multimarkdownExtensions :: Set Extension
222multimarkdownExtensions = Set.fromList
223 [ Ext_pipe_tables
224 , Ext_raw_html
225 , Ext_markdown_attribute
226 , Ext_mmd_link_attributes
227 -- , Ext_raw_tex
228 -- Note: MMD's raw TeX syntax requires raw TeX to be
229 -- enclosed in HTML comment
230 , Ext_tex_math_double_backslash
231 , Ext_intraword_underscores
232 , Ext_mmd_title_block
233 , Ext_footnotes
234 , Ext_definition_lists
235 , Ext_all_symbols_escapable
236 , Ext_implicit_header_references
237 , Ext_auto_identifiers
238 , Ext_mmd_header_identifiers
239 , Ext_implicit_figures
240 -- Note: MMD's syntax for superscripts and subscripts
241 -- is a bit more permissive than pandoc's, allowing
242 -- e^2 and a~1 instead of e^2^ and a~1~, so even with
243 -- these options we don't have full support for MMD
244 -- superscripts and subscripts, but there's no reason
245 -- not to include these:
246 , Ext_superscript
247 , Ext_subscript
248 ]
250strictExtensions :: Set Extension
251strictExtensions = Set.fromList
252 [ Ext_raw_html
253 , Ext_shortcut_reference_links
254 ]
256data ReaderOptions = ReaderOptions{
257 readerExtensions :: Set Extension -- ^ Syntax extensions
258 , readerSmart :: Bool -- ^ Smart punctuation
259 , readerStandalone :: Bool -- ^ Standalone document with header
260 , readerParseRaw :: Bool -- ^ Parse raw HTML, LaTeX
261 , readerColumns :: Int -- ^ Number of columns in terminal
262 , readerTabStop :: Int -- ^ Tab stop
263 , readerOldDashes :: Bool -- ^ Use pandoc <= 1.8.2.1 behavior
264 -- in parsing dashes; -- is em-dash;
265 -- - before numerial is en-dash
266 , readerApplyMacros :: Bool -- ^ Apply macros to TeX math
267 , readerIndentedCodeClasses :: [String] -- ^ Default classes for
268 -- indented code blocks
269 , readerDefaultImageExtension :: String -- ^ Default extension for images
270 , readerTrace :: Bool -- ^ Print debugging info
271 , readerTrackChanges :: TrackChanges
272 , readerFileScope :: Bool -- ^ Parse before combining
273} deriving (Show, Read, Data, Typeable, Generic)
275instance Default ReaderOptions
276 where def = ReaderOptions{
277 readerExtensions = pandocExtensions
278 , readerSmart = False
279 , readerStandalone = False
280 , readerParseRaw = False
281 , readerColumns = 80
282 , readerTabStop = 4
283 , readerOldDashes = False
284 , readerApplyMacros = True
285 , readerIndentedCodeClasses = []
286 , readerDefaultImageExtension = ""
287 , readerTrace = False
288 , readerTrackChanges = AcceptChanges
289 , readerFileScope = False
290 }
292--
293-- Writer options
294--
296data EPUBVersion = EPUB2 | EPUB3 deriving (Eq, Show, Read, Data, Typeable, Generic)
298data HTMLMathMethod = PlainMath
299 | LaTeXMathML (Maybe String) -- url of LaTeXMathML.js
300 | JsMath (Maybe String) -- url of jsMath load script
301 | GladTeX
302 | WebTeX String -- url of TeX->image script.
303 | MathML (Maybe String) -- url of MathMLinHTML.js
304 | MathJax String -- url of MathJax.js
305 | KaTeX String String -- url of stylesheet and katex.js
306 deriving (Show, Read, Eq, Data, Typeable, Generic)
308data CiteMethod = Citeproc -- use citeproc to render them
309 | Natbib -- output natbib cite commands
310 | Biblatex -- output biblatex cite commands
311 deriving (Show, Read, Eq, Data, Typeable, Generic)
313-- | Methods for obfuscating email addresses in HTML.
314data ObfuscationMethod = NoObfuscation
315 | ReferenceObfuscation
316 | JavascriptObfuscation
317 deriving (Show, Read, Eq, Data, Typeable, Generic)
319-- | Varieties of HTML slide shows.
320data HTMLSlideVariant = S5Slides
321 | SlidySlides
322 | SlideousSlides
323 | DZSlides
324 | RevealJsSlides
325 | NoSlides
326 deriving (Show, Read, Eq, Data, Typeable, Generic)
328-- | Options for accepting or rejecting MS Word track-changes.
329data TrackChanges = AcceptChanges
330 | RejectChanges
331 | AllChanges
332 deriving (Show, Read, Eq, Data, Typeable, Generic)
334-- | Options for wrapping text in the output.
335data WrapOption = WrapAuto -- ^ Automatically wrap to width
336 | WrapNone -- ^ No non-semantic newlines
337 | WrapPreserve -- ^ Preserve wrapping of input source
338 deriving (Show, Read, Eq, Data, Typeable, Generic)
340-- | Locations for footnotes and references in markdown output
341data ReferenceLocation = EndOfBlock -- ^ End of block
342 | EndOfSection -- ^ prior to next section header (or end of document)
343 | EndOfDocument -- ^ at end of document
344 deriving (Show, Read, Eq, Data, Typeable, Generic)
346-- | Options for writers
347data WriterOptions = WriterOptions
348 { writerStandalone :: Bool -- ^ Include header and footer
349 , writerTemplate :: String -- ^ Template to use in standalone mode
350 , writerVariables :: [(String, String)] -- ^ Variables to set in template
351 , writerTabStop :: Int -- ^ Tabstop for conversion btw spaces and tabs
352 , writerTableOfContents :: Bool -- ^ Include table of contents
353 , writerSlideVariant :: HTMLSlideVariant -- ^ Are we writing S5, Slidy or Slideous?
354 , writerIncremental :: Bool -- ^ True if lists should be incremental
355 , writerHTMLMathMethod :: HTMLMathMethod -- ^ How to print math in HTML
356 , writerIgnoreNotes :: Bool -- ^ Ignore footnotes (used in making toc)
357 , writerNumberSections :: Bool -- ^ Number sections in LaTeX
358 , writerNumberOffset :: [Int] -- ^ Starting number for section, subsection, ...
359 , writerSectionDivs :: Bool -- ^ Put sections in div tags in HTML
360 , writerExtensions :: Set Extension -- ^ Markdown extensions that can be used
361 , writerReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
362 , writerDpi :: Int -- ^ Dpi for pixel to/from inch/cm conversions
363 , writerWrapText :: WrapOption -- ^ Option for wrapping text
364 , writerColumns :: Int -- ^ Characters in a line (for text wrapping)
365 , writerEmailObfuscation :: ObfuscationMethod -- ^ How to obfuscate emails
366 , writerIdentifierPrefix :: String -- ^ Prefix for section & note ids in HTML
367 -- and for footnote marks in markdown
368 , writerSourceURL :: Maybe String -- ^ Absolute URL + directory of 1st source file
369 , writerUserDataDir :: Maybe FilePath -- ^ Path of user data directory
370 , writerCiteMethod :: CiteMethod -- ^ How to print cites
371 , writerDocbook5 :: Bool -- ^ Produce DocBook5
372 , writerHtml5 :: Bool -- ^ Produce HTML5
373 , writerHtmlQTags :: Bool -- ^ Use @<q>@ tags for quotes in HTML
374 , writerBeamer :: Bool -- ^ Produce beamer LaTeX slide show
375 , writerSlideLevel :: Maybe Int -- ^ Force header level of slides
376 , writerChapters :: Bool -- ^ Use "chapter" for top-level sects
377 , writerListings :: Bool -- ^ Use listings package for code
378 , writerHighlight :: Bool -- ^ Highlight source code
379 , writerHighlightStyle :: Style -- ^ Style to use for highlighting
380 , writerSetextHeaders :: Bool -- ^ Use setext headers for levels 1-2 in markdown
381 , writerTeXLigatures :: Bool -- ^ Use tex ligatures quotes, dashes in latex
382 , writerEpubVersion :: Maybe EPUBVersion -- ^ Nothing or EPUB version
383 , writerEpubMetadata :: String -- ^ Metadata to include in EPUB
384 , writerEpubStylesheet :: Maybe String -- ^ EPUB stylesheet specified at command line
385 , writerEpubFonts :: [FilePath] -- ^ Paths to fonts to embed
386 , writerEpubChapterLevel :: Int -- ^ Header level for chapters (separate files)
387 , writerTOCDepth :: Int -- ^ Number of levels to include in TOC
388 , writerReferenceODT :: Maybe FilePath -- ^ Path to reference ODT if specified
389 , writerReferenceDocx :: Maybe FilePath -- ^ Path to reference DOCX if specified
390 , writerMediaBag :: MediaBag -- ^ Media collected by docx or epub reader
391 , writerVerbose :: Bool -- ^ Verbose debugging output
392 , writerLaTeXArgs :: [String] -- ^ Flags to pass to latex-engine
393 , writerReferenceLocation :: ReferenceLocation -- ^ Location of footnotes and references for writing markdown
394 } deriving (Show, Data, Typeable, Generic)
396instance Default WriterOptions where
397 def = WriterOptions { writerStandalone = False
398 , writerTemplate = ""
399 , writerVariables = []
400 , writerTabStop = 4
401 , writerTableOfContents = False
402 , writerSlideVariant = NoSlides
403 , writerIncremental = False
404 , writerHTMLMathMethod = PlainMath
405 , writerIgnoreNotes = False
406 , writerNumberSections = False
407 , writerNumberOffset = [0,0,0,0,0,0]
408 , writerSectionDivs = False
409 , writerExtensions = pandocExtensions
410 , writerReferenceLinks = False
411 , writerDpi = 96
412 , writerWrapText = WrapAuto
413 , writerColumns = 72
414 , writerEmailObfuscation = NoObfuscation
415 , writerIdentifierPrefix = ""
416 , writerSourceURL = Nothing
417 , writerUserDataDir = Nothing
418 , writerCiteMethod = Citeproc
419 , writerDocbook5 = False
420 , writerHtml5 = False
421 , writerHtmlQTags = False
422 , writerBeamer = False
423 , writerSlideLevel = Nothing
424 , writerChapters = False
425 , writerListings = False
426 , writerHighlight = False
427 , writerHighlightStyle = pygments
428 , writerSetextHeaders = True
429 , writerTeXLigatures = True
430 , writerEpubVersion = Nothing
431 , writerEpubMetadata = ""
432 , writerEpubStylesheet = Nothing
433 , writerEpubFonts = []
434 , writerEpubChapterLevel = 1
435 , writerTOCDepth = 3
436 , writerReferenceODT = Nothing
437 , writerReferenceDocx = Nothing
438 , writerMediaBag = mempty
439 , writerVerbose = False
440 , writerLaTeXArgs = []
441 , writerReferenceLocation = EndOfDocument
442 }
444-- | Returns True if the given extension is enabled.
445isEnabled :: Extension -> WriterOptions -> Bool
446isEnabled ext opts = ext `Set.member` (writerExtensions opts)