Closed kdheepak closed 8 years ago
The library doesn't contain any special way to do this, so
your best bet is to spawn a pandoc process in a shell.
pandoc -s -f markdown -t json
will convert to a json
representation of the AST, which you can manually convert
to a python object using json.loads
.
+++ Dheepak Krishnamurthy [Dec 20 15 21:01 ]:
I'm not sure if this is the best place to ask this question. I have a sample.md as shown below. The following is a ipython notebook
{%ipython-notebook.ipynb%}
When a liquid-tag type syntax is found, I want to add notebook to AST. The end goal is to create a filter that allows a user to include a ipython notebook by using this syntax. I'm able to get the file_name from the sample.md file, and convert it to a markdown file. But I don't quite understand how to get from here to importing the markdown file / ipython notebook into the AST.
!/usr/bin/env python
import os import sys from pandocfilters import toJSONFilter, Str, Para import subprocess
def convert_notebook_to_markdown(file_name): subprocess.call(["jupyter", "nbconvert", "--to", "markdown", file_name])
def convert_markdown_to_para(file_name):
e.g. file_name is ipython-notebook.ipynb.
ipython-notebook.ipynb -> AST
return(file_name)
def convert_notebook_to_para(file_name): convert_notebook_to_markdown(file_name) para = convert_markdown_to_para(file_name) return(para)
def notebook_convert(key, value, format, meta): if key == 'Para': sys.stderr.write("Printing Para " + str(value) + "\n") string_value = value[0]['c'] if string_value[0:1] == "{%" and string_value[-2:-1] == "%}" and '.ipynb ' in string_value: file_name = string_value[2:-2] value[0]['c'] = convert_notebook_to_para(file_name) return Para(value)
if name == "main": toJSONFilter(notebook_convert)
Does that make sense? Is this possible to do?
— Reply to this email directly or [1]view it on GitHub.
References
I'm not sure if this is the best place to ask this question. I have a sample.md as shown below.
When a
liquid-tag
type syntax is found, I want to add notebook to AST. The end goal is to create a filter that allows a user to include a ipython notebook by using this syntax. I'm able to get thefile_name
from the sample.md file, and convert it to a markdown file. But I don't quite understand how to get from here to importing the markdown file / ipython notebook into the AST.Does that make sense? Is this possible to do?