Skip to content

HTML

🚧 Not Implemented Yet
HTML validation is not yet implemented

Markdown is a superset of HTML, meaning you can embed HTML directly in Markdown documents. mdvalidate provides special matchers for validating HTML content.

Use the html matcher type to match any HTML content inside tags:

schema.mds
`some_html:html`
input.md
<image src="./hello.png" />
Output:
{"some_html":"<image src=\"./hello.png\" />"}
schema.mds
`some_html:html`
input.md
this is text

Note: Plain text (not in tags) does not match html, even though it’s technically valid HTML.

The html matcher matches arbitrarily nested HTML:

schema.mds
`some_html:html`
input.md
<div>
<image src="./hello.png" />
</div>
Output:
{"some_html":"<div>\n <image src=\"./hello.png\" />\n</div>"}

Specify maximum nesting depth using the dn suffix (where n is the depth):

schema.mds
`some_html:html`d2
input.md
<div>
<image src="./hello.png" />
</div>
Output:
{"some_html":"<div>\n <image src=\"./hello.png\" />\n</div>"}
schema.mds
`some_html:html`d2
input.md
<div>
<div>
<div>
<image src="./hello.png" />
</div>
</div>
</div>
🚧 Not Implemented Yet

Combine the html matcher with execution validation to validate HTML content:

schema.mds
`valid_html:html!tidy -q -e`
input.md
<div>
<p>Valid HTML</p>
</div>
Output:
{"valid_html":"<div>\n <p>Valid HTML</p>\n</div>"}
schema.mds
`valid_html:html!tidy -q -e`
input.md
<div>
<p>Unclosed tag
</div>

This example uses tidy to validate HTML syntax. The HTML content is passed to the executable via stdin.

For precise validation, use W3C XML Schema in a code block with mds language:

schema.mds
```mds
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="h1" type="xs:string"/>
</xs:schema>
```
input.md
<h1> Hello, world! </h1>
schema.mds
```mds
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="h1" type="xs:string"/>
</xs:schema>
```
input.md
<h2> Hello, world! </h2>
🚧 Not Implemented Yet
This will eventually be something you can configure. Right now it is not implemented at all, and they do not match.

Markdown elements match their HTML equivalents automatically:

schema.mds
# Hi
Text
input.md
<h1> Hi </h1>
Text

This works for all standard Markdown elements like headings, lists, emphasis, etc.

HTML-style comments are supported in Markdown but are not validated by schemas:

Some markdown content.
<!-- This is a comment. -->
Some more markdown content.

Alternative comment syntax using reference-style links is also not validated:

[This is a comment that will be hidden.]: #

This is an intentional limitation - comments are for human readers and don’t require schema enforcement.

  • Only HTML inside tags matches the html matcher
  • XML Schema provides the most precise validation but is more complex
  • Prefer Markdown equivalents over raw HTML when possible
  • Comments are intentionally not validated