HTML
Markdown is a superset of HTML, meaning you can embed HTML directly in Markdown documents. mdvalidate provides special matchers for validating HTML content.
Basic HTML Matching
Section titled “Basic HTML Matching”Use the html matcher type to match any HTML content inside tags:
`some_html:html`<image src="./hello.png" />{"some_html":"<image src=\"./hello.png\" />"}`some_html:html`this is textNote: Plain text (not in tags) does not match html, even though it’s technically valid HTML.
Nested HTML
Section titled “Nested HTML”The html matcher matches arbitrarily nested HTML:
`some_html:html`<div> <image src="./hello.png" /></div>{"some_html":"<div>\n <image src=\"./hello.png\" />\n</div>"}Depth Constraints
Section titled “Depth Constraints”Specify maximum nesting depth using the dn suffix (where n is the depth):
`some_html:html`d2<div> <image src="./hello.png" /></div>{"some_html":"<div>\n <image src=\"./hello.png\" />\n</div>"}`some_html:html`d2<div> <div> <div> <image src="./hello.png" /> </div> </div></div>HTML with Execution Validation
Section titled “HTML with Execution Validation”Combine the html matcher with execution validation to validate HTML content:
`valid_html:html!tidy -q -e`<div> <p>Valid HTML</p></div>{"valid_html":"<div>\n <p>Valid HTML</p>\n</div>"}`valid_html:html!tidy -q -e`<div> <p>Unclosed tag</div>This example uses tidy to validate HTML syntax. The HTML content is passed to the executable via stdin.
XML Schema Validation
Section titled “XML Schema Validation”For precise validation, use W3C XML Schema in a code block with mds language:
```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>```<h1> Hello, world! </h1>```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>```<h2> Hello, world! </h2>Markdown to HTML Equivalence
Section titled “Markdown to HTML Equivalence”Markdown elements match their HTML equivalents automatically:
# Hi
Text<h1> Hi </h1>
TextThis works for all standard Markdown elements like headings, lists, emphasis, etc.
Comments
Section titled “Comments”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
htmlmatcher - XML Schema provides the most precise validation but is more complex
- Prefer Markdown equivalents over raw HTML when possible
- Comments are intentionally not validated