Convert markdown to xml

Hello together
Is there a way to write a custom script to convert markdown to XML and integrate this script into the context menu?
Many thanks for a hint
M

Sure. But it might help if you described what exactly you want the XML to look like. Or maybe you just take the HTML you can generate from markdown?

May I ask why you want to do this?
Also, as @chrillek mentioned, you need to provide more information on this request.

Thanks for your feedback
I would like to simply transform the Markdown text into valid XML to be able to use it in an application. The editor of OxygenXML Editor offers such an export, but only for DITA. However, I work with other XML standards (TEI, or custom schema).

I give an example for the transformation/export
The markdown source is:



#  Markdown Transformation 

Tom (26.06.2022)

## Challenge 1

How do I transform a Markdown document into an XML document? Lorem Ipsum ... .

and I want to receive the follwing XML text:


<xml>
    <topic>Markdown Transformation </topic>
    <author>Tom (26.06.2022)</author>
    <text>
        <title>Challenge 1</title>
        <body>How do I transform a Markdown document into an XML document? Lorem Ipsum ... .
        </body>
    </text>
</xml>

I hope I have been able to make my request understandable
Thanks again
M.

Basically, you’d have to define a mapping from Markdown „elements“ to XML ones.

Why not simply use XSLT to convert the HTML generated from MD? Or any other HTML to XML converter?

Or use Pandoc. It can generate several XML dialects.

Yes, I already do it that way. No problem with this workaround. But it is a workaround and I would like to save myself a step. Obviously there is no possibility to store a custom template/script in Devonthink for a conversion to XML (like the one to HTML) . Too bad.

Obviously there is no possibility to store a custom template/script in Devonthink for a conversion to XML (like the one to HTML) . Too bad.

DEVONthink supports custom templates and scripts that you can install or use as you see fit.

As far as a built-in conversion from Markdown to XML, this is the only request of its kind.

1 Like

No problem. I just wanted to know whether it works or not. I think if there are no other requests of this kind, it’s certainly not worth developing such a solution.
Thank you very much

1 Like

As @chrillek noted, XSLT is designed exactly for this purpose

See xslt-processor - npm for one of many examples of XSLT processors available.

You should be able to write XSLT code to do the conversion and then call the XSLT processor of your choice via smart rule / script.

1 Like

I’m really sorry that I obviously can’t express myself clearly. I have been writing XSLT code for years, using an excellent tool called Ogygen. An XSL transformation from markup to XML is no problem for me. I would have found a Devonthink internal solution just cool.

2 Likes

Is oxygen scriptable by Applescript or command line? If not, then you can still use Oxygen to develop your XSLT code but may want to use something else as the ultimate engine to do the conversions. By executing the script from within Devonthink it could be almost as convenient as native DT3 xslt.

Thank you
I will try to create an import script in Oxygen now, and not an export script in DT :slight_smile:
Kind regards
Manfred