Differences Between CommonMark and Standard Markdown

CommonMark is a standardized version of Markdown that aims to provide a consistent and unambiguous specification for Markdown parsing. While standard Markdown has been widely adopted, it lacks a formal specification, leading to variations in how different Markdown processors interpret the syntax. CommonMark addresses these issues by defining clear rules and behaviors for Markdown syntax.

Key Differences

  • Specification: CommonMark has a formal specification that defines how Markdown should be parsed and rendered, while standard Markdown lacks such a specification, leading to inconsistencies across different implementations.
  • Consistent Parsing: CommonMark ensures that the same Markdown input will produce the same output across all compliant parsers, whereas standard Markdown may yield different results depending on the processor used.
  • Enhanced Features: CommonMark includes additional features and improvements over standard Markdown, such as better handling of edge cases and more robust support for complex structures.
  • Block and Inline Elements: CommonMark has clearer rules for distinguishing between block-level and inline elements, reducing ambiguity in document structure.

Sample Code Comparison

Here’s a comparison of how certain elements are handled in CommonMark versus standard Markdown:

1. Headers

Both CommonMark and standard Markdown use the same syntax for headers:


# Header 1
## Header 2
### Header 3

2. Lists

CommonMark provides consistent behavior for lists, including nested lists:


- Item 1
- Item 2
- Subitem 1
- Subitem 2

3. Emphasis

CommonMark clarifies the rules for emphasis:


This is *italic* and this is **bold**.

4. Blockquotes

Blockquotes are handled consistently in CommonMark:


> This is a blockquote.
> It can span multiple lines.

5. Inline HTML

CommonMark allows inline HTML but has stricter rules about where it can be used:


<p>This is a paragraph.</p>

Conclusion

CommonMark provides a standardized approach to Markdown, addressing the inconsistencies and ambiguities present in standard Markdown. By offering a clear specification and consistent parsing behavior, CommonMark enhances the reliability of Markdown documents across different platforms and applications. This makes it an excellent choice for developers and writers who require a predictable and uniform Markdown experience.