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

xml back to markdown #264

Closed
jeroen opened this issue Aug 31, 2018 · 6 comments
Closed

xml back to markdown #264

jeroen opened this issue Aug 31, 2018 · 6 comments

Comments

@jeroen
Copy link
Contributor

jeroen commented Aug 31, 2018

I was wondering if anyone has worked on a tool to convert the xml AST back to markdown? We would like to structurally edit markdown documents, preferably using xml tools (xpath, etc).

@nwellnhof
Copy link
Contributor

I could probably whip up an XSLT stylesheet in half an hour.

@jeroen
Copy link
Contributor Author

jeroen commented Sep 2, 2018

I think that would be fantastic.

@nwellnhof
Copy link
Contributor

nwellnhof commented Sep 2, 2018

Here's a first attempt: https://gist.github.com/nwellnhof/1594ec597ae06836bc2f974641ec4df7

Note that a MD->XML->MD roundtrip will lose a bit of information.

@jgm If you like, I can commit the XSLT stylesheet to the tools directory.

@jeroen
Copy link
Contributor Author

jeroen commented Sep 2, 2018

Thanks @nwellnhof ! This works quite well. Can you explain why verbatim html is not supported?

Also: I see your name appear in libxslt as well so I might as ask here: in my libxslt bindings the message <xsl:message>Unsupported element... currently triggers a hard error via xsltSetGenericErrorFunc. I guess in this case that is not appropriate and it should print to stderr without bailing.

Do you know if there any way in libxslt to distinguish a terminating from non terminating message in the xmlGenericErrorFunc callback?

@jgm
Copy link
Member

jgm commented Sep 3, 2018 via email

nwellnhof added a commit to nwellnhof/cmark that referenced this issue Sep 14, 2018
Initial version of an XSLT stylesheet that converts the XML format
produced by `cmark -t xml` back to Commonmark.

Fixes commonmark#264
@nwellnhof
Copy link
Contributor

@jeroen The stylesheet in the pull request also handles HTML blocks and inlines.

libxslt will invoke the error handler for every <xsl:message> regardless of the terminate attribute. But unless terminate is set to yes, it will continue to process the stylesheet. There's no structured error facility like in libxml2.

@jgm jgm closed this as completed in #267 Sep 14, 2018
talum referenced this issue in github/cmark-gfm Sep 14, 2021
Initial version of an XSLT stylesheet that converts the XML format
produced by `cmark -t xml` back to Commonmark.

Fixes #264
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants