Skip to content

Commit 31f939f

Browse files
authored
feat: add support for user comments in presentation rendering (#773)
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: <img width="770" height="465" alt="image" src="https://github.com/user-attachments/assets/f0a3aa41-1b90-463f-917b-416731b8a207" /> PR with ignore line breaks: <img width="751" height="414" alt="image" src="https://github.com/user-attachments/assets/f242463e-51f2-45f1-a5a1-69b014175d41" />
2 parents 516d5bb + bca8dbb commit 31f939f

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

docs/src/features/commands.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,25 @@ centered
149149
right aligned
150150
```
151151

152+
153+
## User comments
154+
155+
User comments such as personal notes, TODOs, and other documentation that will
156+
be ignored during presentation rendering can be added using these formats:
157+
158+
```markdown
159+
<!-- // This is a user comment -->
160+
<!-- comment: This is also a user comment which won't be rendered -->
161+
```
162+
These comments are completely invisible during presentation and useful for:
163+
164+
- Personal notes and reminders
165+
- TODO items and planning notes
166+
- Source references and attribution
167+
168+
169+
170+
152171
## Listing available comment commands
153172

154173
The `--list-comment-commands` CLI option outputs all available comment commands to stdout, making it easy to discover and use them in external tools and editors.
@@ -216,4 +235,3 @@ endif
216235
```
217236

218237
With this configuration, pressing `Ctrl+K` in insert mode will open an fzf picker with all available comment commands, allowing you to quickly select and insert them into your presentation.
219-

examples/demo.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ author: Matias
55

66
Customizability
77
---
8-
98
_presenterm_ allows configuring almost anything about your presentation:
109

1110
* The colors used.

src/presentation/builder/comment.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ impl PresentationBuilder<'_, '_> {
1616
Err(error) => {
1717
// If we failed to parse this, make sure we shouldn't have ignored it
1818
if self.should_ignore_comment(comment) {
19+
// Ignored comments should not add line breaks
20+
self.slide_state.ignore_element_line_break = true;
1921
return Ok(());
2022
}
2123
return Err(self.invalid_presentation(source_position, error));
@@ -42,6 +44,7 @@ impl PresentationBuilder<'_, '_> {
4244
CommentCommand::NewLines(count) => {
4345
self.push_line_breaks(count as usize * self.slide_font_size() as usize);
4446
}
47+
CommentCommand::Comment(_) => {}
4548
CommentCommand::JumpToMiddle => self.chunk_operations.push(RenderOperation::JumpToVerticalCenter),
4649
CommentCommand::InitColumnLayout(columns) => {
4750
self.validate_column_layout(&columns, source_position)?;
@@ -149,7 +152,7 @@ impl PresentationBuilder<'_, '_> {
149152
} else {
150153
// Ignore vim-like code folding tags
151154
let comment = comment.trim();
152-
comment == "{{{" || comment == "}}}"
155+
comment == "{{{" || comment == "}}}" || comment.starts_with("//")
153156
}
154157
}
155158

@@ -205,6 +208,7 @@ pub(crate) enum CommentCommand {
205208
SkipSlide,
206209
SpeakerNote(String),
207210
SnippetOutput(String),
211+
Comment(String),
208212
}
209213

210214
impl CommentCommand {
@@ -290,6 +294,7 @@ mod tests {
290294
#[case::incremental_lists("newlines: 2", CommentCommand::NewLines(2))]
291295
#[case::incremental_lists("new_line", CommentCommand::NewLine)]
292296
#[case::incremental_lists("newline", CommentCommand::NewLine)]
297+
#[case::comment("comment: This is a user comment", CommentCommand::Comment("This is a user comment".into()))]
293298
fn command_formatting(#[case] input: &str, #[case] expected: CommentCommand) {
294299
let parsed: CommentCommand = input.parse().expect("deserialization failed");
295300
assert_eq!(parsed, expected);
@@ -301,6 +306,9 @@ mod tests {
301306
#[case::many_close_braces("}}}")]
302307
#[case::vim_command("vim: hi")]
303308
#[case::padded_vim_command("vim: hi")]
309+
#[case::double_slash("// This is a user comment")]
310+
#[case::double_slash_padded(" // This is a padded comment ")]
311+
#[case::comment_colon("comment: This is a user comment")]
304312
fn ignore_comments(#[case] comment: &str) {
305313
let input = format!("<!-- {comment} -->");
306314
Test::new(input).build();

0 commit comments

Comments
 (0)