An OFM comment is hidden text marked with two consecutive percent signs (%%). Use comments for notes to yourself or other authors, drafts, and other text that shouldn’t appear in the rendered document.

OFM comments originate in Obsidian Flavored Markdown. This document describes Comrak’s OFM comments.

To enable OFM comments, pass -e ofm-comments on the command line, or set extension.ofm_comments in the options struct.

Here’s a paragraph with an inline comment, followed by a block comment:

Example 1
$ comrak -e ofm-comments
This is an %%inline%% comment.

%%
This is a block comment.

Block comments can span multiple lines.
%%

Syntax

A comment marker is two consecutive percent signs (%%). A single percent sign is ordinary text. Comrak recognises two kinds of comments: inline comments and block comments.

The contents of a comment are literal text. Comrak doesn’t parse Markdown inside a comment, and HTML output omits the comment entirely.

Inline comments

An inline comment begins with a comment marker in inline content and ends at the next comment marker on the same line. Its opening and closing markers can appear anywhere in the inline content:

Example 2
$ comrak -e ofm-comments
# A %%hidden%% heading

- An %%hidden%% item

**Bold %%hidden%% text**

An inline comment may be empty. Its contents may include a single percent sign, and any Markdown inside it stays literal:

Example 3
$ comrak -e ofm-comments
a %%%% b

a %%100% *not emphasis*%% b

Comment markers don’t nest. The next marker always closes the comment, so this example contains two comments with visible text between them:

Example 4
$ comrak -e ofm-comments
%%first%% visible %%second%%

An inline comment can’t span a line ending. If no closing marker appears on the same line, the opening marker is literal text:

Example 5
$ comrak -e ofm-comments
x %%aa
bb%% tail

A marker on a later line can close a different inline comment, but it can’t close one left unclosed on an earlier line:

Example 6
$ comrak -e ofm-comments
x %%unclosed
y %%closed%% z

Block comments

A block comment begins with a comment marker at the start of a line, after up to three spaces, when the rest of that line contains no percent sign. Any text after the opening marker is part of the comment. Unlike an inline comment, a block comment can contain line endings, blank lines, and Markdown block structure:

Example 7
$ comrak -e ofm-comments
%% Notes for the next revision
# A hidden heading

- A hidden item
- Another hidden item
%%

A block comment can interrupt a paragraph:

Example 8
$ comrak -e ofm-comments
before
%%
hidden
%%
after

The block comment ends at the next comment marker, wherever it appears on a later line. Text after the closing marker remains visible, and Comrak parses its Markdown as usual:

Example 9
$ comrak -e ofm-comments
%%
# A hidden heading

- A hidden item
%%tail

%%
hidden
%%# A visible heading

If the opening line contains another percent sign, it doesn’t begin a block comment. A complete pair of markers on that line forms an inline comment instead:

Example 10
$ comrak -e ofm-comments
%%inline%% visible

If that line has no complete pair, its markers remain literal; an inline comment can’t continue onto the next line:

Example 11
$ comrak -e ofm-comments
%%a%b
cc%%tail

A block comment without a closing marker continues to the end of the document:

Example 12
$ comrak -e ofm-comments
%%
aa

bb

Block comments may appear in containers, such as block quotes and list items. The usual container markers and indentation apply to the opening and closing lines:

Example 13
$ comrak -e ofm-comments
> %%
> hidden
> %%visible

- %%
  hidden
  %%visible

Precedence and escaping

Code spans and fenced code blocks take precedence over comments. Comment markers inside them are literal text:

Example 14
$ comrak -e ofm-comments
`%%inline%%`

```
%%
# text
%%
```

A backslash escape or an entity reference produces a literal percent sign, not part of a comment marker:

Example 15
$ comrak -e ofm-comments
\%%not a comment\%%

%%also not a comment%%

Output

HTML output omits each comment, including its markers and contents. It doesn’t replace the comment with an HTML comment or any other element. Whitespace around an inline comment remains, which can leave two adjacent spaces:

Example 16
$ comrak -e ofm-comments
before %%hidden%% after

CommonMark output writes comments back with %% markers. It preserves their literal contents, and leaves an unclosed block comment unclosed.

In XML output, both kinds of comment are a comment element with xml:space="preserve". The element’s text is the comment’s literal contents, without its markers.

In the AST, an inline comment is a NodeValue::CommentInline. Its NodeComment holds the literal contents. A block comment is a NodeValue::MultilineComment. Its NodeCommentBlock holds the literal contents and whether the comment was explicitly closed. Neither kind of comment has children.

Interactions

Inline comments work in table cells just as they do in other inline content:

Example 17
$ comrak -e ofm-comments -e table
a %%hidden%% | b
--- | ---
x %%hidden%% y | z

With OFM callouts, an inline comment can hide part or all of a callout title:

Example 18
$ comrak -e ofm-callouts -e ofm-comments
> [!note] %%hidden%%
> Body

A block comment between lines of a list item doesn’t by itself make the containing list loose:

Example 19
$ comrak -e ofm-comments
- before
  %%
  hidden%%
  after
- next

A blank line inside such a comment still affects the list’s block structure, so it can make the list loose:

Example 20
$ comrak -e ofm-comments
- %%
  first hidden paragraph

  second hidden paragraph%%after
- next