Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown writer not escaping quotes within JSON #5369

Closed
choldgraf opened this issue Mar 16, 2019 · 3 comments
Closed

Markdown writer not escaping quotes within JSON #5369

choldgraf opened this issue Mar 16, 2019 · 3 comments

Comments

@choldgraf
Copy link

choldgraf commented Mar 16, 2019

Pandoc version: 2.7.1
OS: ubuntu latest


I'm playing around with converting .ipynb format to markdown, and ran into a snag that I think is because Pandoc is embedding JSON in a string but is not escaping the quotes characteres.

When converting ipynb to markdown, I noticed that double-quotes were being used within the contents the metadata, like so:

::: {.cell .markdown tags="["heresatag"]"}

This was confusing the subsequent writer, which didn't correctly parse the contents of tags= because of the double-quotation marks.

Is there a way that we could escape the inner quotation marks so that they don't mess up the conversion?

@mb21
Copy link
Collaborator

mb21 commented Mar 16, 2019

Can you post a minimal sample ipynb file that is converted to the markdown you posted?

@choldgraf
Copy link
Author

choldgraf commented Mar 16, 2019

Sure thing 👍

Here's the contents of an .ipynb file:

ipynb file
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "tags": [
     "one",
     "two"
    ]
   },
   "source": [
    "This cell has metadata"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "tags": [
     "three",
     "four"
    ]
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "This code cell has metadata\n"
     ]
    }
   ],
   "source": [
    "print(\"This code cell has metadata\")"
   ]
  }
 ],
 "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.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}

it has two cells, each of which has two tags. (above the metadata for each cell is in a "metadata" key.

when I convert it to markdown with

# First copy the above code into a file called `minimal.ipynb`
pandoc minimal.ipynb -o minimal.md -s

it outputs this:

---
jupyter:
  kernelspec:
    display_name: Python 3
    language: python
    name: python3
  language_info:
    codemirror_mode:
      name: ipython
      version: '3.0'
    file_extension: '.py'
    mimetype: 'text/x-python'
    name: python
    nbconvert_exporter: python
    pygments_lexer: ipython3
    version: '3.6.5'
  nbformat: 4
  nbformat_minor: 2
---

::: {.cell .markdown tags="["one","two"]"}
This cell has metadata
:::

::: {.cell .code execution_count="2" tags="["three","four"]"}
\``` {.python}
print("This code cell has metadata")
\```

::: {.output .stream .stdout}
    This code cell has metadata
:::
:::

(backslashes at the start of code fences are mine, I added them so github would render it)

@mb21
Copy link
Collaborator

mb21 commented Mar 17, 2019

Thanks! Surprisingly, this appears to be a problem with the markdown writer:

echo '[Div ("",[],[("tags","[\"one\",\"two\"]")]) [] ]' | pandoc -f native -t markdown

::: {tags="["one","two"]"}
:::

@jgm jgm closed this as completed in 3880a23 Mar 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants