diff --git a/css/print.css b/css/print.css index f67a6e23..f5b33391 100644 --- a/css/print.css +++ b/css/print.css @@ -252,7 +252,7 @@ emu-table td, pre, h1, emu-production, -emu-figure:has(> figure > img) figure, +emu-figure, #metadata-block { break-inside: avoid; border: unset; @@ -429,7 +429,7 @@ caption, table > figcaption { caption-side: top; color: #000; font-weight: bold; - margin-bottom: 1rem; + margin-bottom: 0.5lh; text-align: center; } @@ -442,6 +442,14 @@ table:not(:has(tr:nth-of-type(5))) { break-inside: avoid-page; } +table tr:first-of-type, table tr:nth-of-type(2) { + break-after: avoid; +} + +table tr:last-of-type { + break-before: avoid; +} + /* This inheritance looks weird—it's due to how Prince manages continuity in tables across pages */ table > figcaption { display: table-caption; @@ -476,6 +484,16 @@ emu-figure img { height: auto; } +figure figcaption { + color: var(--black); + text-align: center; +} + +emu-figure figcaption, +emu-table figcaption { + margin-bottom: 0.5lh; +} + .attributes-tag { break-before: avoid-page; break-after: avoid-page; diff --git a/src/Clause.ts b/src/Clause.ts index 526c3342..ac4f4614 100644 --- a/src/Clause.ts +++ b/src/Clause.ts @@ -82,6 +82,13 @@ export default class Clause extends Builder { parentNamespace = parent.namespace; } + // Reset figure numbering for each Annex + if (this.isAnnex && !this.parentClause) { + spec._figureCounts.figure = 0; + spec._figureCounts.table = 0; + spec._figurePrefix = `${number}.`; + } + if (node.hasAttribute('namespace')) { this.namespace = node.getAttribute('namespace')!; spec.biblio.createNamespace(this.namespace, parentNamespace); diff --git a/src/Figure.ts b/src/Figure.ts index eba0f4a4..e794c996 100644 --- a/src/Figure.ts +++ b/src/Figure.ts @@ -21,16 +21,16 @@ export default class Figure extends Builder { this.isInformative = node.hasAttribute('informative'); this.captionElem = node.querySelector('emu-caption'); - this.caption = this.type.charAt(0).toUpperCase() + this.type.slice(1) + ' ' + this.number; + this.caption = `${this.type.charAt(0).toUpperCase()}${this.type.slice(1)} ${spec._figurePrefix}${this.number}`; if (this.isInformative) { this.caption += ' (Informative)'; } if (this.captionElem) { - this.caption += ': ' + this.captionElem.innerHTML; + this.caption += ' \u2014 ' + this.captionElem.innerHTML; } else if (node.getAttribute('caption')) { - this.caption += ': ' + node.getAttribute('caption'); + this.caption += ' \u2014 ' + node.getAttribute('caption'); } if (this.id) { @@ -56,6 +56,11 @@ export default class Figure extends Builder { const captionElem = spec.doc.createElement('figcaption'); captionElem.innerHTML = figure.caption; - node.childNodes[0].insertBefore(captionElem, node.childNodes[0].firstChild); + + if (node.nodeName.split('-')[1] === 'FIGURE') { + node.firstElementChild?.appendChild(captionElem); + } else { + node.childNodes[0].insertBefore(captionElem, node.childNodes[0].firstChild); + } } } diff --git a/src/Spec.ts b/src/Spec.ts index 52de1f36..994b2ffc 100644 --- a/src/Spec.ts +++ b/src/Spec.ts @@ -319,6 +319,7 @@ export default class Spec { readonly log: (msg: string) => void; readonly warn: (err: Warning) => void | undefined; + /** @internal */ _figurePrefix: string; /** @internal */ _figureCounts: { [type: string]: number }; /** @internal */ _xrefs: Xref[]; /** @internal */ _ntRefs: NonTerminal[]; @@ -371,6 +372,7 @@ export default class Spec { table: 0, figure: 0, }; + this._figurePrefix = ''; this._xrefs = []; this._ntRefs = []; this._ntStringRefs = []; diff --git a/test/baselines/generated-reference/assets-inline.html b/test/baselines/generated-reference/assets-inline.html index 38847291..fedb739b 100644 --- a/test/baselines/generated-reference/assets-inline.html +++ b/test/baselines/generated-reference/assets-inline.html @@ -3504,7 +3504,7 @@ pre, h1, emu-production, -emu-figure:has(> figure > img) figure, +emu-figure, #metadata-block { break-inside: avoid; border: unset; @@ -3681,7 +3681,7 @@ caption-side: top; color: #000; font-weight: bold; - margin-bottom: 1rem; + margin-bottom: 0.5lh; text-align: center; } @@ -3694,6 +3694,14 @@ break-inside: avoid-page; } +table tr:first-of-type, table tr:nth-of-type(2) { + break-after: avoid; +} + +table tr:last-of-type { + break-before: avoid; +} + /* This inheritance looks weird—it's due to how Prince manages continuity in tables across pages */ table > figcaption { display: table-caption; @@ -3728,6 +3736,16 @@ height: auto; } +figure figcaption { + color: var(--black); + text-align: center; +} + +emu-figure figcaption, +emu-table figcaption { + margin-bottom: 0.5lh; +} + .attributes-tag { break-before: avoid-page; break-after: avoid-page; diff --git a/test/baselines/generated-reference/duplicate-ids.html b/test/baselines/generated-reference/duplicate-ids.html index 6134cdf9..6d3c364d 100644 --- a/test/baselines/generated-reference/duplicate-ids.html +++ b/test/baselines/generated-reference/duplicate-ids.html @@ -24,7 +24,7 @@

1.1 Sub A

2 Section A: Extras

-
Table 1 (Informative): A Table Of Stuff
+
Table 1 (Informative) — A Table Of Stuff
@@ -35,7 +35,7 @@

2 Section A: Extras

3 Section A: Extras

-
Table 2 (Informative): A Table Of Stuff
+
Table 2 (Informative) — A Table Of Stuff
Column 1Column 2
ValueValue 2
diff --git a/test/baselines/generated-reference/figure.html b/test/baselines/generated-reference/figure.html index 2c1e9de6..2264d03d 100644 --- a/test/baselines/generated-reference/figure.html +++ b/test/baselines/generated-reference/figure.html @@ -11,16 +11,16 @@
  • Jump to the most recent link target`
  • -
    Figure 1
    +
    this is a figure! -
    +
    Figure 1
    -
    Figure 2 (Informative): Informative figure
    +
    this is a figure! -
    +
    Figure 2 (Informative) — Informative figure
    -
    Table 1: An example table
    +
    Table 1 — An example table
    Column 1Column 2
    ValueValue 2
    @@ -32,7 +32,7 @@
    Column 1Column 2
    -
    Table 2 (Informative): An example table 2
    +
    Table 2 (Informative) — An example table 2
    @@ -42,12 +42,12 @@
    Column 1Column 2
    ValueValue 2
    -
    Figure 3 (Informative): This is the caption
    +
    this is a figure! -
    +
    Figure 3 (Informative) — This is the caption
    -
    Table 3: This is a table
    +
    Table 3 — This is a table
    @@ -60,7 +60,7 @@
    -
    Table 4 (Informative): This is a second table
    +
    Table 4 (Informative) — This is a second table
    diff --git a/test/baselines/generated-reference/xref.html b/test/baselines/generated-reference/xref.html index fabc8377..059d2d24 100644 --- a/test/baselines/generated-reference/xref.html +++ b/test/baselines/generated-reference/xref.html @@ -94,11 +94,11 @@

    1.1 AbstractOp

    And a third!

    -
    Figure 1
    +
    this is a figure! -
    +
    Figure 1
    -
    Table 1: An example table
    +
    Table 1 — An example table
    Column 1Column 2
    Column 1Column 2