aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-12-29 19:51:08 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2015-12-29 19:52:06 -0800
commitb27783e2ecf5715c9bdf209793a67380a87e65b5 (patch)
tree890328540ef2a619eb10b7a8a5885a40aa61fe72 /src/Text
parent59d6f02a9af4ea47d001c84527df77f26d2d1fdd (diff)
downloadpandoc-b27783e2ecf5715c9bdf209793a67380a87e65b5.tar.gz
Use cmark 0.5.
Closes #2605.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Readers/CommonMark.hs16
-rw-r--r--src/Text/Pandoc/Shared.hs13
-rw-r--r--src/Text/Pandoc/Writers/CommonMark.hs34
3 files changed, 37 insertions, 26 deletions
diff --git a/src/Text/Pandoc/Readers/CommonMark.hs b/src/Text/Pandoc/Readers/CommonMark.hs
index 71c7d05b2..d20d386e7 100644
--- a/src/Text/Pandoc/Readers/CommonMark.hs
+++ b/src/Text/Pandoc/Readers/CommonMark.hs
@@ -58,15 +58,19 @@ addBlocks = foldr addBlock []
addBlock :: Node -> [Block] -> [Block]
addBlock (Node _ PARAGRAPH nodes) =
(Para (addInlines nodes) :)
-addBlock (Node _ HRULE _) =
+addBlock (Node _ THEMATIC_BREAK _) =
(HorizontalRule :)
addBlock (Node _ BLOCK_QUOTE nodes) =
(BlockQuote (addBlocks nodes) :)
-addBlock (Node _ (HTML t) _) =
+addBlock (Node _ (HTML_BLOCK t) _) =
(RawBlock (Format "html") (unpack t) :)
+-- Note: the cmark parser will never generate CUSTOM_BLOCK,
+-- so we don't need to handle it:
+addBlock (Node _ (CUSTOM_BLOCK _onEnter _onExit) _nodes) =
+ id
addBlock (Node _ (CODE_BLOCK info t) _) =
(CodeBlock ("", take 1 (words (unpack info)), []) (unpack t) :)
-addBlock (Node _ (HEADER lev) nodes) =
+addBlock (Node _ (HEADING lev) nodes) =
(Header lev ("",[],[]) (addInlines nodes) :)
addBlock (Node _ (LIST listAttrs) nodes) =
(constructor (map (setTightness . addBlocks . children) nodes) :)
@@ -104,8 +108,12 @@ addInline (Node _ (TEXT t) _) = (map toinl clumps ++)
toinl xs = Str xs
addInline (Node _ LINEBREAK _) = (LineBreak :)
addInline (Node _ SOFTBREAK _) = (SoftBreak :)
-addInline (Node _ (INLINE_HTML t) _) =
+addInline (Node _ (HTML_INLINE t) _) =
(RawInline (Format "html") (unpack t) :)
+-- Note: the cmark parser will never generate CUSTOM_BLOCK,
+-- so we don't need to handle it:
+addInline (Node _ (CUSTOM_INLINE _onEnter _onExit) _nodes) =
+ id
addInline (Node _ (CODE t) _) =
(Code ("",[],[]) (unpack t) :)
addInline (Node _ EMPH nodes) =
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index 9d799fa52..aa07c81e1 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -909,9 +909,11 @@ fetchItem sourceURL s =
case parseURI s' of -- requires absolute URI
-- We don't want to treat C:/ as a scheme:
Just u' | length (uriScheme u') > 2 -> openURL (show u')
- _ -> E.try readLocalFile -- get from local file system
- where readLocalFile = do
- cont <- BS.readFile fp
+ Just u' | uriScheme u' == "file:" ->
+ E.try $ readLocalFile $ dropWhile (=='/') (uriPath u')
+ _ -> E.try $ readLocalFile fp -- get from local file system
+ where readLocalFile f = do
+ cont <- BS.readFile f
return (cont, mime)
dropFragmentAndQuery = takeWhile (\c -> c /= '?' && c /= '#')
fp = unEscapeString $ dropFragmentAndQuery s
@@ -919,8 +921,9 @@ fetchItem sourceURL s =
".gz" -> getMimeType $ dropExtension fp
".svgz" -> getMimeType $ dropExtension fp ++ ".svg"
x -> getMimeType x
- ensureEscaped x@(_:':':'\\':_) = x -- likely windows path
- ensureEscaped x = escapeURIString isAllowedInURI x
+ ensureEscaped = escapeURIString isAllowedInURI . map convertSlash
+ convertSlash '\\' = '/'
+ convertSlash x = x
-- | Like 'fetchItem', but also looks for items in a 'MediaBag'.
fetchItem' :: MediaBag -> Maybe String -> String
diff --git a/src/Text/Pandoc/Writers/CommonMark.hs b/src/Text/Pandoc/Writers/CommonMark.hs
index a786dfd24..262f491a8 100644
--- a/src/Text/Pandoc/Writers/CommonMark.hs
+++ b/src/Text/Pandoc/Writers/CommonMark.hs
@@ -97,8 +97,8 @@ blockToNodes (Para xs) = (node PARAGRAPH (inlinesToNodes xs) :)
blockToNodes (CodeBlock (_,classes,_) xs) =
(node (CODE_BLOCK (T.pack (unwords classes)) (T.pack xs)) [] :)
blockToNodes (RawBlock fmt xs)
- | fmt == Format "html" = (node (HTML (T.pack xs)) [] :)
- | otherwise = id
+ | fmt == Format "html" = (node (HTML_BLOCK (T.pack xs)) [] :)
+ | otherwise = (node (CUSTOM_BLOCK (T.pack xs) (T.empty)) [] :)
blockToNodes (BlockQuote bs) =
(node BLOCK_QUOTE (blocksToNodes bs) :)
blockToNodes (BulletList items) =
@@ -116,8 +116,8 @@ blockToNodes (OrderedList (start, _sty, delim) items) =
_ -> PERIOD_DELIM,
listTight = isTightList items,
listStart = start }) (map (node ITEM . blocksToNodes) items) :)
-blockToNodes HorizontalRule = (node HRULE [] :)
-blockToNodes (Header lev _ ils) = (node (HEADER lev) (inlinesToNodes ils) :)
+blockToNodes HorizontalRule = (node THEMATIC_BREAK [] :)
+blockToNodes (Header lev _ ils) = (node (HEADING lev) (inlinesToNodes ils) :)
blockToNodes (Div _ bs) = (blocksToNodes bs ++)
blockToNodes (DefinitionList items) = blockToNodes (BulletList items')
where items' = map dlToBullet items
@@ -128,7 +128,7 @@ blockToNodes (DefinitionList items) = blockToNodes (BulletList items')
dlToBullet (term, xs) =
Para term : concat xs
blockToNodes t@(Table _ _ _ _ _) =
- (node (HTML (T.pack $! writeHtmlString def $! Pandoc nullMeta [t])) [] :)
+ (node (HTML_BLOCK (T.pack $! writeHtmlString def $! Pandoc nullMeta [t])) [] :)
blockToNodes Null = id
inlinesToNodes :: [Inline] -> [Node]
@@ -142,25 +142,25 @@ inlineToNodes SoftBreak = (node SOFTBREAK [] :)
inlineToNodes (Emph xs) = (node EMPH (inlinesToNodes xs) :)
inlineToNodes (Strong xs) = (node STRONG (inlinesToNodes xs) :)
inlineToNodes (Strikeout xs) =
- ((node (INLINE_HTML (T.pack "<s>")) [] : inlinesToNodes xs ++
- [node (INLINE_HTML (T.pack "</s>")) []]) ++ )
+ ((node (HTML_INLINE (T.pack "<s>")) [] : inlinesToNodes xs ++
+ [node (HTML_INLINE (T.pack "</s>")) []]) ++ )
inlineToNodes (Superscript xs) =
- ((node (INLINE_HTML (T.pack "<sup>")) [] : inlinesToNodes xs ++
- [node (INLINE_HTML (T.pack "</sup>")) []]) ++ )
+ ((node (HTML_INLINE (T.pack "<sup>")) [] : inlinesToNodes xs ++
+ [node (HTML_INLINE (T.pack "</sup>")) []]) ++ )
inlineToNodes (Subscript xs) =
- ((node (INLINE_HTML (T.pack "<sub>")) [] : inlinesToNodes xs ++
- [node (INLINE_HTML (T.pack "</sub>")) []]) ++ )
+ ((node (HTML_INLINE (T.pack "<sub>")) [] : inlinesToNodes xs ++
+ [node (HTML_INLINE (T.pack "</sub>")) []]) ++ )
inlineToNodes (SmallCaps xs) =
- ((node (INLINE_HTML (T.pack "<span style=\"font-variant:small-caps;\">")) []
+ ((node (HTML_INLINE (T.pack "<span style=\"font-variant:small-caps;\">")) []
: inlinesToNodes xs ++
- [node (INLINE_HTML (T.pack "</span>")) []]) ++ )
+ [node (HTML_INLINE (T.pack "</span>")) []]) ++ )
inlineToNodes (Link _ ils (url,tit)) =
(node (LINK (T.pack url) (T.pack tit)) (inlinesToNodes ils) :)
inlineToNodes (Image _ ils (url,tit)) =
(node (IMAGE (T.pack url) (T.pack tit)) (inlinesToNodes ils) :)
inlineToNodes (RawInline fmt xs)
- | fmt == Format "html" = (node (INLINE_HTML (T.pack xs)) [] :)
- | otherwise = id
+ | fmt == Format "html" = (node (HTML_INLINE (T.pack xs)) [] :)
+ | otherwise = (node (CUSTOM_INLINE (T.pack xs) (T.empty)) [] :)
inlineToNodes (Quoted qt ils) =
((node (TEXT start) [] : inlinesToNodes ils ++ [node (TEXT end) []]) ++)
where (start, end) = case qt of
@@ -170,9 +170,9 @@ inlineToNodes (Code _ str) = (node (CODE (T.pack str)) [] :)
inlineToNodes (Math mt str) =
case mt of
InlineMath ->
- (node (INLINE_HTML (T.pack ("\\(" ++ str ++ "\\)"))) [] :)
+ (node (HTML_INLINE (T.pack ("\\(" ++ str ++ "\\)"))) [] :)
DisplayMath ->
- (node (INLINE_HTML (T.pack ("\\[" ++ str ++ "\\]"))) [] :)
+ (node (HTML_INLINE (T.pack ("\\[" ++ str ++ "\\]"))) [] :)
inlineToNodes (Span _ ils) = (inlinesToNodes ils ++)
inlineToNodes (Cite _ ils) = (inlinesToNodes ils ++)
inlineToNodes (Note _) = id -- should not occur