git.iko.soy/typeable/pandoc
on master help sign in
Add `raw_markdown` extension affecting `ipynb` reader.

Specifying `-f ipynb+raw_markdown` will cause Markdown cells to be represented as raw Markdown blocks, instead of being parsed. This is not what you want when going from `ipynb` to other formats, but it may be useful when going from `ipynb` to Markdown or to `ipynb`, to avoid semantically insignificant changes in the contents of the Markdown cells that might otherwise be introduced. Closes #5408.

commit48fb6d947df96e8e1f339b2916740f3e216f8908 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 23 Jul 2020, 17:47 (6 years ago) parentac1f45c
4 files changed+18−4
MANUAL.txt+8 src/Text/Pandoc/Extensions.hs+3−1 src/Text/Pandoc/Readers/Ipynb.hs+5−1 src/Text/Pandoc/Writers/Markdown.hs+2−2
MANUAL.txt+8
@@ -2910,6 +2910,14 @@ input formats
29102910In the `muse` input format, this enables Text::Amuse
29112911extensions to Emacs Muse markup.
29122912
2913+#### Extension: `raw_markdown` ####
2914+
2915+In the `ipynb` input format, this causes Markdown cells
2916+to be included as raw Markdown blocks (allowing lossless
2917+round-tripping) rather than being parsed. Use this only
2918+when you are targetting `ipynb` or a markdown-based
2919+output format.
2920+
29132921#### Extension: `citations` {#org-citations}
29142922
29152923Some aspects of [Pandoc's Markdown citation syntax](#citations) are also accepted
src/Text/Pandoc/Extensions.hs+3−1
@@ -133,6 +133,7 @@ data Extension =
133133 | Ext_raw_attribute -- ^ Allow explicit raw blocks/inlines
134134 | Ext_raw_html -- ^ Allow raw HTML
135135 | Ext_raw_tex -- ^ Allow raw TeX (other than math)
136+ | Ext_raw_markdown -- ^ Parse markdown in ipynb as raw markdown
136137 | Ext_shortcut_reference_links -- ^ Shortcut reference links
137138 | Ext_simple_tables -- ^ Pandoc-style simple tables
138139 | Ext_smart -- ^ "Smart" quotes, apostrophes, ellipses, dashes
@@ -442,7 +443,8 @@ getAllExtensions f = universalExtensions <> getAll f
442443 getAll "markdown_mmd" = allMarkdownExtensions
443444 getAll "markdown_github" = allMarkdownExtensions
444445 getAll "markdown" = allMarkdownExtensions
445− getAll "ipynb" = allMarkdownExtensions
446+ getAll "ipynb" = allMarkdownExtensions <> extensionsFromList
447+ [ Ext_raw_markdown ]
446448 getAll "docx" = extensionsFromList
447449 [ Ext_empty_paragraphs
448450 , Ext_styles
src/Text/Pandoc/Readers/Ipynb.hs+5−1
@@ -78,7 +78,11 @@ cellToBlocks opts lang c = do
7878 mapM_ addAttachment attachments
7979 case cellType c of
8080 Ipynb.Markdown -> do
81− Pandoc _ bs <- walk fixImage <$> readMarkdown opts source
81+ bs <- if isEnabled Ext_raw_markdown opts
82+ then return [RawBlock (Format "markdown") source]
83+ else do
84+ Pandoc _ bs <- walk fixImage <$> readMarkdown opts source
85+ return bs
8286 return $ B.divWith ("",["cell","markdown"],kvs)
8387 $ B.fromList bs
8488 Ipynb.Heading lev -> do
src/Text/Pandoc/Writers/Markdown.hs+2−2
@@ -483,10 +483,10 @@ blockToMarkdown' opts b@(RawBlock f str) = do
483483 let renderEmpty = mempty <$ report (BlockNotRendered b)
484484 case variant of
485485 PlainText -> renderEmpty
486− _ | isEnabled Ext_raw_attribute opts -> rawAttribBlock
487− | f `elem` ["markdown", "markdown_github", "markdown_phpextra",
486+ _ | f `elem` ["markdown", "markdown_github", "markdown_phpextra",
488487 "markdown_mmd", "markdown_strict"] ->
489488 return $ literal str <> literal "\n"
489+ | isEnabled Ext_raw_attribute opts -> rawAttribBlock
490490 | f `elem` ["html", "html5", "html4"] ->
491491 case () of
492492 _ | isEnabled Ext_markdown_attribute opts -> return $