From b27783e2ecf5715c9bdf209793a67380a87e65b5 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 29 Dec 2015 19:51:08 -0800 Subject: Use cmark 0.5. Closes #2605. --- deb/stack.yaml | 2 ++ osx/stack.yaml | 4 +++- pandoc.cabal | 2 +- src/Text/Pandoc/Readers/CommonMark.hs | 16 ++++++++++++---- src/Text/Pandoc/Shared.hs | 13 ++++++++----- src/Text/Pandoc/Writers/CommonMark.hs | 34 +++++++++++++++++----------------- stack.full.yaml | 2 ++ stack.yaml | 2 ++ windows/stack.yaml | 2 ++ 9 files changed, 49 insertions(+), 28 deletions(-) diff --git a/deb/stack.yaml b/deb/stack.yaml index 287949e97..503eba000 100644 --- a/deb/stack.yaml +++ b/deb/stack.yaml @@ -14,4 +14,6 @@ flags: packages: - '..' - 'https://hackage.haskell.org/package/pandoc-citeproc-0.8.1.3/pandoc-citeproc-0.8.1.3.tar.gz' +- location: 'https://hackage.haskell.org/package/cmark-0.5.0/cmark-0.5.0.tar.gz' + extra-dep: true resolver: lts-3.18 diff --git a/osx/stack.yaml b/osx/stack.yaml index 19ce8482d..2752f86de 100644 --- a/osx/stack.yaml +++ b/osx/stack.yaml @@ -17,4 +17,6 @@ ghc-options: packages: - '..' - 'https://hackage.haskell.org/package/pandoc-citeproc-0.8.1.3/pandoc-citeproc-0.8.1.3.tar.gz' -resolver: lts-3.16 +- location: 'https://hackage.haskell.org/package/cmark-0.5.0/cmark-0.5.0.tar.gz' + extra-dep: true +resolver: lts-3.18 diff --git a/pandoc.cabal b/pandoc.cabal index 5dda339c3..24170c719 100644 --- a/pandoc.cabal +++ b/pandoc.cabal @@ -279,7 +279,7 @@ Library deepseq-generics >= 0.1 && < 0.2, JuicyPixels >= 3.1.6.1 && < 3.3, filemanip >= 0.3 && < 0.4, - cmark >= 0.4.0.1 && < 0.5, + cmark >= 0.5 && < 0.6, ghc-prim >= 0.2 if flag(old-locale) Build-Depends: old-locale >= 1 && < 1.1, 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 "")) [] : inlinesToNodes xs ++ - [node (INLINE_HTML (T.pack "")) []]) ++ ) + ((node (HTML_INLINE (T.pack "")) [] : inlinesToNodes xs ++ + [node (HTML_INLINE (T.pack "")) []]) ++ ) inlineToNodes (Superscript xs) = - ((node (INLINE_HTML (T.pack "")) [] : inlinesToNodes xs ++ - [node (INLINE_HTML (T.pack "")) []]) ++ ) + ((node (HTML_INLINE (T.pack "")) [] : inlinesToNodes xs ++ + [node (HTML_INLINE (T.pack "")) []]) ++ ) inlineToNodes (Subscript xs) = - ((node (INLINE_HTML (T.pack "")) [] : inlinesToNodes xs ++ - [node (INLINE_HTML (T.pack "")) []]) ++ ) + ((node (HTML_INLINE (T.pack "")) [] : inlinesToNodes xs ++ + [node (HTML_INLINE (T.pack "")) []]) ++ ) inlineToNodes (SmallCaps xs) = - ((node (INLINE_HTML (T.pack "")) [] + ((node (HTML_INLINE (T.pack "")) [] : inlinesToNodes xs ++ - [node (INLINE_HTML (T.pack "")) []]) ++ ) + [node (HTML_INLINE (T.pack "")) []]) ++ ) 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 diff --git a/stack.full.yaml b/stack.full.yaml index 4ca0a4a69..52c763de2 100644 --- a/stack.full.yaml +++ b/stack.full.yaml @@ -12,5 +12,7 @@ packages: - '../pandoc-citeproc' - '../pandoc-types' - '../texmath' +- location: 'https://hackage.haskell.org/package/cmark-0.5.0/cmark-0.5.0.tar.gz' + extra-dep: true extra-deps: [] resolver: lts-3.18 diff --git a/stack.yaml b/stack.yaml index 6c6da96fb..5b9480a2c 100644 --- a/stack.yaml +++ b/stack.yaml @@ -11,5 +11,7 @@ packages: git: 'https://github.com/jgm/pandoc-types' commit: 7b471a3d129efd8155f6cdcb2f2b58b5605df0fc extra-dep: true +- location: 'https://hackage.haskell.org/package/cmark-0.5.0/cmark-0.5.0.tar.gz' + extra-dep: true extra-deps: [] resolver: lts-3.18 diff --git a/windows/stack.yaml b/windows/stack.yaml index cf3f2aad4..8fd09b2a2 100644 --- a/windows/stack.yaml +++ b/windows/stack.yaml @@ -18,6 +18,8 @@ packages: git: 'https://github.com/jgm/pandoc-types' commit: 7b471a3d129efd8155f6cdcb2f2b58b5605df0fc extra-dep: true +- location: 'https://hackage.haskell.org/package/cmark-0.5.0/cmark-0.5.0.tar.gz' + extra-dep: true extra-deps: - 'hsb2hs-0.3.1' resolver: lts-3.18 -- cgit v1.2.3