git.iko.soy/typeable/pandoc
on master help sign in
Use cmark 0.5.

Closes #2605.

commitb27783e2ecf5715c9bdf209793a67380a87e65b5 authorJohn MacFarlane <jgm@berkeley.edu> dateTue 29 Dec 2015, 19:51 (11 years ago) parent59d6f02
9 files changed+49−28
deb/stack.yaml+2 osx/stack.yaml+3−1 pandoc.cabal+1−1 src/Text/Pandoc/Readers/CommonMark.hs+12−4 src/Text/Pandoc/Shared.hs+8−5 src/Text/Pandoc/Writers/CommonMark.hs+17−17 stack.full.yaml+2 stack.yaml+2 windows/stack.yaml+2
deb/stack.yaml+2
@@ -14,4 +14,6 @@ flags:
1414packages:
1515- '..'
1616- 'https://hackage.haskell.org/package/pandoc-citeproc-0.8.1.3/pandoc-citeproc-0.8.1.3.tar.gz'
17+- location: 'https://hackage.haskell.org/package/cmark-0.5.0/cmark-0.5.0.tar.gz'
18+ extra-dep: true
1719resolver: lts-3.18
osx/stack.yaml+3−1
@@ -17,4 +17,6 @@ ghc-options:
1717packages:
1818- '..'
1919- 'https://hackage.haskell.org/package/pandoc-citeproc-0.8.1.3/pandoc-citeproc-0.8.1.3.tar.gz'
20−resolver: lts-3.16
20+- location: 'https://hackage.haskell.org/package/cmark-0.5.0/cmark-0.5.0.tar.gz'
21+ extra-dep: true
22+resolver: lts-3.18
pandoc.cabal+1−1
@@ -279,7 +279,7 @@ Library
279279 deepseq-generics >= 0.1 && < 0.2,
280280 JuicyPixels >= 3.1.6.1 && < 3.3,
281281 filemanip >= 0.3 && < 0.4,
282− cmark >= 0.4.0.1 && < 0.5,
282+ cmark >= 0.5 && < 0.6,
283283 ghc-prim >= 0.2
284284 if flag(old-locale)
285285 Build-Depends: old-locale >= 1 && < 1.1,
src/Text/Pandoc/Readers/CommonMark.hs+12−4
@@ -58,15 +58,19 @@ addBlocks = foldr addBlock []
5858addBlock :: Node -> [Block] -> [Block]
5959addBlock (Node _ PARAGRAPH nodes) =
6060 (Para (addInlines nodes) :)
61−addBlock (Node _ HRULE _) =
61+addBlock (Node _ THEMATIC_BREAK _) =
6262 (HorizontalRule :)
6363addBlock (Node _ BLOCK_QUOTE nodes) =
6464 (BlockQuote (addBlocks nodes) :)
65−addBlock (Node _ (HTML t) _) =
65+addBlock (Node _ (HTML_BLOCK t) _) =
6666 (RawBlock (Format "html") (unpack t) :)
67+-- Note: the cmark parser will never generate CUSTOM_BLOCK,
68+-- so we don't need to handle it:
69+addBlock (Node _ (CUSTOM_BLOCK _onEnter _onExit) _nodes) =
70+ id
6771addBlock (Node _ (CODE_BLOCK info t) _) =
6872 (CodeBlock ("", take 1 (words (unpack info)), []) (unpack t) :)
69−addBlock (Node _ (HEADER lev) nodes) =
73+addBlock (Node _ (HEADING lev) nodes) =
7074 (Header lev ("",[],[]) (addInlines nodes) :)
7175addBlock (Node _ (LIST listAttrs) nodes) =
7276 (constructor (map (setTightness . addBlocks . children) nodes) :)
@@ -104,8 +108,12 @@ addInline (Node _ (TEXT t) _) = (map toinl clumps ++)
104108 toinl xs = Str xs
105109addInline (Node _ LINEBREAK _) = (LineBreak :)
106110addInline (Node _ SOFTBREAK _) = (SoftBreak :)
107−addInline (Node _ (INLINE_HTML t) _) =
111+addInline (Node _ (HTML_INLINE t) _) =
108112 (RawInline (Format "html") (unpack t) :)
113+-- Note: the cmark parser will never generate CUSTOM_BLOCK,
114+-- so we don't need to handle it:
115+addInline (Node _ (CUSTOM_INLINE _onEnter _onExit) _nodes) =
116+ id
109117addInline (Node _ (CODE t) _) =
110118 (Code ("",[],[]) (unpack t) :)
111119addInline (Node _ EMPH nodes) =
src/Text/Pandoc/Shared.hs+8−5
@@ -909,9 +909,11 @@ fetchItem sourceURL s =
909909 case parseURI s' of -- requires absolute URI
910910 -- We don't want to treat C:/ as a scheme:
911911 Just u' | length (uriScheme u') > 2 -> openURL (show u')
912− _ -> E.try readLocalFile -- get from local file system
913− where readLocalFile = do
914− cont <- BS.readFile fp
912+ Just u' | uriScheme u' == "file:" ->
913+ E.try $ readLocalFile $ dropWhile (=='/') (uriPath u')
914+ _ -> E.try $ readLocalFile fp -- get from local file system
915+ where readLocalFile f = do
916+ cont <- BS.readFile f
915917 return (cont, mime)
916918 dropFragmentAndQuery = takeWhile (\c -> c /= '?' && c /= '#')
917919 fp = unEscapeString $ dropFragmentAndQuery s
@@ -919,8 +921,9 @@ fetchItem sourceURL s =
919921 ".gz" -> getMimeType $ dropExtension fp
920922 ".svgz" -> getMimeType $ dropExtension fp ++ ".svg"
921923 x -> getMimeType x
922− ensureEscaped x@(_:':':'\\':_) = x -- likely windows path
923− ensureEscaped x = escapeURIString isAllowedInURI x
924+ ensureEscaped = escapeURIString isAllowedInURI . map convertSlash
925+ convertSlash '\\' = '/'
926+ convertSlash x = x
924927
925928-- | Like 'fetchItem', but also looks for items in a 'MediaBag'.
926929fetchItem' :: MediaBag -> Maybe String -> String
src/Text/Pandoc/Writers/CommonMark.hs+17−17
@@ -97,8 +97,8 @@ blockToNodes (Para xs) = (node PARAGRAPH (inlinesToNodes xs) :)
9797blockToNodes (CodeBlock (_,classes,_) xs) =
9898 (node (CODE_BLOCK (T.pack (unwords classes)) (T.pack xs)) [] :)
9999blockToNodes (RawBlock fmt xs)
100− | fmt == Format "html" = (node (HTML (T.pack xs)) [] :)
101− | otherwise = id
100+ | fmt == Format "html" = (node (HTML_BLOCK (T.pack xs)) [] :)
101+ | otherwise = (node (CUSTOM_BLOCK (T.pack xs) (T.empty)) [] :)
102102blockToNodes (BlockQuote bs) =
103103 (node BLOCK_QUOTE (blocksToNodes bs) :)
104104blockToNodes (BulletList items) =
@@ -116,8 +116,8 @@ blockToNodes (OrderedList (start, _sty, delim) items) =
116116 _ -> PERIOD_DELIM,
117117 listTight = isTightList items,
118118 listStart = start }) (map (node ITEM . blocksToNodes) items) :)
119−blockToNodes HorizontalRule = (node HRULE [] :)
120−blockToNodes (Header lev _ ils) = (node (HEADER lev) (inlinesToNodes ils) :)
119+blockToNodes HorizontalRule = (node THEMATIC_BREAK [] :)
120+blockToNodes (Header lev _ ils) = (node (HEADING lev) (inlinesToNodes ils) :)
121121blockToNodes (Div _ bs) = (blocksToNodes bs ++)
122122blockToNodes (DefinitionList items) = blockToNodes (BulletList items')
123123 where items' = map dlToBullet items
@@ -128,7 +128,7 @@ blockToNodes (DefinitionList items) = blockToNodes (BulletList items')
128128 dlToBullet (term, xs) =
129129 Para term : concat xs
130130blockToNodes t@(Table _ _ _ _ _) =
131− (node (HTML (T.pack $! writeHtmlString def $! Pandoc nullMeta [t])) [] :)
131+ (node (HTML_BLOCK (T.pack $! writeHtmlString def $! Pandoc nullMeta [t])) [] :)
132132blockToNodes Null = id
133133
134134inlinesToNodes :: [Inline] -> [Node]
@@ -142,25 +142,25 @@ inlineToNodes SoftBreak = (node SOFTBREAK [] :)
142142inlineToNodes (Emph xs) = (node EMPH (inlinesToNodes xs) :)
143143inlineToNodes (Strong xs) = (node STRONG (inlinesToNodes xs) :)
144144inlineToNodes (Strikeout xs) =
145− ((node (INLINE_HTML (T.pack "<s>")) [] : inlinesToNodes xs ++
146− [node (INLINE_HTML (T.pack "</s>")) []]) ++ )
145+ ((node (HTML_INLINE (T.pack "<s>")) [] : inlinesToNodes xs ++
146+ [node (HTML_INLINE (T.pack "</s>")) []]) ++ )
147147inlineToNodes (Superscript xs) =
148− ((node (INLINE_HTML (T.pack "<sup>")) [] : inlinesToNodes xs ++
149− [node (INLINE_HTML (T.pack "</sup>")) []]) ++ )
148+ ((node (HTML_INLINE (T.pack "<sup>")) [] : inlinesToNodes xs ++
149+ [node (HTML_INLINE (T.pack "</sup>")) []]) ++ )
150150inlineToNodes (Subscript xs) =
151− ((node (INLINE_HTML (T.pack "<sub>")) [] : inlinesToNodes xs ++
152− [node (INLINE_HTML (T.pack "</sub>")) []]) ++ )
151+ ((node (HTML_INLINE (T.pack "<sub>")) [] : inlinesToNodes xs ++
152+ [node (HTML_INLINE (T.pack "</sub>")) []]) ++ )
153153inlineToNodes (SmallCaps xs) =
154− ((node (INLINE_HTML (T.pack "<span style=\"font-variant:small-caps;\">")) []
154+ ((node (HTML_INLINE (T.pack "<span style=\"font-variant:small-caps;\">")) []
155155 : inlinesToNodes xs ++
156− [node (INLINE_HTML (T.pack "</span>")) []]) ++ )
156+ [node (HTML_INLINE (T.pack "</span>")) []]) ++ )
157157inlineToNodes (Link _ ils (url,tit)) =
158158 (node (LINK (T.pack url) (T.pack tit)) (inlinesToNodes ils) :)
159159inlineToNodes (Image _ ils (url,tit)) =
160160 (node (IMAGE (T.pack url) (T.pack tit)) (inlinesToNodes ils) :)
161161inlineToNodes (RawInline fmt xs)
162− | fmt == Format "html" = (node (INLINE_HTML (T.pack xs)) [] :)
163− | otherwise = id
162+ | fmt == Format "html" = (node (HTML_INLINE (T.pack xs)) [] :)
163+ | otherwise = (node (CUSTOM_INLINE (T.pack xs) (T.empty)) [] :)
164164inlineToNodes (Quoted qt ils) =
165165 ((node (TEXT start) [] : inlinesToNodes ils ++ [node (TEXT end) []]) ++)
166166 where (start, end) = case qt of
@@ -170,9 +170,9 @@ inlineToNodes (Code _ str) = (node (CODE (T.pack str)) [] :)
170170inlineToNodes (Math mt str) =
171171 case mt of
172172 InlineMath ->
173− (node (INLINE_HTML (T.pack ("\\(" ++ str ++ "\\)"))) [] :)
173+ (node (HTML_INLINE (T.pack ("\\(" ++ str ++ "\\)"))) [] :)
174174 DisplayMath ->
175− (node (INLINE_HTML (T.pack ("\\[" ++ str ++ "\\]"))) [] :)
175+ (node (HTML_INLINE (T.pack ("\\[" ++ str ++ "\\]"))) [] :)
176176inlineToNodes (Span _ ils) = (inlinesToNodes ils ++)
177177inlineToNodes (Cite _ ils) = (inlinesToNodes ils ++)
178178inlineToNodes (Note _) = id -- should not occur
stack.full.yaml+2
@@ -12,5 +12,7 @@ packages:
1212- '../pandoc-citeproc'
1313- '../pandoc-types'
1414- '../texmath'
15+- location: 'https://hackage.haskell.org/package/cmark-0.5.0/cmark-0.5.0.tar.gz'
16+ extra-dep: true
1517extra-deps: []
1618resolver: lts-3.18
stack.yaml+2
@@ -11,5 +11,7 @@ packages:
1111 git: 'https://github.com/jgm/pandoc-types'
1212 commit: 7b471a3d129efd8155f6cdcb2f2b58b5605df0fc
1313 extra-dep: true
14+- location: 'https://hackage.haskell.org/package/cmark-0.5.0/cmark-0.5.0.tar.gz'
15+ extra-dep: true
1416extra-deps: []
1517resolver: lts-3.18
windows/stack.yaml+2
@@ -18,6 +18,8 @@ packages:
1818 git: 'https://github.com/jgm/pandoc-types'
1919 commit: 7b471a3d129efd8155f6cdcb2f2b58b5605df0fc
2020 extra-dep: true
21+- location: 'https://hackage.haskell.org/package/cmark-0.5.0/cmark-0.5.0.tar.gz'
22+ extra-dep: true
2123extra-deps:
2224- 'hsb2hs-0.3.1'
2325resolver: lts-3.18