Skip to content

Add language prefixes for inline code - #1

Merged
ioquatix merged 7 commits into
mainfrom
inline-code-info
Aug 20, 2026
Merged

Add language prefixes for inline code#1
ioquatix merged 7 commits into
mainfrom
inline-code-info

Conversation

@ioquatix

@ioquatix ioquatix commented Jul 13, 2026

Copy link
Copy Markdown
Member

Summary

This adds opt-in language annotations for inline code spans through CMARK_OPT_INLINE_CODE_INFO and the CLI flag --inline-code-info.

Ruby code: ruby:`Object.new`

With the option enabled, this renders as:

<p>Ruby code: <code class="language-ruby">Object.new</code></p>

Without the option, the language prefix remains literal text:

<p>Ruby code: ruby:<code>Object.new</code></p>

Language identifiers begin with an alphanumeric character and may additionally contain _, -, +, #, and .. Examples include c++, c#, objective-c, and ruby_template.

Behavior

  • A language prefix is recognized only when immediately followed by a complete inline code span.
  • Ordinary punctuation after inline code remains untouched, for example Use `x`: then continue.
  • Empty, quoted, invalid, and unclosed prefixes remain literal Markdown.
  • CommonMark output preserves the prefix syntax and round-trips it.
  • HTML output uses class="language-..."; XML output exposes the language in the info attribute.
  • Smart-punctuation mode recognizes language identifiers before processing _, -, or ..

API

  • Adds cmark_node_get_code_info and cmark_node_set_code_info for code blocks and inline code spans.
  • Inline setters validate the language identifier and treat an empty or null value as clearing it.
  • Existing cmark_node_get_fence_info and cmark_node_set_fence_info behavior remains restricted to code blocks and front matter.
  • Inline language parsing remains disabled unless CMARK_OPT_INLINE_CODE_INFO is selected.

Validation

Passing:

  • Inline language round-trip tests.
  • Smart-punctuation inline language round-trip tests.
  • Regression tests for disabled parsing and punctuation preservation.
  • C API parser, accessor, setter, HTML, and CommonMark assertions.
  • AddressSanitizer runs for both inline language test suites.

The complete test suite retains four failures already present on the base branch: two standalone inline-node newline assertions and the <m:abc> autolink expectation in three test variants.

@samuel-williams-shopify samuel-williams-shopify changed the title Add inline code info strings Add language prefixes for inline code Aug 20, 2026
ioquatix and others added 7 commits August 20, 2026 16:38
Assisted-By: devx/c76f68ef-c5ab-4096-b170-fc6974ad760d
Assisted-By: devx/c76f68ef-c5ab-4096-b170-fc6974ad760d
Assisted-By: devx/c76f68ef-c5ab-4096-b170-fc6974ad760d
Assisted-By: devx/c76f68ef-c5ab-4096-b170-fc6974ad760d
@ioquatix
ioquatix merged commit 63aeddc into main Aug 20, 2026
10 checks passed
@ioquatix
ioquatix deleted the inline-code-info branch August 20, 2026 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants