fix(html): remove non-standard meta tag date

This commit is contained in:
Chance Addis 2025-04-04 07:32:14 -07:00
parent b8d1c7cf87
commit 6e20a4c47c
17 changed files with 7 additions and 53 deletions

View File

@ -6,11 +6,9 @@ pub use self::encode::html;
use comemo::{Track, Tracked, TrackedMut}; use comemo::{Track, Tracked, TrackedMut};
pub use ecow::EcoVec; pub use ecow::EcoVec;
use typst_library::diag::{bail, warning, At, SourceDiagnostic, SourceResult, StrResult}; use typst_library::diag::{bail, warning, At, SourceResult};
use typst_library::engine::{Engine, Route, Sink, Traced}; use typst_library::engine::{Engine, Route, Sink, Traced};
use typst_library::foundations::{ use typst_library::foundations::{Content, StyleChain, Target, TargetElem};
Content, Datetime, Smart, StyleChain, Target, TargetElem,
};
use typst_library::html::{ use typst_library::html::{
attr, tag, FrameElem, HtmlDocument, HtmlElem, HtmlElement, HtmlNode, attr, tag, FrameElem, HtmlDocument, HtmlElem, HtmlElement, HtmlNode,
}; };
@ -87,7 +85,7 @@ fn html_document_impl(
let output = handle_list(&mut engine, &mut locator, children.iter().copied())?; let output = handle_list(&mut engine, &mut locator, children.iter().copied())?;
let introspector = Introspector::html(&output); let introspector = Introspector::html(&output);
let root = root_element(&mut engine, output, &info)?; let root = root_element(output, &info)?;
Ok(HtmlDocument { info, root, introspector }) Ok(HtmlDocument { info, root, introspector })
} }
@ -265,14 +263,8 @@ fn handle(
/// Wrap the nodes in `<html>` and `<body>` if they are not yet rooted, /// Wrap the nodes in `<html>` and `<body>` if they are not yet rooted,
/// supplying a suitable `<head>`. /// supplying a suitable `<head>`.
fn root_element( fn root_element(output: Vec<HtmlNode>, info: &DocumentInfo) -> SourceResult<HtmlElement> {
engine: &mut Engine, let head = head_element(info);
output: Vec<HtmlNode>,
info: &DocumentInfo,
) -> SourceResult<HtmlElement> {
let head = head_element(engine, info).map_err(|err| {
EcoVec::from([SourceDiagnostic::warning(Span::detached(), err)])
})?;
let body = match classify_output(output)? { let body = match classify_output(output)? {
OutputKind::Html(element) => return Ok(element), OutputKind::Html(element) => return Ok(element),
OutputKind::Body(body) => body, OutputKind::Body(body) => body,
@ -282,7 +274,7 @@ fn root_element(
} }
/// Generate a `<head>` element. /// Generate a `<head>` element.
fn head_element(engine: &mut Engine, info: &DocumentInfo) -> StrResult<HtmlElement> { fn head_element(info: &DocumentInfo) -> HtmlElement {
let mut children = vec![]; let mut children = vec![];
children.push(HtmlElement::new(tag::meta).with_attr(attr::charset, "utf-8").into()); children.push(HtmlElement::new(tag::meta).with_attr(attr::charset, "utf-8").into());
@ -329,29 +321,7 @@ fn head_element(engine: &mut Engine, info: &DocumentInfo) -> StrResult<HtmlEleme
) )
} }
match info.date { HtmlElement::new(tag::head).with_children(children)
Smart::Auto => children.push(
HtmlElement::new(tag::meta)
.with_attr(attr::name, "date")
.with_attr(
attr::content,
Datetime::today(engine, Smart::Auto)?.display(Smart::Auto)?,
)
.into(),
),
Smart::Custom(optional_date) => {
if let Some(date) = optional_date {
children.push(
HtmlElement::new(tag::meta)
.with_attr(attr::name, "date")
.with_attr(attr::content, date.display(Smart::Auto).unwrap())
.into(),
)
}
}
}
Ok(HtmlElement::new(tag::head).with_children(children))
} }
/// Determine which kind of output the user generated. /// Determine which kind of output the user generated.

View File

@ -3,7 +3,6 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="date" content="1970-01-01">
</head> </head>
<body> <body>
<table> <table>

View File

@ -3,7 +3,6 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="date" content="1970-01-01">
</head> </head>
<body> <body>
<p>Paragraph</p> <p>Paragraph</p>

View File

@ -3,7 +3,6 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="date" content="1970-01-01">
</head> </head>
<body> <body>
<p>Text <span style="display: inline-block;">Span</span>.</p> <p>Text <span style="display: inline-block;">Span</span>.</p>

View File

@ -3,7 +3,6 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="date" content="1970-01-01">
</head> </head>
<body> <body>
<table> <table>

View File

@ -3,7 +3,6 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="date" content="1970-01-01">
</head> </head>
<body> <body>
<table> <table>

View File

@ -3,7 +3,6 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="date" content="1970-01-01">
</head> </head>
<body> <body>
<div> <div>

View File

@ -3,7 +3,6 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="date" content="1970-01-01">
</head> </head>
<body> <body>
<ol start="3"> <ol start="3">

View File

@ -3,7 +3,6 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="date" content="1970-01-01">
</head> </head>
<body> <body>
<h2>Level 1</h2> <h2>Level 1</h2>

View File

@ -3,7 +3,6 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="date" content="1970-01-01">
</head> </head>
<body> <body>
<p><a href="https://example.com/">https://example.com/</a></p> <p><a href="https://example.com/">https://example.com/</a></p>

View File

@ -3,7 +3,6 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="date" content="1970-01-01">
</head> </head>
<body> <body>
<div> <div>

View File

@ -3,7 +3,6 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="date" content="1970-01-01">
</head> </head>
<body> <body>
<h2>Heading is no paragraph</h2> <h2>Heading is no paragraph</h2>

View File

@ -3,7 +3,6 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="date" content="1970-01-01">
</head> </head>
<body> <body>
<blockquote cite="https://typst.app/home">Compose papers faster</blockquote> <blockquote cite="https://typst.app/home">Compose papers faster</blockquote>

View File

@ -3,7 +3,6 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="date" content="1970-01-01">
</head> </head>
<body> <body>
<p>When you said that “he surely meant that she intended to say “I'm sorry””, I was quite confused.</p> <p>When you said that “he surely meant that she intended to say “I'm sorry””, I was quite confused.</p>

View File

@ -3,7 +3,6 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="date" content="1970-01-01">
</head> </head>
<body> <body>
<blockquote>… ἔοικα γοῦν τούτου γε σμικρῷ τινι αὐτῷ τούτῳ σοφώτερος εἶναι, ὅτι ἃ μὴ οἶδα οὐδὲ οἴομαι εἰδέναι.</blockquote> <blockquote>… ἔοικα γοῦν τούτου γε σμικρῷ τινι αὐτῷ τούτῳ σοφώτερος εἶναι, ὅτι ἃ μὴ οἶδα οὐδὲ οἴομαι εἰδέναι.</blockquote>

View File

@ -3,7 +3,6 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="date" content="1970-01-01">
</head> </head>
<body> <body>
<table> <table>

View File

@ -3,7 +3,6 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="date" content="1970-01-01">
</head> </head>
<body> <body>
<div> <div>