Skip to content

Comments

Fix doc attribute parsing to properly handle block comments#1130

Merged
emilio merged 1 commit intomozilla:mainfrom
pexip:documentation-blocks
Feb 21, 2026
Merged

Fix doc attribute parsing to properly handle block comments#1130
emilio merged 1 commit intomozilla:mainfrom
pexip:documentation-blocks

Conversation

@sd-collins
Copy link
Contributor

@sd-collins sd-collins commented Feb 20, 2026

The existing parsing logic is flawed, as it concatenates consecutive lines, e.g. this:

/// # Heading
/// This is the first paragraph.
///
/// - First
/// - Second
/// - Third

...becomes this (correct):

/**
 * # Heading
 * This is the first paragraph.
 *
 * - First
 * - Second
 * - Third
 */

But the same thing as a block comment:

/**
# Heading
This is the first paragraph.

- First
- Second
- Third
*/

...becomes this (broken):

/**
 * # Heading This is the first paragraph.
 *
 *- First - Second - Third
 */

The current splitting logic (introduced in #454) tries to join together lines in the same paragraph but without properly parsing and interpreting the markdown, leading to removing semantically-important line breaks.
It also allows for broken syntax if a / is placed at the beginning of a line, since there is no leading space after the * marker (creating a */ which closes the comment block).

The simpler approach in this PR is to simply split on newlines, which makes the parsing behaviour of block doc comments more consistent with single-line doc comments. We also add a single space at the start of each line, which is normally included in single-line doc comments but not in the block variant and prevents us accidentally creating a */.

EDIT: I also realised I had to remove "common" whitespace between all lines in the block, or else block doc comments within modules are parsed with leading whitespace included, which is usually not intended. I have included tests for all new functionality and slightly modified the documentation_attr test for the new behaviour.

The existing parsing logic is flawed, as it concatenates consecutive
lines, e.g. this:

/**
This is the first paragraph.
*/

...becomes this:

/**
 * # Heading This is the first paragraph.
*/

Lists are also effected.
Copy link
Collaborator

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks sensible

@emilio emilio added this pull request to the merge queue Feb 21, 2026
Merged via the queue into mozilla:main with commit 3620e88 Feb 21, 2026
3 checks passed
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