12
$\begingroup$

Is there already a markdown to XML parser implemented in Mathematica? I wrote a one for my pelican rewrite, but realized I should have asked here first. Mine is almost certainly faulty in a few major ways (I just don't know them yet) and would much rather use some one else's if it exists.

$\endgroup$
6
  • $\begingroup$ I do not think Mathematica has a ton of support for Markdown in any capacity. Maybe someone knows something I do not though. $\endgroup$ Commented Aug 28, 2017 at 2:21
  • $\begingroup$ @user6014 I'm pretty sure there's no native implementation for anything. It would be nice, but also something of a blow given the amount of time I've sunk implementing this kind of thing. I was more wondering if the community had some gold-standard markdown parser. $\endgroup$ Commented Aug 28, 2017 at 2:48
  • $\begingroup$ Most of the discussions I have seen on MSE are about the other direction: from Mathematica to Markdown. You might find some useful ideas in this answer of "CSS Selectors for Symbolic XML". $\endgroup$ Commented Aug 28, 2017 at 13:21
  • $\begingroup$ @AntonAntonov the issue is less doing it myself as I've already done that. I more wanted to know if someone else has done it better. But that answer on CSS selectors is very useful. I will need to remember that one. $\endgroup$ Commented Aug 28, 2017 at 15:20
  • $\begingroup$ If you really need this (for using, not self-education), I would write a wrapper for some established library. Or why not just use the XHTML produced by the original application: daringfireball.net/projects/markdown $\endgroup$ Commented Sep 4, 2017 at 16:17

3 Answers 3

7
$\begingroup$

To get the ball rolling, here's my incomplete parser.

And here's a minimal markdown sample.


This is what my markdown parser makes of it, used like so:

CloudExport[
 MarkdownToXML[
   Import["https://raw.githubusercontent.com/b3m2a1/mathematica-BTools/\
 master/Resources/Templates/PacletServer/content/pages/About.md",
    "Text"
    ],
  "StripMetaInformation" -> False
  ],
 "HTML",
 "user:b3m2a1.testing/mdtest.html",
 Permissions -> "Public"
 ]

CloudObject["https://www.wolframcloud.com/objects/b3m2a1.testing/mdtest.html"]

(Note that it will strip that meta-information header block by default, hence the "StripMetaInformation"->False)

$\endgroup$
1
  • $\begingroup$ Does not seem to work anymore. $\endgroup$ Commented Jan 9, 2020 at 14:26
3
$\begingroup$

The package "Markdown2WL" attempts that, but unfortunately it is fairly incomplete. Also, see the corresponding Community post.


(In general I like the idea of a Markdown-to-Mathematica converter written in Mathematica.)

$\endgroup$
3
$\begingroup$

In version 14.3, you can now import and export expressions to Markdown.

ImportString["
# Title
- Item 1
- Item 2
## Subtitle
[Link](https://mathematica.stackexchange.com)
", {"Markdown", "FormattedText"}]

enter image description here

ExportString[{{1, 2, 3}, {4, 5, 6}}, "Markdown"]
(* |  |  |  |
   | - | - | - |
   | 1 | 2 | 3 |
   | 4 | 5 | 6 |  *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.