Skip to content

Commit 8604e6e

Browse files
authored
Restore superscripts that are stripped by yaml parser in print js (#648)
* Restore superscripts that are stripped by yaml parser, orphan and widow tweaks, move medatadata box styles from specs to ecmarkup * Add prince documentation links, update PUBLISHING.md
1 parent 23aab7c commit 8604e6e

File tree

5 files changed

+125
-24
lines changed

5 files changed

+125
-24
lines changed

PUBLISHING.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ status: proposal
1111
stage: 3
1212
```
1313
14-
- If using the alternative copyright for a standard publication, `location` is also mandatory. For example:
14+
- You can also specify various boilerplate content (see the boilerplate/ directory) For example:
1515
1616
```yaml
1717
title: ECMAScript® Language Specification
@@ -34,6 +34,8 @@ boilerplate:
3434
location: https://262.ecma-international.org/16.0/
3535
```
3636

37+
## Build and print
38+
3739
To generate markup for use in PDF conversion, make sure to include the options `--assets`, `--assets-dir`, and `--printable`. If you have images and styles to include, make sure to move them into your assets directory before running `ecmarkup`. For example:
3840

3941
```shell
@@ -49,4 +51,4 @@ cd path/to/spec
4951
prince-books --script ./node_modules/ecmarkup/js/print.js out/index.html -o path/to/output.pdf
5052
```
5153

52-
This has been extensively tested with Prince 15. Earlier and later editions not guaranteed.
54+
This has been extensively tested with [Prince Books](https://www.princexml.com/books/), built off of Prince 15. Earlier and later editions not guaranteed. CSS rule-specific documentation available in css/print.css.

css/elements.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,23 @@ body.oldtoc {
289289
margin: 0 auto;
290290
}
291291

292+
#metadata-block {
293+
margin: 4em 0;
294+
padding: 10px;
295+
border: 1px solid #ee8421;
296+
}
297+
298+
#metadata-block h1 {
299+
font-size: 1.5em;
300+
margin-top: 0;
301+
}
302+
303+
#metadata-block > ul {
304+
list-style-type: none;
305+
margin: 0;
306+
padding: 0;
307+
}
308+
292309
span[aria-hidden='true'] {
293310
font-size: 0;
294311
white-space: pre;
@@ -1627,4 +1644,5 @@ emu-normative-optional,
16271644

16281645
#ecma-logo {
16291646
background: var(--figure-background);
1647+
width: 500px;
16301648
}

css/print.css

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969

7070
:root {
7171
--page-number-style: decimal;
72+
-prince-change-line-breaks-for-pagination: yes; /* see https://www.princexml.com/doc/prince-for-books/#pagination-fine-tuning */
7273
}
7374

7475
@page {
@@ -77,16 +78,16 @@
7778
margin-bottom: 20mm;
7879
margin-inside: 19mm;
7980
margin-outside: 13mm;
80-
-prince-page-fill: prefer-fill;
81+
-prince-page-fill: prefer-balance; /* see https://www.princexml.com/doc/prince-for-books/#the-property--prince-page-fill */
8182

82-
/* Uncomment when producing WIP versions of final standards */
83+
/* Uncomment when producing WIP versions of final standards, see https://www.princexml.com/doc/paged/#page-regions */
8384
/*
8485
@prince-overlay {
8586
color: rgba(0,0,0,0.15);
86-
content: "WORK IN PROGRESS";
87+
content: "DRAFT";
8788
font-family: Arial;
8889
font-weight: bolder;
89-
font-size: 100pt;
90+
font-size: 200pt;
9091
transform: rotate(-60deg);
9192
}
9293
*/
@@ -196,7 +197,7 @@ body {
196197
line-height: 1.15;
197198
}
198199

199-
h1, h2, h3, h4, h5, h6 { -prince-bookmark-level: none }
200+
h1, h2, h3, h4, h5, h6 { -prince-bookmark-level: none } /* see https://www.princexml.com/doc/prince-output/#pdf-bookmarks */
200201

201202
.copyright-notice + h1.title {
202203
break-before: recto;
@@ -216,15 +217,24 @@ p {
216217
text-wrap: pretty;
217218
overflow-wrap: break-word;
218219
hyphens: auto;
219-
orphans: 2;
220-
widows: 2;
220+
orphans: 2, -prince-prefer 3; /* see https://www.princexml.com/doc/prince-for-books/#pagination-goals */
221+
widows: 2, -prince-prefer 3;
221222
}
222223

223224
h1 {
224225
text-wrap: balance;
225226
line-height: 1.4;
226227
}
227228

229+
pre:has(> code) {
230+
margin: 0;
231+
}
232+
233+
p + pre:has(+ p) {
234+
padding-top: 0;
235+
padding-bottom: 0;
236+
}
237+
228238
emu-alg {
229239
display: block; /* Can't render block elements inside inline elements. */
230240
}
@@ -263,6 +273,10 @@ emu-alg ol li:last-child {
263273
break-after: initial; /* it's okay to break after the last item in a list, even if it's also the first item in the list */
264274
}
265275

276+
emu-normative-optional {
277+
break-inside: avoid;
278+
}
279+
266280
emu-normative-optional emu-clause[id] {
267281
margin-top: 0;
268282
}
@@ -281,6 +295,10 @@ emu-note .note {
281295
min-width: 4.5em;
282296
}
283297

298+
emu-note table td {
299+
background-color: white;
300+
}
301+
284302
emu-note p,
285303
emu-table td p {
286304
text-align: left;
@@ -309,7 +327,6 @@ emu-intro, emu-clause, emu-annex {
309327
}
310328

311329
emu-clause p:first-of-type {
312-
margin-bottom: 0;
313330
orphans: 3;
314331
}
315332

@@ -429,7 +446,7 @@ caption, table > figcaption {
429446
}
430447

431448
caption {
432-
-prince-caption-page: first;
449+
-prince-caption-page: first; /* see https://www.princexml.com/doc/css-props/#prop-prince-caption-page */
433450
}
434451

435452
/* do not break inside of small tables */
@@ -470,6 +487,11 @@ emu-figure img {
470487
height: auto;
471488
}
472489

490+
.attributes-tag {
491+
break-before: avoid-page;
492+
break-after: avoid-page;
493+
}
494+
473495
#spec-container {
474496
max-width: initial;
475497
}
@@ -565,8 +587,8 @@ emu-annex > h1 .secnum {
565587
border: 1px solid black;
566588
padding: 1em;
567589
page: copyright;
568-
page-break-before: always;
569-
page-break-after: always;
590+
break-before: page;
591+
break-after: page;
570592
}
571593

572594
.secnum {

js/print.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313
const shortname = document.querySelector('h1.shortname');
1414
const version = document.querySelector('h1.version');
15+
const title = document.querySelector('h1.title');
16+
17+
shortname.innerHTML = restoreSuperScripts(shortname.innerHTML);
18+
version.innerHTML = restoreSuperScripts(version.innerHTML);
19+
title.innerHTML = restoreSuperScripts(title.innerHTML);
1520

1621
rearrangeTables();
1722

@@ -22,6 +27,20 @@ PDF.title = document.title;
2227
PDF.author = 'Ecma International';
2328
PDF.subject = shortname.innerHTML + (version ? ', ' + version.innerHTML : '');
2429

30+
function restoreSuperScripts(string) {
31+
if (!string) return false;
32+
33+
return string
34+
.replace(/(\d)st/, '$1<sup>st</sup>')
35+
.replace(/(\d)nd/, '$1<sup>nd</sup>')
36+
.replace(/(\d)rd/, '$1<sup>rd</sup>')
37+
.replace(/(\d)th/, '$1<sup>th</sup>')
38+
.replace('&reg;', '<sup>&reg;</sup>')
39+
.replace('®', '<sup>®</sup>')
40+
.replace('&trade;', '<sup>&trade;</sup>')
41+
.replace('™', '<sup>™</sup>');
42+
}
43+
2544
/**
2645
* Sets up table captions and figcaptions for tables, which provides for
2746
* continuation table captions.

test/baselines/generated-reference/assets-inline.html

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,23 @@
19061906
margin: 0 auto;
19071907
}
19081908
1909+
#metadata-block {
1910+
margin: 4em 0;
1911+
padding: 10px;
1912+
border: 1px solid #ee8421;
1913+
}
1914+
1915+
#metadata-block h1 {
1916+
font-size: 1.5em;
1917+
margin-top: 0;
1918+
}
1919+
1920+
#metadata-block > ul {
1921+
list-style-type: none;
1922+
margin: 0;
1923+
padding: 0;
1924+
}
1925+
19091926
span[aria-hidden='true'] {
19101927
font-size: 0;
19111928
white-space: pre;
@@ -3244,6 +3261,7 @@
32443261
32453262
#ecma-logo {
32463263
background: var(--figure-background);
3264+
width: 500px;
32473265
}
32483266
</style><style>@media print {
32493267
@font-face {
@@ -3317,6 +3335,7 @@
33173335
33183336
:root {
33193337
--page-number-style: decimal;
3338+
-prince-change-line-breaks-for-pagination: yes; /* see https://www.princexml.com/doc/prince-for-books/#pagination-fine-tuning */
33203339
}
33213340
33223341
@page {
@@ -3325,16 +3344,16 @@
33253344
margin-bottom: 20mm;
33263345
margin-inside: 19mm;
33273346
margin-outside: 13mm;
3328-
-prince-page-fill: prefer-fill;
3347+
-prince-page-fill: prefer-balance; /* see https://www.princexml.com/doc/prince-for-books/#the-property--prince-page-fill */
33293348
3330-
/* Uncomment when producing WIP versions of final standards */
3349+
/* Uncomment when producing WIP versions of final standards, see https://www.princexml.com/doc/paged/#page-regions */
33313350
/*
33323351
@prince-overlay {
33333352
color: rgba(0,0,0,0.15);
3334-
content: "WORK IN PROGRESS";
3353+
content: "DRAFT";
33353354
font-family: Arial;
33363355
font-weight: bolder;
3337-
font-size: 100pt;
3356+
font-size: 200pt;
33383357
transform: rotate(-60deg);
33393358
}
33403359
*/
@@ -3444,7 +3463,7 @@
34443463
line-height: 1.15;
34453464
}
34463465
3447-
h1, h2, h3, h4, h5, h6 { -prince-bookmark-level: none }
3466+
h1, h2, h3, h4, h5, h6 { -prince-bookmark-level: none } /* see https://www.princexml.com/doc/prince-output/#pdf-bookmarks */
34483467
34493468
.copyright-notice + h1.title {
34503469
break-before: recto;
@@ -3464,15 +3483,24 @@
34643483
text-wrap: pretty;
34653484
overflow-wrap: break-word;
34663485
hyphens: auto;
3467-
orphans: 2;
3468-
widows: 2;
3486+
orphans: 2, -prince-prefer 3; /* see https://www.princexml.com/doc/prince-for-books/#pagination-goals */
3487+
widows: 2, -prince-prefer 3;
34693488
}
34703489
34713490
h1 {
34723491
text-wrap: balance;
34733492
line-height: 1.4;
34743493
}
34753494
3495+
pre:has(> code) {
3496+
margin: 0;
3497+
}
3498+
3499+
p + pre:has(+ p) {
3500+
padding-top: 0;
3501+
padding-bottom: 0;
3502+
}
3503+
34763504
emu-alg {
34773505
display: block; /* Can't render block elements inside inline elements. */
34783506
}
@@ -3511,6 +3539,10 @@
35113539
break-after: initial; /* it's okay to break after the last item in a list, even if it's also the first item in the list */
35123540
}
35133541
3542+
emu-normative-optional {
3543+
break-inside: avoid;
3544+
}
3545+
35143546
emu-normative-optional emu-clause[id] {
35153547
margin-top: 0;
35163548
}
@@ -3529,6 +3561,10 @@
35293561
min-width: 4.5em;
35303562
}
35313563
3564+
emu-note table td {
3565+
background-color: white;
3566+
}
3567+
35323568
emu-note p,
35333569
emu-table td p {
35343570
text-align: left;
@@ -3557,7 +3593,6 @@
35573593
}
35583594
35593595
emu-clause p:first-of-type {
3560-
margin-bottom: 0;
35613596
orphans: 3;
35623597
}
35633598
@@ -3677,7 +3712,7 @@
36773712
}
36783713
36793714
caption {
3680-
-prince-caption-page: first;
3715+
-prince-caption-page: first; /* see https://www.princexml.com/doc/css-props/#prop-prince-caption-page */
36813716
}
36823717
36833718
/* do not break inside of small tables */
@@ -3718,6 +3753,11 @@
37183753
height: auto;
37193754
}
37203755
3756+
.attributes-tag {
3757+
break-before: avoid-page;
3758+
break-after: avoid-page;
3759+
}
3760+
37213761
#spec-container {
37223762
max-width: initial;
37233763
}
@@ -3813,8 +3853,8 @@
38133853
border: 1px solid black;
38143854
padding: 1em;
38153855
page: copyright;
3816-
page-break-before: always;
3817-
page-break-after: always;
3856+
break-before: page;
3857+
break-after: page;
38183858
}
38193859
38203860
.secnum {

0 commit comments

Comments
 (0)