git.iko.soy/typeable/pandoc
on 041ab7b help sign in
.github/workflows/ci.yml+1−3
since splitsnapshots
unifiedsplit
@@ -40,11 +40,9 @@ jobs:
40
40
41 runs-on: ubuntu-latest
41 runs-on: ubuntu-latest
42 strategy:
42 strategy:
43− fail-fast: true
43+ fail-fast: false
44 matrix:
44 matrix:
45 versions:
45 versions:
46− - ghc: '8.0.2'
47− cabal: '2.4'
48 - ghc: '8.2.2'
46 - ghc: '8.2.2'
49 cabal: '2.4'
47 cabal: '2.4'
50 - ghc: '8.4.4'
48 - ghc: '8.4.4'
CONTRIBUTING.md+1−1
@@ -144,7 +144,7 @@ Please follow these guidelines:
1449. It is better not to introduce new dependencies. Dependencies on
1449. It is better not to introduce new dependencies. Dependencies on
145 external C libraries should especially be avoided.
145 external C libraries should especially be avoided.
146
146
147−10. We aim for compatibility with ghc versions from 8.0 to the
147+10. We aim for compatibility with ghc versions from 8.2 to the
148 latest release. All pull requests and commits are tested
148 latest release. All pull requests and commits are tested
149 automatically on CircleCI.
149 automatically on CircleCI.
150
150
MANUAL.txt+33
@@ -226,6 +226,7 @@ header when requesting a document from a URL:
226
226
227 ::: {#input-formats}
227 ::: {#input-formats}
228 - `commonmark` ([CommonMark] Markdown)
228 - `commonmark` ([CommonMark] Markdown)
229+ - `commonmark_x` ([CommonMark] Markdown with extensions)
229 - `creole` ([Creole 1.0])
230 - `creole` ([Creole 1.0])
230 - `csv` ([CSV] table)
231 - `csv` ([CSV] table)
231 - `docbook` ([DocBook])
232 - `docbook` ([DocBook])
@@ -277,6 +278,7 @@ header when requesting a document from a URL:
277 - `asciidoc` ([AsciiDoc]) or `asciidoctor` ([AsciiDoctor])
278 - `asciidoc` ([AsciiDoc]) or `asciidoctor` ([AsciiDoctor])
278 - `beamer` ([LaTeX beamer][`beamer`] slide show)
279 - `beamer` ([LaTeX beamer][`beamer`] slide show)
279 - `commonmark` ([CommonMark] Markdown)
280 - `commonmark` ([CommonMark] Markdown)
281+ - `commonmark_x` ([CommonMark] Markdown with extensions)
280 - `context` ([ConTeXt])
282 - `context` ([ConTeXt])
281 - `docbook` or `docbook4` ([DocBook] 4)
283 - `docbook` or `docbook4` ([DocBook] 4)
282 - `docbook5` (DocBook 5)
284 - `docbook5` (DocBook 5)
@@ -4935,6 +4937,37 @@ in pandoc, but may be enabled by adding `+EXTENSION` to the format
4935name, where `EXTENSION` is the name of the extension. Thus, for
4937name, where `EXTENSION` is the name of the extension. Thus, for
4936example, `markdown+hard_line_breaks` is Markdown with hard line breaks.
4938example, `markdown+hard_line_breaks` is Markdown with hard line breaks.
4937
4939
4940+#### Extension: `attributes` ####
4941+
4942+Allows attributes to be attached to any inline or block-level
4943+element. The syntax for the attributes is the same as that
4944+used in [`header_attributes`][Extension: `header_attributes`].
4945+
4946+- Attributes that occur immediately after an inline
4947+ element affect that element. If they follow a space, then they
4948+ belong to the space. (Hence, this option subsumes
4949+ `inline_code_attributes` and `link_attributes`.)
4950+- Attributes that occur immediately before a block
4951+ element, on a line by themselves, affect that
4952+ element.
4953+- Consecutive attribute specifiers may be used,
4954+ either for blocks or for inlines. Their attributes
4955+ will be combined.
4956+- Attributes that occur at the end of the text of
4957+ a Setext or ATX heading (separated by whitespace
4958+ from the text) affect the heading element. (Hence, this
4959+ option subsumes `header_attributes`.)
4960+- Attributes that occur after the opening fence
4961+ in a fenced code block affect the code block element. (Hence,
4962+ this option subsumes `fenced_code_attributes`.)
4963+- Attributes that occur at the end of a reference
4964+ link definition affect links that refer to that
4965+ definition.
4966+
4967+Note that pandoc's AST does not currently allow attributes
4968+to be attached to arbitrary elements. Hence a Span or Div
4969+container will be added if needed.
4970+
4938#### Extension: `old_dashes` ####
4971#### Extension: `old_dashes` ####
4939
4972
4940Selects the pandoc <= 1.8.2.1 behavior for parsing smart dashes:
4973Selects the pandoc <= 1.8.2.1 behavior for parsing smart dashes:
cabal.project+18
@@ -17,3 +17,21 @@ source-repository-package
17 type: git
17 type: git
18 location: https://github.com/jgm/pandoc-types
18 location: https://github.com/jgm/pandoc-types
19 tag: dd50a6eaeaf63773bbf04d6ef34b86d6f92b7825
19 tag: dd50a6eaeaf63773bbf04d6ef34b86d6f92b7825
20+
21+source-repository-package
22+ type: git
23+ location: https://github.com/jgm/commonmark-hs
24+ tag: dab1978e19cbafd4b7540cf545346969091929d5
25+ subdir: commonmark
26+
27+source-repository-package
28+ type: git
29+ location: https://github.com/jgm/commonmark-hs
30+ tag: dab1978e19cbafd4b7540cf545346969091929d5
31+ subdir: commonmark-extensions
32+
33+source-repository-package
34+ type: git
35+ location: https://github.com/jgm/commonmark-hs
36+ tag: dab1978e19cbafd4b7540cf545346969091929d5
37+ subdir: commonmark-pandoc
pandoc.cabal+10−7
@@ -11,7 +11,7 @@ bug-reports: https://github.com/jgm/pandoc/issues
11stability: alpha
11stability: alpha
12homepage: https://pandoc.org
12homepage: https://pandoc.org
13category: Text
13category: Text
14−tested-with: GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.5
14+tested-with: GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.5, GHC == 8.8.1, GHC == 8.10.1
15synopsis: Conversion between markup formats
15synopsis: Conversion between markup formats
16description: Pandoc is a Haskell library for converting from one markup
16description: Pandoc is a Haskell library for converting from one markup
17 format to another, and a command-line tool that uses
17 format to another, and a command-line tool that uses
@@ -377,7 +377,7 @@ flag trypandoc
377 Default: False
377 Default: False
378
378
379library
379library
380− build-depends: base >= 4.9 && < 5,
380+ build-depends: base >= 4.10 && < 5,
381 syb >= 0.1 && < 0.8,
381 syb >= 0.1 && < 0.8,
382 containers >= 0.4.2.1 && < 0.7,
382 containers >= 0.4.2.1 && < 0.7,
383 unordered-containers >= 0.2 && < 0.3,
383 unordered-containers >= 0.2 && < 0.3,
@@ -421,8 +421,11 @@ library
421 deepseq >= 1.3 && < 1.5,
421 deepseq >= 1.3 && < 1.5,
422 JuicyPixels >= 3.1.6.1 && < 3.4,
422 JuicyPixels >= 3.1.6.1 && < 3.4,
423 Glob >= 0.7 && < 0.11,
423 Glob >= 0.7 && < 0.11,
424− cmark-gfm >= 0.2 && < 0.3,
425 doctemplates >= 0.8.2 && < 0.9,
424 doctemplates >= 0.8.2 && < 0.9,
425+ commonmark-pandoc >= 0.1,
426+ commonmark >= 0.1,
427+ commonmark-extensions >= 0.1,
428+ cmark-gfm >= 0.2.0,
426 network-uri >= 2.6 && < 2.7,
429 network-uri >= 2.6 && < 2.7,
427 network >= 2.6,
430 network >= 2.6,
428 connection >= 0.3.1,
431 connection >= 0.3.1,
@@ -647,7 +650,7 @@ library
647 buildable: True
650 buildable: True
648
651
649executable pandoc
652executable pandoc
650− build-depends: pandoc, base >= 4.8 && < 5
653+ build-depends: pandoc, base >= 4.10 && < 5
651 if impl(ghc < 8.4)
654 if impl(ghc < 8.4)
652 hs-source-dirs: prelude
655 hs-source-dirs: prelude
653 other-modules: Prelude
656 other-modules: Prelude
@@ -704,7 +707,7 @@ benchmark weigh-pandoc
704 main-is: weigh-pandoc.hs
707 main-is: weigh-pandoc.hs
705 hs-source-dirs: benchmark
708 hs-source-dirs: benchmark
706 build-depends: pandoc,
709 build-depends: pandoc,
707− base >= 4.8 && < 5,
710+ base >= 4.10 && < 5,
708 text,
711 text,
709 weigh >= 0.0 && < 0.1,
712 weigh >= 0.0 && < 0.1,
710 mtl >= 2.2 && < 2.3
713 mtl >= 2.2 && < 2.3
@@ -731,7 +734,7 @@ test-suite test-pandoc
731 type: exitcode-stdio-1.0
734 type: exitcode-stdio-1.0
732 main-is: test-pandoc.hs
735 main-is: test-pandoc.hs
733 hs-source-dirs: test
736 hs-source-dirs: test
734− build-depends: base >= 4.8 && < 5,
737+ build-depends: base >= 4.10 && < 5,
735 pandoc,
738 pandoc,
736 pandoc-types >= 1.21 && < 1.22,
739 pandoc-types >= 1.21 && < 1.22,
737 mtl >= 2.2 && < 2.3,
740 mtl >= 2.2 && < 2.3,
@@ -839,7 +842,7 @@ benchmark benchmark-pandoc
839 hs-source-dirs: benchmark
842 hs-source-dirs: benchmark
840 build-depends: pandoc,
843 build-depends: pandoc,
841 time, bytestring, containers,
844 time, bytestring, containers,
842− base >= 4.8 && < 5,
845+ base >= 4.10 && < 5,
843 text >= 1.1.1.0 && < 1.3,
846 text >= 1.1.1.0 && < 1.3,
844 mtl >= 2.2 && < 2.3,
847 mtl >= 2.2 && < 2.3,
845 criterion >= 1.0 && < 1.6
848 criterion >= 1.0 && < 1.6
src/Text/Pandoc/Extensions.hs+54−12
@@ -150,6 +150,7 @@ data Extension =
150 | Ext_tex_math_single_backslash -- ^ TeX math btw \(..\) \[..\]
150 | Ext_tex_math_single_backslash -- ^ TeX math btw \(..\) \[..\]
151 | Ext_yaml_metadata_block -- ^ YAML metadata block
151 | Ext_yaml_metadata_block -- ^ YAML metadata block
152 | Ext_gutenberg -- ^ Use Project Gutenberg conventions for plain
152 | Ext_gutenberg -- ^ Use Project Gutenberg conventions for plain
153+ | Ext_attributes -- ^ Generic attribute syntax
153 deriving (Show, Read, Enum, Eq, Ord, Bounded, Data, Typeable, Generic)
154 deriving (Show, Read, Enum, Eq, Ord, Bounded, Data, Typeable, Generic)
154
155
155-- | Extensions to be used with pandoc-flavored markdown.
156-- | Extensions to be used with pandoc-flavored markdown.
@@ -242,21 +243,14 @@ phpMarkdownExtraExtensions = extensionsFromList
242-- | Extensions to be used with github-flavored markdown.
243-- | Extensions to be used with github-flavored markdown.
243githubMarkdownExtensions :: Extensions
244githubMarkdownExtensions :: Extensions
244githubMarkdownExtensions = extensionsFromList
245githubMarkdownExtensions = extensionsFromList
245− [ Ext_all_symbols_escapable
246− , Ext_pipe_tables
246+ [ Ext_pipe_tables
247 , Ext_raw_html
247 , Ext_raw_html
248− , Ext_fenced_code_blocks
249 , Ext_auto_identifiers
248 , Ext_auto_identifiers
250 , Ext_gfm_auto_identifiers
249 , Ext_gfm_auto_identifiers
251− , Ext_backtick_code_blocks
252 , Ext_autolink_bare_uris
250 , Ext_autolink_bare_uris
253− , Ext_space_in_atx_header
254− , Ext_intraword_underscores
255 , Ext_strikeout
251 , Ext_strikeout
256 , Ext_task_lists
252 , Ext_task_lists
257 , Ext_emoji
253 , Ext_emoji
258− , Ext_lists_without_preceding_blankline
259− , Ext_shortcut_reference_links
260 ]
254 ]
261
255
262-- | Extensions to be used with multimarkdown.
256-- | Extensions to be used with multimarkdown.
@@ -308,7 +302,16 @@ getDefaultExtensions :: T.Text -> Extensions
308getDefaultExtensions "markdown_strict" = strictExtensions
302getDefaultExtensions "markdown_strict" = strictExtensions
309getDefaultExtensions "markdown_phpextra" = phpMarkdownExtraExtensions
303getDefaultExtensions "markdown_phpextra" = phpMarkdownExtraExtensions
310getDefaultExtensions "markdown_mmd" = multimarkdownExtensions
304getDefaultExtensions "markdown_mmd" = multimarkdownExtensions
311−getDefaultExtensions "markdown_github" = githubMarkdownExtensions
305+getDefaultExtensions "markdown_github" = githubMarkdownExtensions <>
306+ extensionsFromList
307+ [ Ext_all_symbols_escapable
308+ , Ext_backtick_code_blocks
309+ , Ext_fenced_code_blocks
310+ , Ext_space_in_atx_header
311+ , Ext_intraword_underscores
312+ , Ext_lists_without_preceding_blankline
313+ , Ext_shortcut_reference_links
314+ ]
312getDefaultExtensions "markdown" = pandocExtensions
315getDefaultExtensions "markdown" = pandocExtensions
313getDefaultExtensions "ipynb" =
316getDefaultExtensions "ipynb" =
314 extensionsFromList
317 extensionsFromList
@@ -335,6 +338,29 @@ getDefaultExtensions "plain" = plainExtensions
335getDefaultExtensions "gfm" = githubMarkdownExtensions
338getDefaultExtensions "gfm" = githubMarkdownExtensions
336getDefaultExtensions "commonmark" = extensionsFromList
339getDefaultExtensions "commonmark" = extensionsFromList
337 [Ext_raw_html]
340 [Ext_raw_html]
341+getDefaultExtensions "commonmark_x" = extensionsFromList
342+ [ Ext_pipe_tables
343+ , Ext_raw_html
344+ , Ext_auto_identifiers
345+ , Ext_strikeout
346+ , Ext_task_lists
347+ , Ext_emoji
348+ , Ext_pipe_tables
349+ , Ext_raw_html
350+ , Ext_raw_tex -- only supported in writer (for math)
351+ , Ext_smart
352+ , Ext_tex_math_dollars
353+ , Ext_superscript
354+ , Ext_subscript
355+ , Ext_definition_lists
356+ , Ext_footnotes
357+ , Ext_fancy_lists
358+ , Ext_fenced_divs
359+ , Ext_bracketed_spans
360+ , Ext_raw_attribute
361+ , Ext_implicit_header_references
362+ , Ext_attributes
363+ ]
338getDefaultExtensions "org" = extensionsFromList
364getDefaultExtensions "org" = extensionsFromList
339 [Ext_citations,
365 [Ext_citations,
340 Ext_auto_identifiers]
366 Ext_auto_identifiers]
@@ -430,16 +456,32 @@ getAllExtensions f = universalExtensions <> getAll f
430 [ Ext_amuse ]
456 [ Ext_amuse ]
431 getAll "asciidoc" = autoIdExtensions
457 getAll "asciidoc" = autoIdExtensions
432 getAll "plain" = allMarkdownExtensions
458 getAll "plain" = allMarkdownExtensions
433− getAll "gfm" = githubMarkdownExtensions <>
459+ getAll "gfm" = getAll "commonmark"
460+ getAll "commonmark" =
434 autoIdExtensions <>
461 autoIdExtensions <>
435 extensionsFromList
462 extensionsFromList
463+ [ Ext_pipe_tables
464+ , Ext_autolink_bare_uris
465+ , Ext_strikeout
466+ , Ext_task_lists
467+ , Ext_emoji
436− [ Ext_raw_html
468+ , Ext_raw_html
437 , Ext_raw_tex -- only supported in writer (for math)
469 , Ext_raw_tex -- only supported in writer (for math)
438 , Ext_implicit_figures
470 , Ext_implicit_figures
439 , Ext_hard_line_breaks
471 , Ext_hard_line_breaks
440 , Ext_smart
472 , Ext_smart
473+ , Ext_tex_math_dollars
474+ , Ext_superscript
475+ , Ext_subscript
476+ , Ext_definition_lists
477+ , Ext_footnotes
478+ , Ext_fancy_lists
479+ , Ext_fenced_divs
480+ , Ext_bracketed_spans
481+ , Ext_raw_attribute
482+ , Ext_implicit_header_references
483+ , Ext_attributes
441 ]
484 ]
442− getAll "commonmark" = getAll "gfm"
443 getAll "org" = autoIdExtensions <>
485 getAll "org" = autoIdExtensions <>
444 extensionsFromList
486 extensionsFromList
445 [ Ext_citations
487 [ Ext_citations
src/Text/Pandoc/Readers.hs+1
@@ -111,6 +111,7 @@ readers = [ ("native" , TextReader readNative)
111 ,("markdown_github" , TextReader readMarkdown)
111 ,("markdown_github" , TextReader readMarkdown)
112 ,("markdown_mmd", TextReader readMarkdown)
112 ,("markdown_mmd", TextReader readMarkdown)
113 ,("commonmark" , TextReader readCommonMark)
113 ,("commonmark" , TextReader readCommonMark)
114+ ,("commonmark_x" , TextReader readCommonMark)
114 ,("creole" , TextReader readCreole)
115 ,("creole" , TextReader readCreole)
115 ,("dokuwiki" , TextReader readDokuWiki)
116 ,("dokuwiki" , TextReader readDokuWiki)
116 ,("gfm" , TextReader readCommonMark)
117 ,("gfm" , TextReader readCommonMark)
src/Text/Pandoc/Readers/CommonMark.hs+40−198
@@ -1,4 +1,5 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE ScopedTypeVariables #-}
2{-# LANGUAGE ViewPatterns #-}
3{-# LANGUAGE ViewPatterns #-}
3{- |
4{- |
4 Module : Text.Pandoc.Readers.CommonMark
5 Module : Text.Pandoc.Readers.CommonMark
@@ -16,209 +17,50 @@ CommonMark is a strongly specified variant of Markdown: http://commonmark.org.
16module Text.Pandoc.Readers.CommonMark (readCommonMark)
17module Text.Pandoc.Readers.CommonMark (readCommonMark)
17where
18where
18
19
19−import CMarkGFM
20+import Commonmark
20−import Control.Monad.State
21+import Commonmark.Extensions
21−import qualified Data.Set as Set
22+import Commonmark.Pandoc
22import Data.Text (Text)
23import Data.Text (Text)
23−import qualified Data.Text as T
24import Text.Pandoc.Class.PandocMonad (PandocMonad)
24import Text.Pandoc.Class.PandocMonad (PandocMonad)
25import Text.Pandoc.Definition
25import Text.Pandoc.Definition
26−import Text.Pandoc.Emoji (emojiToInline)
26+import Text.Pandoc.Builder as B
27import Text.Pandoc.Options
27import Text.Pandoc.Options
28−import Text.Pandoc.Shared (uniqueIdent, taskListItemFromAscii)
28+import Text.Pandoc.Error
29−import Text.Pandoc.Walk (walkM)
29+import Control.Monad.Except
30+import Data.Functor.Identity (runIdentity)
30
31
31-- | Parse a CommonMark formatted string into a 'Pandoc' structure.
32-- | Parse a CommonMark formatted string into a 'Pandoc' structure.
32readCommonMark :: PandocMonad m => ReaderOptions -> Text -> m Pandoc
33readCommonMark :: PandocMonad m => ReaderOptions -> Text -> m Pandoc
33−readCommonMark opts s = return $
34+readCommonMark opts s = do
34− (if isEnabled Ext_auto_identifiers opts
35+ let res = runIdentity $
35− then addHeaderIdentifiers opts
36+ commonmarkWith (foldr (<>) defaultSyntaxSpec exts) "input" s
36− else id) $
37+ case res of
37− nodeToPandoc opts $ commonmarkToNode opts' exts s
38+ Left err -> throwError $ PandocParsecError s err
39+ Right (Cm bls :: Cm () Blocks) -> return $ B.doc bls
40+ where
41+ exts = [ hardLineBreaksSpec | isEnabled Ext_hard_line_breaks opts ] ++
38− where opts' = [ optSmart | isEnabled Ext_smart opts ]
42+ [ smartPunctuationSpec | isEnabled Ext_smart opts ] ++
39− exts = [ extStrikethrough | isEnabled Ext_strikeout opts ] ++
43+ [ strikethroughSpec | isEnabled Ext_strikeout opts ] ++
44+ [ superscriptSpec | isEnabled Ext_superscript opts ] ++
45+ [ subscriptSpec | isEnabled Ext_subscript opts ] ++
46+ [ mathSpec | isEnabled Ext_tex_math_dollars opts ] ++
47+ [ fancyListSpec | isEnabled Ext_fancy_lists opts ] ++
48+ [ fencedDivSpec | isEnabled Ext_fenced_divs opts ] ++
49+ [ bracketedSpanSpec | isEnabled Ext_bracketed_spans opts ] ++
50+ [ rawAttributeSpec | isEnabled Ext_raw_attribute opts ] ++
51+ [ attributesSpec | isEnabled Ext_attributes opts ] ++
40− [ extTable | isEnabled Ext_pipe_tables opts ] ++
52+ [ pipeTableSpec | isEnabled Ext_pipe_tables opts ] ++
41− [ extAutolink | isEnabled Ext_autolink_bare_uris opts ]
53+ [ autolinkSpec | isEnabled Ext_autolink_bare_uris opts ] ++
54+ [ emojiSpec | isEnabled Ext_emoji opts ] ++
55+ [ autoIdentifiersSpec
56+ | isEnabled Ext_gfm_auto_identifiers opts
57+ , not (isEnabled Ext_ascii_identifiers opts) ] ++
58+ [ autoIdentifiersAsciiSpec
59+ | isEnabled Ext_gfm_auto_identifiers opts
60+ , isEnabled Ext_ascii_identifiers opts ] ++
61+ [ implicitHeadingReferencesSpec
62+ | isEnabled Ext_implicit_header_references opts ] ++
63+ [ footnoteSpec | isEnabled Ext_footnotes opts ] ++
64+ [ definitionListSpec | isEnabled Ext_definition_lists opts ] ++
65+ [ taskListSpec | isEnabled Ext_task_lists opts ]
42
66
43−convertEmojis :: Text -> [Inline]
44−convertEmojis s@(T.uncons -> Just (':',xs)) =
45− case T.break (==':') xs of
46− (ys, T.uncons -> Just (':',zs)) ->
47− case emojiToInline ys of
48− Just em -> em : convertEmojis zs
49− Nothing -> Str (":" <> ys) : convertEmojis (":" <> zs)
50− _ -> [Str s]
51−convertEmojis s =
52− case T.break (==':') s of
53− ("","") -> []
54− (_,"") -> [Str s]
55− (xs,ys) -> Str xs : convertEmojis ys
56−
57−addHeaderIdentifiers :: ReaderOptions -> Pandoc -> Pandoc
58−addHeaderIdentifiers opts doc = evalState (walkM (addHeaderId opts) doc) mempty
59−
60−addHeaderId :: ReaderOptions -> Block -> State (Set.Set Text) Block
61−addHeaderId opts (Header lev (_,classes,kvs) ils) = do
62− ids <- get
63− let ident = uniqueIdent (readerExtensions opts) ils ids
64− modify (Set.insert ident)
65− return $ Header lev (ident,classes,kvs) ils
66−addHeaderId _ x = return x
67−
68−nodeToPandoc :: ReaderOptions -> Node -> Pandoc
69−nodeToPandoc opts (Node _ DOCUMENT nodes) =
70− Pandoc nullMeta $ foldr (addBlock opts) [] nodes
71−nodeToPandoc opts n = -- shouldn't happen
72− Pandoc nullMeta $ foldr (addBlock opts) [] [n]
73−
74−addBlocks :: ReaderOptions -> [Node] -> [Block]
75−addBlocks opts = foldr (addBlock opts) []
76−
77−addBlock :: ReaderOptions -> Node -> [Block] -> [Block]
78−addBlock opts (Node _ PARAGRAPH nodes) =
79− case addInlines opts nodes of
80− [Image attr alt (src,tit)]
81− | isEnabled Ext_implicit_figures opts
82− -- the "fig:" prefix indicates an implicit figure
83− -> (Para [Image attr alt (src, "fig:" <> tit)] :)
84− ils -> (Para ils :)
85−addBlock _ (Node _ THEMATIC_BREAK _) =
86− (HorizontalRule :)
87−addBlock opts (Node _ BLOCK_QUOTE nodes) =
88− (BlockQuote (addBlocks opts nodes) :)
89−addBlock opts (Node _ (HTML_BLOCK t) _)
90− | isEnabled Ext_raw_html opts = (RawBlock (Format "html") t :)
91− | otherwise = id
92−-- Note: the cmark parser will never generate CUSTOM_BLOCK,
93−-- so we don't need to handle it:
94−addBlock _ (Node _ (CUSTOM_BLOCK _onEnter _onExit) _nodes) =
95− id
96−addBlock _ (Node _ (CODE_BLOCK info t) _) =
97− (CodeBlock ("", take 1 (T.words info), []) t :)
98−addBlock opts (Node _ (HEADING lev) nodes) =
99− (Header lev ("",[],[]) (addInlines opts nodes) :)
100−addBlock opts (Node _ (LIST listAttrs) nodes) =
101− (constructor (map listItem nodes) :)
102− where constructor = case listType listAttrs of
103− BULLET_LIST -> BulletList
104− ORDERED_LIST -> OrderedList
105− (start, DefaultStyle, delim)
106− start = listStart listAttrs
107− listItem = taskListItemFromAscii exts . setTightness
108− . addBlocks opts . children
109− setTightness = if listTight listAttrs
110− then map paraToPlain
111− else id
112− paraToPlain (Para xs) = Plain xs
113− paraToPlain x = x
114− delim = case listDelim listAttrs of
115− PERIOD_DELIM -> Period
116− PAREN_DELIM -> OneParen
117− exts = readerExtensions opts
118−addBlock opts (Node _ (TABLE alignments) nodes) =
119− (Table
120− nullAttr
121− (Caption Nothing [])
122− (zip aligns widths)
123− (TableHead nullAttr headers)
124− [TableBody nullAttr 0 [] rows]
125− (TableFoot nullAttr []) :)
126− where aligns = map fromTableCellAlignment alignments
127− fromTableCellAlignment NoAlignment = AlignDefault
128− fromTableCellAlignment LeftAligned = AlignLeft
129− fromTableCellAlignment RightAligned = AlignRight
130− fromTableCellAlignment CenterAligned = AlignCenter
131− widths = replicate numcols ColWidthDefault
132− numcols = if null rows'
133− then 0
134− else maximum $ map rowLength rows'
135− rows' = map toRow $ filter isRow nodes
136− (headers, rows) = case rows' of
137− (h:rs) -> ([h], rs)
138− [] -> ([], [])
139− isRow (Node _ TABLE_ROW _) = True
140− isRow _ = False
141− isCell (Node _ TABLE_CELL _) = True
142− isCell _ = False
143− toRow (Node _ TABLE_ROW ns) = Row nullAttr $ map toCell $ filter isCell ns
144− toRow (Node _ t _) = error $ "toRow encountered non-row " ++ show t
145− toCell (Node _ TABLE_CELL []) = fromSimpleCell []
146− toCell (Node _ TABLE_CELL (n:ns))
147− | isBlockNode n = fromSimpleCell $ addBlocks opts (n:ns)
148− | otherwise = fromSimpleCell [Plain (addInlines opts (n:ns))]
149− toCell (Node _ t _) = error $ "toCell encountered non-cell " ++ show t
150− fromSimpleCell = Cell nullAttr AlignDefault 1 1
151− rowLength (Row _ body) = length body -- all cells are 1×1
152−addBlock _ (Node _ TABLE_ROW _) = id -- handled in TABLE
153−addBlock _ (Node _ TABLE_CELL _) = id -- handled in TABLE
154−addBlock _ _ = id
155−
156−isBlockNode :: Node -> Bool
157−isBlockNode (Node _ nodetype _) =
158− case nodetype of
159− DOCUMENT -> True
160− THEMATIC_BREAK -> True
161− PARAGRAPH -> True
162− BLOCK_QUOTE -> True
163− HTML_BLOCK _ -> True
164− CUSTOM_BLOCK _ _ -> True
165− CODE_BLOCK _ _ -> True
166− HEADING _ -> True
167− LIST _ -> True
168− ITEM -> True
169− TEXT _ -> False
170− SOFTBREAK -> False
171− LINEBREAK -> False
172− HTML_INLINE _ -> False
173− CUSTOM_INLINE _ _ -> False
174− CODE _ -> False
175− EMPH -> False
176− STRONG -> False
177− LINK _ _ -> False
178− IMAGE _ _ -> False
179− STRIKETHROUGH -> False
180− TABLE _ -> False
181− TABLE_ROW -> False
182− TABLE_CELL -> False
183−
184−children :: Node -> [Node]
185−children (Node _ _ ns) = ns
186−
187−addInlines :: ReaderOptions -> [Node] -> [Inline]
188−addInlines opts = foldr (addInline opts) []
189−
190−addInline :: ReaderOptions -> Node -> [Inline] -> [Inline]
191−addInline opts (Node _ (TEXT t) _) = (concatMap toinl clumps ++)
192− where clumps = T.groupBy samekind t
193− samekind ' ' ' ' = True
194− samekind ' ' _ = False
195− samekind _ ' ' = False
196− samekind _ _ = True
197− toinl (T.uncons -> Just (' ', _)) = [Space]
198− toinl xs = if isEnabled Ext_emoji opts
199− then convertEmojis xs
200− else [Str xs]
201−addInline _ (Node _ LINEBREAK _) = (LineBreak :)
202−addInline opts (Node _ SOFTBREAK _)
203− | isEnabled Ext_hard_line_breaks opts = (LineBreak :)
204− | otherwise = (SoftBreak :)
205−addInline opts (Node _ (HTML_INLINE t) _)
206− | isEnabled Ext_raw_html opts = (RawInline (Format "html") t :)
207− | otherwise = id
208−-- Note: the cmark parser will never generate CUSTOM_BLOCK,
209−-- so we don't need to handle it:
210−addInline _ (Node _ (CUSTOM_INLINE _onEnter _onExit) _nodes) =
211− id
212−addInline _ (Node _ (CODE t) _) =
213− (Code ("",[],[]) t :)
214−addInline opts (Node _ EMPH nodes) =
215− (Emph (addInlines opts nodes) :)
216−addInline opts (Node _ STRONG nodes) =
217− (Strong (addInlines opts nodes) :)
218−addInline opts (Node _ STRIKETHROUGH nodes) =
219− (Strikeout (addInlines opts nodes) :)
220−addInline opts (Node _ (LINK url title) nodes) =
221− (Link nullAttr (addInlines opts nodes) (url, title) :)
222−addInline opts (Node _ (IMAGE url title) nodes) =
223− (Image nullAttr (addInlines opts nodes) (url, title) :)
224−addInline _ _ = id
src/Text/Pandoc/Templates.hs+1
@@ -97,6 +97,7 @@ getDefaultTemplate writer = do
97 "markdown_mmd" -> getDefaultTemplate "markdown"
97 "markdown_mmd" -> getDefaultTemplate "markdown"
98 "markdown_phpextra" -> getDefaultTemplate "markdown"
98 "markdown_phpextra" -> getDefaultTemplate "markdown"
99 "gfm" -> getDefaultTemplate "commonmark"
99 "gfm" -> getDefaultTemplate "commonmark"
100+ "commonmark_x" -> getDefaultTemplate "commonmark"
100 _ -> do
101 _ -> do
101 let fname = "templates" </> "default" <.> T.unpack format
102 let fname = "templates" </> "default" <.> T.unpack format
102 UTF8.toText <$> readDataFile fname
103 UTF8.toText <$> readDataFile fname
src/Text/Pandoc/Writers.hs+1
@@ -178,6 +178,7 @@ writers = [
178 ,("asciidoctor" , TextWriter writeAsciiDoctor)
178 ,("asciidoctor" , TextWriter writeAsciiDoctor)
179 ,("haddock" , TextWriter writeHaddock)
179 ,("haddock" , TextWriter writeHaddock)
180 ,("commonmark" , TextWriter writeCommonMark)
180 ,("commonmark" , TextWriter writeCommonMark)
181+ ,("commonmark_x" , TextWriter writeCommonMark)
181 ,("gfm" , TextWriter writeCommonMark)
182 ,("gfm" , TextWriter writeCommonMark)
182 ,("tei" , TextWriter writeTEI)
183 ,("tei" , TextWriter writeTEI)
183 ,("muse" , TextWriter writeMuse)
184 ,("muse" , TextWriter writeMuse)
stack.yaml+6
@@ -30,6 +30,12 @@ extra-deps:
30- HsYAML-0.2.1.0
30- HsYAML-0.2.1.0
31- HsYAML-aeson-0.2.0.0
31- HsYAML-aeson-0.2.0.0
32- doctemplates-0.8.2
32- doctemplates-0.8.2
33+- git: https://github.com/jgm/commonmark-hs
34+ commit: dab1978e19cbafd4b7540cf545346969091929d5
35+ subdirs:
36+ - commonmark
37+ - commonmark-extensions
38+ - commonmark-pandoc
33ghc-options:
39ghc-options:
34 "$locals": -fhide-source-paths -Wno-missing-home-modules
40 "$locals": -fhide-source-paths -Wno-missing-home-modules
35resolver: lts-14.6
41resolver: lts-14.6