Skip to content

Commit d2ff8c7

Browse files
committed
engine_spx2html: use <div class="tdux-p"> instead of <p>
This might seem bonkers, but using the <p> tag to group paragraphs actually introduces some real problems. You can't put things like <ul> or <div> inside <p> tags -- they automatically close them. That's not compatible with TeX's model of how paragraphs work, since they might contain things like math displays or lists. As the HTML spec emphasizes, the <p> tag does not carry special semantics, so it's OK not to use it. In fact, the spec recommends using <div> tags if you do want to demarcate semantic paragraphs.
1 parent ce1e76e commit d2ff8c7

2 files changed

Lines changed: 20 additions & 15 deletions

File tree

crates/engine_spx2html/src/lib.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -844,11 +844,9 @@ impl EmittingState {
844844
}
845845
}
846846

847-
fn push_elem(&mut self, name: &str, origin: ElementOrigin, common: &mut Common) {
847+
fn push_elem(&mut self, el: Element, origin: ElementOrigin) {
848848
self.close_automatics();
849849

850-
let el = self.create_elem(name, true, common);
851-
852850
let new_item = {
853851
let cur = self.cur_elstate();
854852

@@ -981,23 +979,30 @@ impl EmittingState {
981979
contents: &str,
982980
common: &mut Common,
983981
) -> Result<()> {
984-
if let Some(element) = contents.strip_prefix("tdux:as ") {
982+
if contents == "tdux:asp" {
985983
if self.content_finished {
986-
self.warn_finished_content(&format!("auto start tag <{}>", element), common);
984+
self.warn_finished_content("auto start paragraph", common);
987985
} else if self.cur_elstate().do_auto_tags {
988-
let el = self.create_elem(element, true, common);
986+
// Why are we using <div>s instead of <p>? As the HTML spec
987+
// emphasizes, <p> tags are structural, not semantic. You cannot
988+
// put tags like <ul> or <div> inside <p> -- they automatically
989+
// close the paragraph. This does not align with TeX's idea of a
990+
// paragraph, and there's no upside to trying to use <p>'s -- as
991+
// the spec notes, the <p> tag does not activate any important
992+
// semantics itself. The HTML spec explicitly recommends that
993+
// you can use <div> elements to group logical paragraphs. So
994+
// that's what we do.
995+
let el = self.create_elem("div", true, common);
989996
self.push_space_if_needed(x, None);
990-
self.current_content.push('<');
991-
self.current_content.push_str(el.name());
992-
self.current_content.push('>');
993-
self.push_elem(element, ElementOrigin::EngineAuto, common);
997+
self.current_content.push_str("<div class=\"tdux-p\">");
998+
self.push_elem(el, ElementOrigin::EngineAuto);
994999
}
9951000
Ok(())
996-
} else if let Some(element) = contents.strip_prefix("tdux:ae ") {
1001+
} else if contents == "tdux:aep" {
9971002
if self.content_finished {
998-
self.warn_finished_content(&format!("auto end tag </{}>", element), common);
1003+
self.warn_finished_content("auto end paragraph", common);
9991004
} else if self.cur_elstate().do_auto_tags {
1000-
self.pop_elem(element, common);
1005+
self.pop_elem("div", common);
10011006
}
10021007
Ok(())
10031008
} else if let Some(kind) = contents.strip_prefix("tdux:cs ") {

crates/engine_xetex/xetex/xetex-xetex0.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14791,7 +14791,7 @@ new_graf(bool indented)
1479114791

1479214792
/* Tectonic customization: insert <p> flagged as automatic */
1479314793
if (semantic_pagination_enabled)
14794-
tt_insert_special("tdux:as p");
14794+
tt_insert_special("tdux:asp");
1479514795

1479614796
if (LOCAL(every_par) != TEX_NULL)
1479714797
begin_token_list(LOCAL(every_par), EVERY_PAR_TEXT);
@@ -14857,7 +14857,7 @@ end_graf(void)
1485714857
if (cur_list.mode == HMODE) {
1485814858
/* Tectonic customization: insert </p> flagged as automatic */
1485914859
if (semantic_pagination_enabled)
14860-
tt_insert_special("tdux:ae p");
14860+
tt_insert_special("tdux:aep");
1486114861

1486214862
if (cur_list.head == cur_list.tail)
1486314863
pop_nest();

0 commit comments

Comments
 (0)