Skip to content
This repository has been archived by the owner on Mar 26, 2022. It is now read-only.

Output Markdown from AST #63

Closed
goodmami opened this issue May 3, 2016 · 9 comments
Closed

Output Markdown from AST #63

goodmami opened this issue May 3, 2016 · 9 comments

Comments

@goodmami
Copy link

goodmami commented May 3, 2016

Is it within the project's scope to generate CommonMark from the AST? I'm looking for something that lets me programmatically assemble an AST and generate Markdown, e.g. for generating GitHub wikis. For example, if this were possible:

ast.append_child(blocks.CodeBlock("code"))

or even:

ast.append_child(parser.parse('```\ncode\n```'))

Then I could do:

>>> CommonMarkRenderer().render(ast)
[...]
```
code
```
[...]

Or perhaps this is something that would first have to be done in https://github.com/jgm/commonmark.js?

@goodmami
Copy link
Author

goodmami commented May 9, 2016

After digging around a bit more, I found that this has been discussed before at talk.commonmark.org, and furthermore it's already done in cmark as of v0.24.1, so I'd like to think it's in-scope.

Maybe I'll have to submit a PR (if I can put together the renderer)

@JoshData
Copy link

Fyi, I have some work-in-progress code for this at https://github.com/JoshData/commonmark-py-plaintext.

@goodmami
Copy link
Author

Thanks! Looks like a good start. Although the backslash escaping is excessive (e.g. for links; see http://spec.commonmark.org/0.25/#example-294)

@nikolas
Copy link
Collaborator

nikolas commented May 11, 2016

I will implement the CommonMark renderer in this library if jgm puts it in commonmark.js. In the meantime, JoshData's library looks cool, maybe we can incorporate that into CommonMark-py if necessary.

@JoshData
Copy link

@goodmami Thanks, good point. I've pushed a few more commits.

@goodmami
Copy link
Author

@nikolas Thanks! Is there a reason you are bound to commonmark.js? cmark is also a reference implementation. Perhaps because Javascript might be easier to port to Python? I'm just curious; not trying to be insistent.

@JoshData Great, thanks

@nikolas
Copy link
Collaborator

nikolas commented May 11, 2016

@goodmami That's a good point.. we aren't necessarily bound to commonmark.js, that's just where the original authors of this library happened to be porting the code from. There's no reason we can't also port the C code using cmark. I'll take a closer look at cmark and see if it makes sense to use both of these reference implementations with CommonMark-py. I wasn't aware that jgm was adding different features to the different reference implementations.

@unode
Copy link

unode commented Sep 6, 2017

Any work done in this front? I'm currently looking for exactly this.
At the moment it seems like no other "markdown" python library out there provides a way to output the same format that was parsed.

@goodmami
Copy link
Author

goodmami commented Sep 6, 2017

@unode: I'm not sure about others, but I'm not working on it and I'm currently unable to take up the task. I would still like to see it implemented, though!

Also, if this repo is de facto bound to commonmark.js, then this issue needs to be resolved first. But if this repo is free to implement features from cmark as well, then it's just a pull request away, I'd think. Any takers?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants