mirror of
https://github.com/typst/typst
synced 2025-06-24 14:22:51 +08:00
Consistent codepoint formatting in HTML and PDF error messages
This commit is contained in:
parent
e9dc4bb204
commit
fbb02f40d9
@ -165,7 +165,7 @@ fn write_escape(w: &mut Writer, c: char) -> StrResult<()> {
|
||||
c if charsets::is_w3c_text_char(c) && c != '\r' => {
|
||||
write!(w.buf, "&#x{:x};", c as u32).unwrap()
|
||||
}
|
||||
_ => bail!("the character {} cannot be encoded in HTML", c.repr()),
|
||||
_ => bail!("the character `{}` cannot be encoded in HTML", c.repr()),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ use krilla::surface::Surface;
|
||||
use krilla::{Document, SerializeSettings};
|
||||
use krilla_svg::render_svg_glyph;
|
||||
use typst_library::diag::{bail, error, SourceDiagnostic, SourceResult};
|
||||
use typst_library::foundations::NativeElement;
|
||||
use typst_library::foundations::{NativeElement, Repr};
|
||||
use typst_library::introspection::Location;
|
||||
use typst_library::layout::{
|
||||
Abs, Frame, FrameItem, GroupItem, PagedDocument, Size, Transform,
|
||||
@ -429,14 +429,18 @@ fn convert_error(
|
||||
display_font(gc.fonts_backward.get(f).unwrap());
|
||||
hint: "try using a different font"
|
||||
),
|
||||
ValidationError::InvalidCodepointMapping(_, _, cp, loc) => {
|
||||
if let Some(c) = cp.map(|c| eco_format!("{:#06x}", c as u32)) {
|
||||
ValidationError::InvalidCodepointMapping(_, _, c, loc) => {
|
||||
if let Some(c) = c {
|
||||
let msg = if loc.is_some() {
|
||||
"the PDF contains text with"
|
||||
} else {
|
||||
"the text contains"
|
||||
};
|
||||
error!(to_span(*loc), "{prefix} {msg} the disallowed codepoint {c}")
|
||||
error!(
|
||||
to_span(*loc),
|
||||
"{prefix} {msg} the disallowed codepoint `{}`",
|
||||
c.repr()
|
||||
)
|
||||
} else {
|
||||
// I think this code path is in theory unreachable,
|
||||
// but just to be safe.
|
||||
@ -454,13 +458,12 @@ fn convert_error(
|
||||
}
|
||||
}
|
||||
ValidationError::UnicodePrivateArea(_, _, c, loc) => {
|
||||
let code_point = eco_format!("{:#06x}", *c as u32);
|
||||
let msg = if loc.is_some() { "the PDF" } else { "the text" };
|
||||
error!(
|
||||
to_span(*loc),
|
||||
"{prefix} {msg} contains the codepoint {code_point}";
|
||||
"{prefix} {msg} contains the codepoint `{}`", c.repr();
|
||||
hint: "codepoints from the Unicode private area are \
|
||||
forbidden in this export mode"
|
||||
forbidden in this export mode",
|
||||
)
|
||||
}
|
||||
ValidationError::Transparency(loc) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user