Skip to content

feat: add support for user comments in presentation rendering#773

Merged
mfontanini merged 3 commits intomfontanini:masterfrom
Cyberistic:feature/user-comments
Feb 7, 2026
Merged

feat: add support for user comments in presentation rendering#773
mfontanini merged 3 commits intomfontanini:masterfrom
Cyberistic:feature/user-comments

Conversation

@Cyberistic
Copy link
Contributor

@Cyberistic Cyberistic commented Nov 2, 2025

I've found the function should_ignore_comment and have been relying on it to add user comments inside presentations by abusing the <!-- vim: comment here --> since I don't use vim for this anyways.

This isn't clean and a dedicated way to comment should be added IMO. Also, there is an issue with the hacky vim solution above, it adds a newline where the comment should be ignored; fixed by using self.slide_state.ignore_element_line_break = true on ignored comments.

Current comments:
image

PR with ignore line breaks:
image

Copy link
Owner

@mfontanini mfontanini left a comment

Choose a reason for hiding this comment

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

Sorry, I've been out for a while and this slipped through. A couple of comments but looks good overall!


// Ignore user comments with Comment: prefix (case-insensitive)
// e.g., <!-- Comment: This is a comment -->
if trimmed_comment.len() >= 8 {
Copy link
Owner

Choose a reason for hiding this comment

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

The comment: case is better handled if you add it to the CommentCommand enum, e.g.

enum CommentCommand {
     // ....
    Comment(String)
}

Which is then ignored in the match that handles this. I also don't think making this case insensitive makes sense here given no other comment command is case insensitive.

examples/demo.md Outdated

Customizability
---
<!-- Comment: You can add comments like this that won't show up in the presentation -->
Copy link
Owner

Choose a reason for hiding this comment

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

I wouldn't touch the demo presentation for this feature. The docs are the ultimate guide, this is just here to show the most commonly used features.

@StefanUlbrich
Copy link

Hi, this would be a very useful feature. Is there any progress?

Copilot AI review requested due to automatic review settings February 4, 2026 15:08
@Cyberistic
Copy link
Contributor Author

Hi, this would be a very useful feature. Is there any progress?

Thanks for the reminder, applied latest changes. Waiting for @mfontanini to confirm and merge.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds first-class support for “user comments” in HTML comments so they don’t affect rendered slide spacing, and documents the feature.

Changes:

  • Prevents ignored/unparseable HTML comments from introducing an extra rendered line break.
  • Adds a comment: command variant and ignores it during presentation rendering.
  • Documents supported user comment formats and cleans up a whitespace-only line in the demo markdown.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/presentation/builder/comment.rs Implements no-linebreak behavior for ignored comments; adds Comment command parsing and tests.
examples/demo.md Removes a stray whitespace-only line from the demo.
docs/src/features/commands.md Documents user comment formats (// and comment:).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 16 to +20
Err(error) => {
// If we failed to parse this, make sure we shouldn't have ignored it
if self.should_ignore_comment(comment) {
// Ignored comments should not add line breaks
self.slide_state.ignore_element_line_break = true;
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

With command_prefix configured, valid commands that do not start with the prefix can still be parsed/executed because parsing happens before this error branch and only falls back to should_ignore_comment when parsing fails. This contradicts the documented behavior of command_prefix (docs/src/configuration/options.md). Consider enforcing the prefix before attempting to parse (or update docs/tests to reflect the intended semantics).

Copilot uses AI. Check for mistakes.
Comment on lines 18 to 22
if self.should_ignore_comment(comment) {
// Ignored comments should not add line breaks
self.slide_state.ignore_element_line_break = true;
return Ok(());
}
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

This fixes the extra newline issue for ignored comments by setting ignore_element_line_break, but there isn’t a regression test asserting the rendered output doesn’t gain a blank line when an ignored comment appears between two rendered elements. Adding a render-based test (e.g., text + ignored comment + text) would help prevent reintroducing this behavior.

Copilot uses AI. Check for mistakes.
Comment on lines 219 to 212
SkipSlide,
SpeakerNote(String),
SnippetOutput(String),
Comment(String),
}
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

CommentCommand::Comment is now a parseable command, but CommentCommand::generate_samples() (used by --list-comment-commands) still claims to generate samples for “all available commands” and doesn’t include comment. Either add a sample for comment: to keep the listing complete, or adjust the wording/approach so user comments aren’t treated as a command.

Copilot uses AI. Check for mistakes.

// Ignore user comments with // prefix
// e.g., <!-- // This is a comment -->
let trimmed_comment = comment.trim_start_matches(&self.options.command_prefix).trim();
Copy link
Owner

Choose a reason for hiding this comment

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

Probably should have noticed this before but why the trim_start_matches(command_prefix)? This means you're trying to trim a prefix (say cmd: although an empty string by default) and then trying to see if what you end up with starts with //. This means this code would ignore a command like <!-- cmd: // foo --> and that seems wrong to me.

e.g. test with this presentation:

---
options:
  command_prefix: "cmd:"
---

<!-- cmd://hi -->

To me this line shouldn't exist and the line below should just check if comment.starts_with("//") since this is already trimmed a few lines above.

// Ignore vim-like code folding tags
let comment = comment.trim();
comment == "{{{" || comment == "}}}"
if comment == "{{{" || comment == "}}}" {
Copy link
Owner

Choose a reason for hiding this comment

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

Or just to be concise: this line should just be

 comment == "{{{" || comment == "}}}" || comment.starts_with("//")

@mfontanini mfontanini force-pushed the feature/user-comments branch from 55ed44c to bca8dbb Compare February 7, 2026 22:00
@mfontanini mfontanini merged commit 31f939f into mfontanini:master Feb 7, 2026
4 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.

3 participants