From 800744ed9d3923eecf3436f2029e77033e8f1b6a Mon Sep 17 00:00:00 2001 From: Mathias Fischler Date: Mon, 7 Aug 2023 13:47:29 +0200 Subject: [PATCH] Show warning to user if they use double/empty underscores (italic) (#1871) --- crates/typst/src/eval/mod.rs | 13 ++++++++++++- tests/typ/lint/markup.typ | 13 +++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/crates/typst/src/eval/mod.rs b/crates/typst/src/eval/mod.rs index 770d9fd1c..544f04f07 100644 --- a/crates/typst/src/eval/mod.rs +++ b/crates/typst/src/eval/mod.rs @@ -600,7 +600,18 @@ impl Eval for ast::Emph { #[tracing::instrument(name = "Emph::eval", skip_all)] fn eval(&self, vm: &mut Vm) -> SourceResult { - Ok((vm.items.emph)(self.body().eval(vm)?)) + let body = self.body(); + if body.exprs().next().is_none() { + vm.vt + .tracer + .warn(warning!(self.span(), "no text within underscores").with_hint( + EcoString::from( + "using multiple consecutive underscores (e.g. __) has no additional effect", + ), + )); + } + + Ok((vm.items.emph)(body.eval(vm)?)) } } diff --git a/tests/typ/lint/markup.typ b/tests/typ/lint/markup.typ index 1cb446589..319fec119 100644 --- a/tests/typ/lint/markup.typ +++ b/tests/typ/lint/markup.typ @@ -5,9 +5,22 @@ // Warning: 1-3 no text within stars // Hint: 1-3 using multiple consecutive stars (e.g. **) has no additional effect ** + --- // Warning: 1-3 no text within stars // Hint: 1-3 using multiple consecutive stars (e.g. **) has no additional effect // Warning: 11-13 no text within stars // Hint: 11-13 using multiple consecutive stars (e.g. **) has no additional effect **not bold** + +--- +// Warning: 1-3 no text within underscores +// Hint: 1-3 using multiple consecutive underscores (e.g. __) has no additional effect +__ + +--- +// Warning: 1-3 no text within underscores +// Hint: 1-3 using multiple consecutive underscores (e.g. __) has no additional effect +// Warning: 13-15 no text within underscores +// Hint: 13-15 using multiple consecutive underscores (e.g. __) has no additional effect +__not italic__