git.iko.soy/typeable/pandoc
on master help sign in
Split extensions code from Options into separate Text.Pandoc.Extensions.

API change. However, Extensions exports Options, so this shouldn't have much impact.

commit14272521600f9a616c07333261fa258b3dc5c487 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 14 Jan 2017, 10:29 (10 years ago) parent93e4cd9
3 files changed+250−205
pandoc.cabal+2 src/Text/Pandoc/Extensions.hs+245 src/Text/Pandoc/Options.hs+3−205
pandoc.cabal+2
@@ -257,6 +257,7 @@ Library
257257 containers >= 0.1 && < 0.6,
258258 unordered-containers >= 0.2 && < 0.3,
259259 array >= 0.3 && < 0.6,
260+ largeword >= 1.2 && < 1.3,
260261 parsec >= 3.1 && < 3.2,
261262 mtl >= 2.2 && < 2.3,
262263 filepath >= 1.1 && < 1.5,
@@ -328,6 +329,7 @@ Library
328329
329330 Exposed-Modules: Text.Pandoc,
330331 Text.Pandoc.Options,
332+ Text.Pandoc.Extensions,
331333 Text.Pandoc.Pretty,
332334 Text.Pandoc.Shared,
333335 Text.Pandoc.MediaBag,
src/Text/Pandoc/Extensions.hsnew file+245
@@ -0,0 +1,245 @@
1+{-# LANGUAGE DeriveDataTypeable, DeriveGeneric #-}
2+{-
3+Copyright (C) 2012-2016 John MacFarlane <jgm@berkeley.edu>
4+
5+This program is free software; you can redistribute it and/or modify
6+it under the terms of the GNU General Public License as published by
7+the Free Software Foundation; either version 2 of the License, or
8+(at your option) any later version.
9+
10+This program is distributed in the hope that it will be useful,
11+but WITHOUT ANY WARRANTY; without even the implied warranty of
12+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+GNU General Public License for more details.
14+
15+You should have received a copy of the GNU General Public License
16+along with this program; if not, write to the Free Software
17+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18+-}
19+
20+{- |
21+ Module : Text.Pandoc.Extensions
22+ Copyright : Copyright (C) 2012-2016 John MacFarlane
23+ License : GNU GPL, version 2 or above
24+
25+ Maintainer : John MacFarlane <jgm@berkeley.edu>
26+ Stability : alpha
27+ Portability : portable
28+
29+Data structures and functions for representing markup extensions.
30+-}
31+module Text.Pandoc.Extensions ( Extension(..)
32+ , pandocExtensions
33+ , plainExtensions
34+ , strictExtensions
35+ , phpMarkdownExtraExtensions
36+ , githubMarkdownExtensions
37+ , multimarkdownExtensions )
38+where
39+import Data.LargeWord (Word256)
40+import Data.Bits ()
41+import Data.Set (Set)
42+import qualified Data.Set as Set
43+import Data.Data (Data)
44+import Data.Typeable (Typeable)
45+import GHC.Generics (Generic)
46+
47+newtype Extensions = Extensions { unExtensions :: Word256 }
48+
49+-- | Individually selectable syntax extensions.
50+data Extension =
51+ Ext_footnotes -- ^ Pandoc/PHP/MMD style footnotes
52+ | Ext_inline_notes -- ^ Pandoc-style inline notes
53+ | Ext_pandoc_title_block -- ^ Pandoc title block
54+ | Ext_yaml_metadata_block -- ^ YAML metadata block
55+ | Ext_mmd_title_block -- ^ Multimarkdown metadata block
56+ | Ext_table_captions -- ^ Pandoc-style table captions
57+ | Ext_implicit_figures -- ^ A paragraph with just an image is a figure
58+ | Ext_simple_tables -- ^ Pandoc-style simple tables
59+ | Ext_multiline_tables -- ^ Pandoc-style multiline tables
60+ | Ext_grid_tables -- ^ Grid tables (pandoc, reST)
61+ | Ext_pipe_tables -- ^ Pipe tables (as in PHP markdown extra)
62+ | Ext_citations -- ^ Pandoc/citeproc citations
63+ | Ext_raw_tex -- ^ Allow raw TeX (other than math)
64+ | Ext_raw_html -- ^ Allow raw HTML
65+ | Ext_tex_math_dollars -- ^ TeX math between $..$ or $$..$$
66+ | Ext_tex_math_single_backslash -- ^ TeX math btw \(..\) \[..\]
67+ | Ext_tex_math_double_backslash -- ^ TeX math btw \\(..\\) \\[..\\]
68+ | Ext_latex_macros -- ^ Parse LaTeX macro definitions (for math only)
69+ | Ext_fenced_code_blocks -- ^ Parse fenced code blocks
70+ | Ext_fenced_code_attributes -- ^ Allow attributes on fenced code blocks
71+ | Ext_backtick_code_blocks -- ^ GitHub style ``` code blocks
72+ | Ext_inline_code_attributes -- ^ Allow attributes on inline code
73+ | Ext_markdown_in_html_blocks -- ^ Interpret as markdown inside HTML blocks
74+ | Ext_native_divs -- ^ Use Div blocks for contents of <div> tags
75+ | Ext_native_spans -- ^ Use Span inlines for contents of <span>
76+ | Ext_bracketed_spans -- ^ Bracketed spans with attributes
77+ | Ext_markdown_attribute -- ^ Interpret text inside HTML as markdown
78+ -- iff container has attribute 'markdown'
79+ | Ext_escaped_line_breaks -- ^ Treat a backslash at EOL as linebreak
80+ | Ext_link_attributes -- ^ link and image attributes
81+ | Ext_mmd_link_attributes -- ^ MMD style reference link attributes
82+ | Ext_autolink_bare_uris -- ^ Make all absolute URIs into links
83+ | Ext_fancy_lists -- ^ Enable fancy list numbers and delimiters
84+ | Ext_lists_without_preceding_blankline -- ^ Allow lists without preceding blank
85+ | Ext_startnum -- ^ Make start number of ordered list significant
86+ | Ext_definition_lists -- ^ Definition lists as in pandoc, mmd, php
87+ | Ext_compact_definition_lists -- ^ Definition lists without
88+ -- space between items, and disallow laziness
89+ | Ext_example_lists -- ^ Markdown-style numbered examples
90+ | Ext_all_symbols_escapable -- ^ Make all non-alphanumerics escapable
91+ | Ext_angle_brackets_escapable -- ^ Make < and > escapable
92+ | Ext_intraword_underscores -- ^ Treat underscore inside word as literal
93+ | Ext_blank_before_blockquote -- ^ Require blank line before a blockquote
94+ | Ext_blank_before_header -- ^ Require blank line before a header
95+ | Ext_strikeout -- ^ Strikeout using ~~this~~ syntax
96+ | Ext_superscript -- ^ Superscript using ^this^ syntax
97+ | Ext_subscript -- ^ Subscript using ~this~ syntax
98+ | Ext_hard_line_breaks -- ^ All newlines become hard line breaks
99+ | Ext_ignore_line_breaks -- ^ Newlines in paragraphs are ignored
100+ | Ext_east_asian_line_breaks -- ^ Newlines in paragraphs are ignored between
101+ -- East Asian wide characters
102+ | Ext_literate_haskell -- ^ Enable literate Haskell conventions
103+ | Ext_abbreviations -- ^ PHP markdown extra abbreviation definitions
104+ | Ext_emoji -- ^ Support emoji like :smile:
105+ | Ext_auto_identifiers -- ^ Automatic identifiers for headers
106+ | Ext_ascii_identifiers -- ^ ascii-only identifiers for headers
107+ | Ext_header_attributes -- ^ Explicit header attributes {#id .class k=v}
108+ | Ext_mmd_header_identifiers -- ^ Multimarkdown style header identifiers [myid]
109+ | Ext_implicit_header_references -- ^ Implicit reference links for headers
110+ | Ext_line_blocks -- ^ RST style line blocks
111+ | Ext_epub_html_exts -- ^ Recognise the EPUB extended version of HTML
112+ | Ext_shortcut_reference_links -- ^ Shortcut reference links
113+ deriving (Show, Read, Enum, Eq, Ord, Bounded, Data, Typeable, Generic)
114+
115+pandocExtensions :: Set Extension
116+pandocExtensions = Set.fromList
117+ [ Ext_footnotes
118+ , Ext_inline_notes
119+ , Ext_pandoc_title_block
120+ , Ext_yaml_metadata_block
121+ , Ext_table_captions
122+ , Ext_implicit_figures
123+ , Ext_simple_tables
124+ , Ext_multiline_tables
125+ , Ext_grid_tables
126+ , Ext_pipe_tables
127+ , Ext_citations
128+ , Ext_raw_tex
129+ , Ext_raw_html
130+ , Ext_tex_math_dollars
131+ , Ext_latex_macros
132+ , Ext_fenced_code_blocks
133+ , Ext_fenced_code_attributes
134+ , Ext_backtick_code_blocks
135+ , Ext_inline_code_attributes
136+ , Ext_markdown_in_html_blocks
137+ , Ext_native_divs
138+ , Ext_native_spans
139+ , Ext_bracketed_spans
140+ , Ext_escaped_line_breaks
141+ , Ext_fancy_lists
142+ , Ext_startnum
143+ , Ext_definition_lists
144+ , Ext_example_lists
145+ , Ext_all_symbols_escapable
146+ , Ext_intraword_underscores
147+ , Ext_blank_before_blockquote
148+ , Ext_blank_before_header
149+ , Ext_strikeout
150+ , Ext_superscript
151+ , Ext_subscript
152+ , Ext_auto_identifiers
153+ , Ext_header_attributes
154+ , Ext_link_attributes
155+ , Ext_implicit_header_references
156+ , Ext_line_blocks
157+ , Ext_shortcut_reference_links
158+ ]
159+
160+plainExtensions :: Set Extension
161+plainExtensions = Set.fromList
162+ [ Ext_table_captions
163+ , Ext_implicit_figures
164+ , Ext_simple_tables
165+ , Ext_multiline_tables
166+ , Ext_grid_tables
167+ , Ext_latex_macros
168+ , Ext_fancy_lists
169+ , Ext_startnum
170+ , Ext_definition_lists
171+ , Ext_example_lists
172+ , Ext_intraword_underscores
173+ , Ext_blank_before_blockquote
174+ , Ext_blank_before_header
175+ , Ext_strikeout
176+ ]
177+
178+phpMarkdownExtraExtensions :: Set Extension
179+phpMarkdownExtraExtensions = Set.fromList
180+ [ Ext_footnotes
181+ , Ext_pipe_tables
182+ , Ext_raw_html
183+ , Ext_markdown_attribute
184+ , Ext_fenced_code_blocks
185+ , Ext_definition_lists
186+ , Ext_intraword_underscores
187+ , Ext_header_attributes
188+ , Ext_link_attributes
189+ , Ext_abbreviations
190+ , Ext_shortcut_reference_links
191+ ]
192+
193+githubMarkdownExtensions :: Set Extension
194+githubMarkdownExtensions = Set.fromList
195+ [ Ext_angle_brackets_escapable
196+ , Ext_pipe_tables
197+ , Ext_raw_html
198+ , Ext_fenced_code_blocks
199+ , Ext_auto_identifiers
200+ , Ext_ascii_identifiers
201+ , Ext_backtick_code_blocks
202+ , Ext_autolink_bare_uris
203+ , Ext_intraword_underscores
204+ , Ext_strikeout
205+ , Ext_hard_line_breaks
206+ , Ext_emoji
207+ , Ext_lists_without_preceding_blankline
208+ , Ext_shortcut_reference_links
209+ ]
210+
211+multimarkdownExtensions :: Set Extension
212+multimarkdownExtensions = Set.fromList
213+ [ Ext_pipe_tables
214+ , Ext_raw_html
215+ , Ext_markdown_attribute
216+ , Ext_mmd_link_attributes
217+ -- , Ext_raw_tex
218+ -- Note: MMD's raw TeX syntax requires raw TeX to be
219+ -- enclosed in HTML comment
220+ , Ext_tex_math_double_backslash
221+ , Ext_intraword_underscores
222+ , Ext_mmd_title_block
223+ , Ext_footnotes
224+ , Ext_definition_lists
225+ , Ext_all_symbols_escapable
226+ , Ext_implicit_header_references
227+ , Ext_auto_identifiers
228+ , Ext_mmd_header_identifiers
229+ , Ext_implicit_figures
230+ -- Note: MMD's syntax for superscripts and subscripts
231+ -- is a bit more permissive than pandoc's, allowing
232+ -- e^2 and a~1 instead of e^2^ and a~1~, so even with
233+ -- these options we don't have full support for MMD
234+ -- superscripts and subscripts, but there's no reason
235+ -- not to include these:
236+ , Ext_superscript
237+ , Ext_subscript
238+ ]
239+
240+strictExtensions :: Set Extension
241+strictExtensions = Set.fromList
242+ [ Ext_raw_html
243+ , Ext_shortcut_reference_links
244+ ]
245+
src/Text/Pandoc/Options.hs+3−205
@@ -29,13 +29,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2929Data structures and functions for representing parser and writer
3030options.
3131-}
32−module Text.Pandoc.Options ( Extension(..)
33− , pandocExtensions
34− , plainExtensions
35− , strictExtensions
36− , phpMarkdownExtraExtensions
37− , githubMarkdownExtensions
38− , multimarkdownExtensions
32+module Text.Pandoc.Options ( module Text.Pandoc.Extensions
3933 , ReaderOptions(..)
4034 , HTMLMathMethod (..)
4135 , CiteMethod (..)
@@ -50,212 +44,16 @@ module Text.Pandoc.Options ( Extension(..)
5044 , def
5145 , isEnabled
5246 ) where
53−import Data.Set (Set)
47+import Text.Pandoc.Extensions
5448import qualified Data.Set as Set
5549import Data.Default
5650import Text.Pandoc.Highlighting (Style, pygments)
5751import Text.Pandoc.MediaBag (MediaBag)
5852import Data.Data (Data)
53+import Data.Set (Set)
5954import Data.Typeable (Typeable)
6055import GHC.Generics (Generic)
6156
62−-- | Individually selectable syntax extensions.
63−data Extension =
64− Ext_footnotes -- ^ Pandoc/PHP/MMD style footnotes
65− | Ext_inline_notes -- ^ Pandoc-style inline notes
66− | Ext_pandoc_title_block -- ^ Pandoc title block
67− | Ext_yaml_metadata_block -- ^ YAML metadata block
68− | Ext_mmd_title_block -- ^ Multimarkdown metadata block
69− | Ext_table_captions -- ^ Pandoc-style table captions
70− | Ext_implicit_figures -- ^ A paragraph with just an image is a figure
71− | Ext_simple_tables -- ^ Pandoc-style simple tables
72− | Ext_multiline_tables -- ^ Pandoc-style multiline tables
73− | Ext_grid_tables -- ^ Grid tables (pandoc, reST)
74− | Ext_pipe_tables -- ^ Pipe tables (as in PHP markdown extra)
75− | Ext_citations -- ^ Pandoc/citeproc citations
76− | Ext_raw_tex -- ^ Allow raw TeX (other than math)
77− | Ext_raw_html -- ^ Allow raw HTML
78− | Ext_tex_math_dollars -- ^ TeX math between $..$ or $$..$$
79− | Ext_tex_math_single_backslash -- ^ TeX math btw \(..\) \[..\]
80− | Ext_tex_math_double_backslash -- ^ TeX math btw \\(..\\) \\[..\\]
81− | Ext_latex_macros -- ^ Parse LaTeX macro definitions (for math only)
82− | Ext_fenced_code_blocks -- ^ Parse fenced code blocks
83− | Ext_fenced_code_attributes -- ^ Allow attributes on fenced code blocks
84− | Ext_backtick_code_blocks -- ^ GitHub style ``` code blocks
85− | Ext_inline_code_attributes -- ^ Allow attributes on inline code
86− | Ext_markdown_in_html_blocks -- ^ Interpret as markdown inside HTML blocks
87− | Ext_native_divs -- ^ Use Div blocks for contents of <div> tags
88− | Ext_native_spans -- ^ Use Span inlines for contents of <span>
89− | Ext_bracketed_spans -- ^ Bracketed spans with attributes
90− | Ext_markdown_attribute -- ^ Interpret text inside HTML as markdown
91− -- iff container has attribute 'markdown'
92− | Ext_escaped_line_breaks -- ^ Treat a backslash at EOL as linebreak
93− | Ext_link_attributes -- ^ link and image attributes
94− | Ext_mmd_link_attributes -- ^ MMD style reference link attributes
95− | Ext_autolink_bare_uris -- ^ Make all absolute URIs into links
96− | Ext_fancy_lists -- ^ Enable fancy list numbers and delimiters
97− | Ext_lists_without_preceding_blankline -- ^ Allow lists without preceding blank
98− | Ext_startnum -- ^ Make start number of ordered list significant
99− | Ext_definition_lists -- ^ Definition lists as in pandoc, mmd, php
100− | Ext_compact_definition_lists -- ^ Definition lists without
101− -- space between items, and disallow laziness
102− | Ext_example_lists -- ^ Markdown-style numbered examples
103− | Ext_all_symbols_escapable -- ^ Make all non-alphanumerics escapable
104− | Ext_angle_brackets_escapable -- ^ Make < and > escapable
105− | Ext_intraword_underscores -- ^ Treat underscore inside word as literal
106− | Ext_blank_before_blockquote -- ^ Require blank line before a blockquote
107− | Ext_blank_before_header -- ^ Require blank line before a header
108− | Ext_strikeout -- ^ Strikeout using ~~this~~ syntax
109− | Ext_superscript -- ^ Superscript using ^this^ syntax
110− | Ext_subscript -- ^ Subscript using ~this~ syntax
111− | Ext_hard_line_breaks -- ^ All newlines become hard line breaks
112− | Ext_ignore_line_breaks -- ^ Newlines in paragraphs are ignored
113− | Ext_east_asian_line_breaks -- ^ Newlines in paragraphs are ignored between
114− -- East Asian wide characters
115− | Ext_literate_haskell -- ^ Enable literate Haskell conventions
116− | Ext_abbreviations -- ^ PHP markdown extra abbreviation definitions
117− | Ext_emoji -- ^ Support emoji like :smile:
118− | Ext_auto_identifiers -- ^ Automatic identifiers for headers
119− | Ext_ascii_identifiers -- ^ ascii-only identifiers for headers
120− | Ext_header_attributes -- ^ Explicit header attributes {#id .class k=v}
121− | Ext_mmd_header_identifiers -- ^ Multimarkdown style header identifiers [myid]
122− | Ext_implicit_header_references -- ^ Implicit reference links for headers
123− | Ext_line_blocks -- ^ RST style line blocks
124− | Ext_epub_html_exts -- ^ Recognise the EPUB extended version of HTML
125− | Ext_shortcut_reference_links -- ^ Shortcut reference links
126− deriving (Show, Read, Enum, Eq, Ord, Bounded, Data, Typeable, Generic)
127−
128−pandocExtensions :: Set Extension
129−pandocExtensions = Set.fromList
130− [ Ext_footnotes
131− , Ext_inline_notes
132− , Ext_pandoc_title_block
133− , Ext_yaml_metadata_block
134− , Ext_table_captions
135− , Ext_implicit_figures
136− , Ext_simple_tables
137− , Ext_multiline_tables
138− , Ext_grid_tables
139− , Ext_pipe_tables
140− , Ext_citations
141− , Ext_raw_tex
142− , Ext_raw_html
143− , Ext_tex_math_dollars
144− , Ext_latex_macros
145− , Ext_fenced_code_blocks
146− , Ext_fenced_code_attributes
147− , Ext_backtick_code_blocks
148− , Ext_inline_code_attributes
149− , Ext_markdown_in_html_blocks
150− , Ext_native_divs
151− , Ext_native_spans
152− , Ext_bracketed_spans
153− , Ext_escaped_line_breaks
154− , Ext_fancy_lists
155− , Ext_startnum
156− , Ext_definition_lists
157− , Ext_example_lists
158− , Ext_all_symbols_escapable
159− , Ext_intraword_underscores
160− , Ext_blank_before_blockquote
161− , Ext_blank_before_header
162− , Ext_strikeout
163− , Ext_superscript
164− , Ext_subscript
165− , Ext_auto_identifiers
166− , Ext_header_attributes
167− , Ext_link_attributes
168− , Ext_implicit_header_references
169− , Ext_line_blocks
170− , Ext_shortcut_reference_links
171− ]
172−
173−plainExtensions :: Set Extension
174−plainExtensions = Set.fromList
175− [ Ext_table_captions
176− , Ext_implicit_figures
177− , Ext_simple_tables
178− , Ext_multiline_tables
179− , Ext_grid_tables
180− , Ext_latex_macros
181− , Ext_fancy_lists
182− , Ext_startnum
183− , Ext_definition_lists
184− , Ext_example_lists
185− , Ext_intraword_underscores
186− , Ext_blank_before_blockquote
187− , Ext_blank_before_header
188− , Ext_strikeout
189− ]
190−
191−phpMarkdownExtraExtensions :: Set Extension
192−phpMarkdownExtraExtensions = Set.fromList
193− [ Ext_footnotes
194− , Ext_pipe_tables
195− , Ext_raw_html
196− , Ext_markdown_attribute
197− , Ext_fenced_code_blocks
198− , Ext_definition_lists
199− , Ext_intraword_underscores
200− , Ext_header_attributes
201− , Ext_link_attributes
202− , Ext_abbreviations
203− , Ext_shortcut_reference_links
204− ]
205−
206−githubMarkdownExtensions :: Set Extension
207−githubMarkdownExtensions = Set.fromList
208− [ Ext_angle_brackets_escapable
209− , Ext_pipe_tables
210− , Ext_raw_html
211− , Ext_fenced_code_blocks
212− , Ext_auto_identifiers
213− , Ext_ascii_identifiers
214− , Ext_backtick_code_blocks
215− , Ext_autolink_bare_uris
216− , Ext_intraword_underscores
217− , Ext_strikeout
218− , Ext_hard_line_breaks
219− , Ext_emoji
220− , Ext_lists_without_preceding_blankline
221− , Ext_shortcut_reference_links
222− ]
223−
224−multimarkdownExtensions :: Set Extension
225−multimarkdownExtensions = Set.fromList
226− [ Ext_pipe_tables
227− , Ext_raw_html
228− , Ext_markdown_attribute
229− , Ext_mmd_link_attributes
230− -- , Ext_raw_tex
231− -- Note: MMD's raw TeX syntax requires raw TeX to be
232− -- enclosed in HTML comment
233− , Ext_tex_math_double_backslash
234− , Ext_intraword_underscores
235− , Ext_mmd_title_block
236− , Ext_footnotes
237− , Ext_definition_lists
238− , Ext_all_symbols_escapable
239− , Ext_implicit_header_references
240− , Ext_auto_identifiers
241− , Ext_mmd_header_identifiers
242− , Ext_implicit_figures
243− -- Note: MMD's syntax for superscripts and subscripts
244− -- is a bit more permissive than pandoc's, allowing
245− -- e^2 and a~1 instead of e^2^ and a~1~, so even with
246− -- these options we don't have full support for MMD
247− -- superscripts and subscripts, but there's no reason
248− -- not to include these:
249− , Ext_superscript
250− , Ext_subscript
251− ]
252−
253−strictExtensions :: Set Extension
254−strictExtensions = Set.fromList
255− [ Ext_raw_html
256− , Ext_shortcut_reference_links
257− ]
258−
25957data ReaderOptions = ReaderOptions{
26058 readerExtensions :: Set Extension -- ^ Syntax extensions
26159 , readerSmart :: Bool -- ^ Smart punctuation