mmarkdown / mmark

Mmark: a powerful markdown processor in Go geared towards the IETF
https://mmark.miek.nl
Other
480 stars 45 forks source link

Enhancement: Using CDATA rather than entity escape codes in the sourcecode element #186

Closed ajeanmahoney closed 1 year ago

ajeanmahoney commented 1 year ago

Description

When mmark converts an Internet-Draft written in markdown to an xml2rfc v3 file, it substitutes &quot; for double quotation marks (") and &lt; and &gt; for angle brackets (<>). This renders fine in the various outputs of xml2rfc.

However, this escaping becomes problematic for text that is wrapped in <sourcecode>, which should be extractable from the XML and usable upon extraction. For example, this JSON example in <sourcecode> should look like this (using CDATA):

<sourcecode type="JSON"><![CDATA[
                  "identifier": [
                     {
                        "system": "urn:oid:2.16.578.1.12.4.1.2.101",
                        "type": "ENH",
                        "value": "<organizational number>"
                     ...
]]></sourcecode>

Rather than this:

<sourcecode type="JSON">
               &quot;identifier&quot;: [
                  {
                     &quot;system&quot;: &quot;urn:oid:2.16.578.1.12.4.1.2.101&quot;,
                     &quot;type&quot;: &quot;ENH&quot;,
                     &quot;value&quot;: &quot;&lt;organizational number&gt;&quot;
                     ...
</sourcecode>

What version of mmark are you using?

This is seen with versions 2.2.31 and 2.2.30

What is the most minimal markdown snippets that shows the problem?

Although not minimal, there are plenty of examples in the following: https://github.com/oauthstuff/draft-oauth-rar

miekg commented 1 year ago

Thanks. I think just making source code output CDATA makes a lot of sense, the only thing that might clash here are callouts, but prolly little used and you can always use plain artwork for those.

Should not be too hard to make such a change.

miekg commented 1 year ago

Can you try the branch in #187 ?

ajeanmahoney commented 1 year ago

Thanks for the quick response!

I set up the Go environment, checked out the cdata branch, built mmark, and converted the draft-oauth-rar md file into XML. However, I'm still seeing escape codes in <sourcecode> and no use of CDATA. Maybe I'm missing something?

miekg commented 1 year ago

[ Quoting @.***> in "Re: [mmarkdown/mmark] Enhancement: ..." ]

Thanks for the quick response!

I set up the Go environment, checked out the cdata branch, built mmark, and converted the draft-oauth-rar md file into XML. However, I'm still seeing escape codes in and no use of CDATA. Maybe I'm missing something?

Odd, if I use:

## Common Configurations

A host can participate in the domain name system in a number of ways,

```
              Local Host                        |  Foreign
                                                |
+---------+               +----------+         |  +--------+
|         | user queries  |          |queries  |  |        |
|  User   |-------------->|          |---------|->|Foreign |
| Program |               | Resolver |         |  |  Name  |
|         |<--------------|          |<--------|--| Server |
|         | user responses|          |responses|  |        |
+---------+               +----------+         |  +--------+
                             |     A            |
             cache additions |     | references |
                             V     |            |
                           +----------+         |
                           |  cache   |         |
                           +----------+         |
```

converts to:

% ./mmark x.md
<?xml version="1.0" encoding="utf-8"?>
<!-- name="GENERATOR" content="github.com/mmarkdown/mmark Mmark Markdown Processor - mmark.miek.nl" -->

<section anchor="common-configurations"><name>Common Configurations</name>
<t>A host can participate in the domain name system in a number of ways,</t>

<artwork><![CDATA[             Local Host                        |  Foreign
                                                |
+---------+               +----------+         |  +--------+
|         | user queries  |          |queries  |  |        |
|  User   |-------------->|          |---------|->|Foreign |
| Program |               | Resolver |         |  |  Name  |
|         |<--------------|          |<--------|--| Server |
|         | user responses|          |responses|  |        |
+---------+               +----------+         |  +--------+
                             |     A            |
             cache additions |     | references |
                             V     |            |
                           +----------+         |
                           |  cache   |         |
                           +----------+         |
]]>
</artwork>
</section>
</section>
miekg commented 1 year ago

fixed by #187