aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Krewinkel <[email protected]>2022-08-22 12:06:08 +0200
committerAlbert Krewinkel <[email protected]>2022-08-22 12:53:58 +0200
commit08f1f4551cea2b1af660b35ce3ddf39dd4ed416c (patch)
tree5361befd68f412acc09e37591f23e65103247006
parent90610eb78c3fcd9b943fd2e4d7730149248250d8 (diff)
Org writer: add support for jupyter nodebook cells.
Closes: #6367
-rw-r--r--src/Text/Pandoc/Writers/Org.hs8
-rw-r--r--test/command/6367.md75
2 files changed, 83 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Writers/Org.hs b/src/Text/Pandoc/Writers/Org.hs
index a749e48af..936e2aa87 100644
--- a/src/Text/Pandoc/Writers/Org.hs
+++ b/src/Text/Pandoc/Writers/Org.hs
@@ -105,6 +105,14 @@ blockToOrg :: PandocMonad m
=> Block -- ^ Block element
-> Org m (Doc Text)
blockToOrg Null = return empty
+blockToOrg (Div (_, ["cell", "code"], _) (CodeBlock attr t : bs)) = do
+ -- ipynb code cell
+ let (ident, classes, kvs) = attr
+ blockListToOrg (CodeBlock (ident, classes ++ ["code"], kvs) t : bs)
+blockToOrg (Div (_, ["output", "execute_result"], _) [CodeBlock _attr t]) = do
+ -- ipynb code result
+ return $ "#+RESULTS:" $$
+ (prefixed ": " . vcat . map literal $ T.split (== '\n') t)
blockToOrg (Div attr@(ident,_,_) bs) = do
opts <- gets stOptions
-- Strip off bibliography if citations enabled
diff --git a/test/command/6367.md b/test/command/6367.md
new file mode 100644
index 000000000..74c56a04b
--- /dev/null
+++ b/test/command/6367.md
@@ -0,0 +1,75 @@
+```
+% pandoc -f ipynb -t org
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "A Markdown cell"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "2"
+ ]
+ },
+ "execution_count": 1,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# A code cell\n",
+ "1 + 1"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Another Markdown cell"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.8.2"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 4
+}
+^D
+A Markdown cell
+
+#+begin_src jupyter-python
+# A code cell
+1 + 1
+#+end_src
+
+#+RESULTS:
+: 2
+
+Another Markdown cell
+```