-
-
Notifications
You must be signed in to change notification settings - Fork 170
feat: add support for user comments in presentation rendering #773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,8 @@ impl PresentationBuilder<'_, '_> { | |
| 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; | ||
| return Ok(()); | ||
| } | ||
|
Comment on lines
18
to
22
|
||
| return Err(self.invalid_presentation(source_position, error)); | ||
|
|
@@ -42,6 +44,7 @@ impl PresentationBuilder<'_, '_> { | |
| CommentCommand::NewLines(count) => { | ||
| self.push_line_breaks(count as usize * self.slide_font_size() as usize); | ||
| } | ||
| CommentCommand::Comment(_) => {} | ||
| CommentCommand::JumpToMiddle => self.chunk_operations.push(RenderOperation::JumpToVerticalCenter), | ||
| CommentCommand::InitColumnLayout(columns) => { | ||
| self.validate_column_layout(&columns, source_position)?; | ||
|
|
@@ -149,7 +152,7 @@ impl PresentationBuilder<'_, '_> { | |
| } else { | ||
| // Ignore vim-like code folding tags | ||
| let comment = comment.trim(); | ||
| comment == "{{{" || comment == "}}}" | ||
| comment == "{{{" || comment == "}}}" || comment.starts_with("//") | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -205,6 +208,7 @@ pub(crate) enum CommentCommand { | |
| SkipSlide, | ||
| SpeakerNote(String), | ||
| SnippetOutput(String), | ||
| Comment(String), | ||
| } | ||
|
Comment on lines
208
to
212
|
||
|
|
||
| impl CommentCommand { | ||
|
|
@@ -290,6 +294,7 @@ mod tests { | |
| #[case::incremental_lists("newlines: 2", CommentCommand::NewLines(2))] | ||
| #[case::incremental_lists("new_line", CommentCommand::NewLine)] | ||
| #[case::incremental_lists("newline", CommentCommand::NewLine)] | ||
| #[case::comment("comment: This is a user comment", CommentCommand::Comment("This is a user comment".into()))] | ||
| fn command_formatting(#[case] input: &str, #[case] expected: CommentCommand) { | ||
| let parsed: CommentCommand = input.parse().expect("deserialization failed"); | ||
| assert_eq!(parsed, expected); | ||
|
|
@@ -301,6 +306,9 @@ mod tests { | |
| #[case::many_close_braces("}}}")] | ||
| #[case::vim_command("vim: hi")] | ||
| #[case::padded_vim_command("vim: hi")] | ||
| #[case::double_slash("// This is a user comment")] | ||
| #[case::double_slash_padded(" // This is a padded comment ")] | ||
| #[case::comment_colon("comment: This is a user comment")] | ||
| fn ignore_comments(#[case] comment: &str) { | ||
| let input = format!("<!-- {comment} -->"); | ||
| Test::new(input).build(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With
command_prefixconfigured, 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 toshould_ignore_commentwhen parsing fails. This contradicts the documented behavior ofcommand_prefix(docs/src/configuration/options.md). Consider enforcing the prefix before attempting to parse (or update docs/tests to reflect the intended semantics).