Skip to content

Commit c28f581

Browse files
committed
post-process/hyphenate html output
- add soft hyphens to text - justify text on all browsers - use htmld and hyphenate libs w/ en-US pattern - run dpl-docs w/ hyphenation
1 parent 40da781 commit c28f581

File tree

10 files changed

+138
-35
lines changed

10 files changed

+138
-35
lines changed

css/style.css

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -506,17 +506,6 @@ body.std .subnav a.package
506506
text-align: justify;
507507
}
508508

509-
/* This is a CSS hack to only target Blink based browsers
510-
Targets Chrome 28 and later and Opera 14 and later
511-
*/
512-
@media all and (-webkit-min-device-pixel-ratio:0) and (min-resolution: .001dpcm) {
513-
#content
514-
{
515-
/* because Blink based browsers don't support hyphens */
516-
text-align: left;
517-
}
518-
}
519-
520509
.subnav + #content
521510
{
522511
margin-left: 19em;

dlang.org.ddoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ _=
4141

4242
CONSOLE=$(TC pre, console notranslate, $0)
4343
COPYRIGHT=Copyright © 1999-$(YEAR) by Digital Mars $(REG), All Rights Reserved
44-
CPPCODE=$(TC pre, cppcode notranslate, $0)
44+
CPPCODE=$(TC pre, cppcode donthyphenate notranslate, $0)
4545
CPPLISTING=$(CPPCODE $0)
4646
CROSS=✘
4747
_=
4848

4949
D=$(SPANC d_inlinecode donthyphenate notranslate, $0)
50-
D_CODE=$(TC pre, d_code notranslate, $0)
50+
D_CODE=$(TC pre, d_code donthyphenate notranslate, $0)
5151
_=
5252

5353
DDOC=
@@ -127,7 +127,7 @@ DDOC_PSYMBOL = $(ADEF $0)$(SPANC ddoc_psymbol, $0)
127127
DDOC_ANCHOR = $(ADEF .$1)$(DIVCID quickindex, quickindex.$1, )
128128
DDOC_DECL = $(TC dt, d_decl, $(DIV, $0))
129129
DDOC_UNDEFINED_MACRO = $(DDOC_COMMENT UNDEFINED MACRO: "$1")
130-
DDOCCODE=$(TC pre, ddoccode notranslate, $0)
130+
DDOCCODE=$(TC pre, ddoccode donthyphenate notranslate, $0)
131131
DDOCKEYVAL=$(DIVC keyval $1, $(SPANC key key$1, $1:) $(DIVC val val$1, $+))
132132
DDOCKEYVAL2=$(DIVC keyval $1, $(SPANC key key$1, $2:) $(DIVC val val$1, $(TAIL $+)))
133133
DDSUBLINK=$(LINK2 $(ROOT_DIR)$1.html#$2, $3)
@@ -160,7 +160,7 @@ GLINK2=$(DDSUBLINK spec/$1,$2,$(I $2))
160160
GLOSSARY = $(WEB dlang.org/glossary.html#$0, $0)
161161
GLOSSARY2 = $(WEB dlang.org/glossary.html#$1, $2)
162162
GNAME=<a id="$0">$(SPANC gname, $0)</a>
163-
GRAMMAR=$(TC pre, bnf notranslate, $0)
163+
GRAMMAR=$(TC pre, bnf donthyphenate notranslate, $0)
164164
GREEN=$(SPANC green, $0)
165165
GT=&gt;
166166
_=
@@ -198,7 +198,7 @@ MENU_W_SUBMENU_LINK = <li class='expand-container'><a class='expand-toggle' href
198198
MENU_W_SUBMENU_END = </li>
199199
META_KEYWORDS=D programming language
200200
META_DESCRIPTION=D Programming Language
201-
MODDEFFILE=$(TC pre, moddeffile notranslate, $0)
201+
MODDEFFILE=$(TC pre, moddeffile donthyphenate notranslate, $0)
202202
MULTICOL_CELL=<td colspan="$1">$+</td>
203203
MULTICOL_HEADER=<th colspan="$1">$+</th>
204204
MULTICOLS=$+
@@ -339,7 +339,7 @@ RELATIVE_LINK2=$(ALOCAL $1, $+)
339339
_=
340340

341341
SAMPLESRC=$(SPANC sample_src, $(AHTTPS github.com/D-Programming-Language/dmd/blob/master/samples/$0, /dmd/samples/d/$0))
342-
SCINI=$(TC pre, scini notranslate, $0)
342+
SCINI=$(TC pre, scini donthyphenate notranslate, $0)
343343
SCRIPTLOAD=<script type="text/javascript" src="$0"></script>
344344
SEARCHDEFAULT_PHOBOS=
345345
SEARCHDEFAULT_FORUM=

dpl-docs/dub.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "dpl-docs",
33
"dependencies": {
4-
"ddox": "~>0.12.0"
4+
"ddox": "~>0.12.1"
55
},
66
"versions": ["VibeCustomMain"]
77
}

dpl-docs/dub.selections.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
{
22
"fileVersion": 1,
33
"versions": {
4-
"ddox": "0.12.0",
4+
"ddox": "0.12.1",
55
"libevent": "2.0.1+2.0.16",
66
"libev": "5.0.0+4.04",
7-
"libhttp2": "0.2.6",
87
"openssl": "1.1.4+1.0.1g",
9-
"memutils": "0.4.1",
8+
"libdparse": "0.2.1",
9+
"memutils": "0.4.4",
1010
"vibe-d": "0.7.26",
1111
"backtrace-d": "~master",
12+
"hyphenate": "1.1.0",
1213
"libasync": "0.7.5",
13-
"libdparse": "0.2.1"
14+
"libhttp2": "0.2.6"
1415
}
1516
}

html-postprocessor/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
html-postprocessor
2+
.dub
3+
docs.json
4+
__dummy.html
5+
*.o
6+
*.obj

html-postprocessor/dub.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "html-postprocessor",
3+
"authors": ["Martin Nowak"],
4+
"dependencies": {
5+
"hyphenate": "~>1.1.0",
6+
"htmld": "~>0.2.12"
7+
}
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"fileVersion": 1,
3+
"versions": {
4+
"hyphenate": "1.1.1",
5+
"htmld": "0.2.13"
6+
}
7+
}

html-postprocessor/src/app.d

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import hyphenate;
2+
3+
/// global immutable instance initialized for en-US
4+
static immutable Hyphenator h;
5+
shared static this()
6+
{
7+
h = cast(immutable) Hyphenator(import("hyphen.tex"));
8+
}
9+
10+
/// hyphenate a HTML file
11+
void hyphenateHTML(string path)
12+
{
13+
import html : createDocument, Node, NodeWrapper;
14+
import std.algorithm : canFind, splitter;
15+
import std.array : appender, replace;
16+
import std.file : readText;
17+
import std.regex : ctRegex, replaceAllInto;
18+
19+
auto doc = createDocument(path.readText);
20+
21+
void visit(NodeWrapper!Node node, bool hyphenate)
22+
{
23+
enum wordsRE = ctRegex!("[\\w\&shy;]+", "g");
24+
if (node.isTextNode)
25+
{
26+
if (hyphenate)
27+
{
28+
auto app = appender!string;
29+
replaceAllInto!((m, app) {
30+
auto word = m.hit.replace("\&shy;", "");
31+
h.hyphenate(word, "\&shy;", s => app.put(s));
32+
})(app, node.text, wordsRE);
33+
node.text = app.data;
34+
}
35+
}
36+
else
37+
{
38+
if (node.tag == "script" || node.tag == "style")
39+
return;
40+
41+
if (node.attr("class").splitter.canFind("hyphenate"))
42+
hyphenate = true;
43+
else if (node.attr("class").splitter.canFind("donthyphenate"))
44+
hyphenate = false;
45+
46+
foreach (child; node.children)
47+
visit(child, hyphenate);
48+
}
49+
}
50+
51+
visit(doc.root, false);
52+
53+
import std.stdio : File;
54+
55+
with (File(path, "w"))
56+
{
57+
auto orng = lockingTextWriter;
58+
doc.root.innerHTML(orng);
59+
}
60+
}
61+
62+
void main(string[] args)
63+
{
64+
import std.parallelism : parallel;
65+
import std.file : readText;
66+
67+
foreach (path; args[1 .. $].parallel)
68+
hyphenateHTML(path);
69+
}

posix.mak

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ DOC_OUTPUT_DIR:=$(shell pwd)/web
2121
GIT_HOME=https://github.com/D-Programming-Language
2222
DPL_DOCS_PATH=dpl-docs
2323
DPL_DOCS=$(DPL_DOCS_PATH)/dpl-docs
24+
HTML_POSTPROCESSOR_PATH=html-postprocessor
25+
HTML_POSTPROCESSOR=$(HTML_POSTPROCESSOR_PATH)/html-postprocessor
2426
REMOTE_DIR=d-programming@digitalmars.com:data
2527
GENERATED=.generated
2628

@@ -232,7 +234,7 @@ $(DOC_OUTPUT_DIR)/dmd-%.verbatim : %.ddoc dcompiler.dd verbatim.ddoc $(DMD)
232234
# Rulez
233235
################################################################################
234236

235-
all : docs html
237+
all : docs html postprocess-html
236238

237239
docs : phobos-prerelease druntime-prerelease druntime-release phobos-release \
238240
apidocs-release apidocs-prerelease
@@ -245,6 +247,8 @@ kindle : ${DOC_OUTPUT_DIR}/dlangspec.mobi
245247

246248
pdf : ${DOC_OUTPUT_DIR}/dlangspec.pdf
247249

250+
postprocess-html : ${HTML_POSTPROCESSOR_PATH}/.done
251+
248252
$(DOC_OUTPUT_DIR)/sitemap.html : $(ALL_FILES_BUT_SITEMAP) $(DMD)
249253
cp -f sitemap-template.dd sitemap.dd
250254
(true $(foreach F, $(TARGETS), \
@@ -274,7 +278,7 @@ rebase-druntime: ; cd $(DRUNTIME_DIR) && $(call REBASE,druntime)
274278
rebase-phobos: ; cd $(PHOBOS_DIR) && $(call REBASE,phobos)
275279

276280
clean:
277-
rm -rf $(DOC_OUTPUT_DIR) ${GENERATED} dpl-docs/.dub
281+
rm -rf $(DOC_OUTPUT_DIR) ${GENERATED} ${DPL_DOCS_PATH}/.dub ${HTML_POSTPROCESSOR_PATH}/.done ${HTML_POSTPROCESSOR_PATH}/.dub
278282
rm -rf auto dlangspec-consolidated.d $(addprefix dlangspec,.aux .d .dvi .fdb_latexmk .fls .log .out .pdf .tex .txt .verbatim.txt)
279283
rm -f docs.json docs-prerelease.json dpl-docs/dpl-docs
280284
@echo You should issue manually: rm -rf ${DMD_DIR}-${LATEST} ${DRUNTIME_DIR}-${LATEST} ${PHOBOS_DIR}-${LATEST} ${STABLE_DMD_ROOT} ${DUB_DIR}
@@ -389,7 +393,7 @@ ${DOC_OUTPUT_DIR}/phobos-prerelease/object.verbatim : $(DMD)
389393
# phobos, latest released build and current build
390394
################################################################################
391395

392-
.PHONY: phobos-prerelease
396+
#.PHONY: phobos-prerelease
393397
phobos-prerelease : ${PHOBOS_DIR} $(STD_DDOC_PRE) druntime-prerelease
394398
${MAKE} --directory=${PHOBOS_DIR} -f posix.mak \
395399
STDDOC="$(addprefix `pwd`/, $(STD_DDOC_PRE))" \
@@ -422,19 +426,19 @@ apidocs-prerelease : ${DOC_OUTPUT_DIR}/library-prerelease/sitemap.xml ${DOC_OUTP
422426
apidocs-release : ${DOC_OUTPUT_DIR}/library/sitemap.xml ${DOC_OUTPUT_DIR}/library/.htaccess
423427
apidocs-serve : docs-prerelease.json
424428
${DPL_DOCS} serve-html --std-macros=html.ddoc --std-macros=dlang.org.ddoc --std-macros=std.ddoc --std-macros=macros.ddoc --std-macros=std-ddox.ddoc \
425-
--override-macros=std-ddox-override.ddoc --package-order=std \
429+
--override-macros=std-ddox-override.ddoc --package-order=std --hyphenate \
426430
--git-target=master --web-file-dir=. docs-prerelease.json
427431

428432
${DOC_OUTPUT_DIR}/library-prerelease/sitemap.xml : docs-prerelease.json
429433
@mkdir -p $(dir $@)
430434
${DPL_DOCS} generate-html --file-name-style=lowerUnderscored --std-macros=html.ddoc --std-macros=dlang.org.ddoc --std-macros=std.ddoc --std-macros=macros.ddoc --std-macros=std-ddox.ddoc \
431-
--override-macros=std-ddox-override.ddoc --package-order=std \
435+
--override-macros=std-ddox-override.ddoc --package-order=std --hyphenate \
432436
--git-target=master docs-prerelease.json ${DOC_OUTPUT_DIR}/library-prerelease
433437

434438
${DOC_OUTPUT_DIR}/library/sitemap.xml : docs.json
435439
@mkdir -p $(dir $@)
436440
${DPL_DOCS} generate-html --file-name-style=lowerUnderscored --std-macros=html.ddoc --std-macros=dlang.org.ddoc --std-macros=std.ddoc --std-macros=macros.ddoc --std-macros=std-ddox.ddoc \
437-
--override-macros=std-ddox-override.ddoc --package-order=std \
441+
--override-macros=std-ddox-override.ddoc --package-order=std --hyphenate \
438442
--git-target=v${LATEST} docs.json ${DOC_OUTPUT_DIR}/library
439443

440444
${DOC_OUTPUT_DIR}/library/.htaccess : dpl_release_htaccess
@@ -493,6 +497,26 @@ ${STABLE_DMD}:
493497
${DUB}: ${DUB_DIR} ${STABLE_DMD}
494498
cd ${DUB_DIR} && DC="$(abspath ${STABLE_DMD}) -conf=$(abspath ${STABLE_DMD_CONF})" ./build.sh
495499

500+
################################################################################
501+
# HTML post-processing
502+
################################################################################
503+
504+
# binary
505+
.PHONY: html-postprocessor
506+
html-postprocessor: ${DUB} ${STABLE_DMD}
507+
DFLAGS="$(DPL_DOCS_DFLAGS)" ${DUB} build --root=${HTML_POSTPROCESSOR_PATH} \
508+
--compiler=${STABLE_DMD}
509+
510+
# post process html output (currently hyphenation)
511+
# process any html file that is newer than the rule's .done dummy file
512+
${HTML_POSTPROCESSOR_PATH}/.done: ${ALL_FILES} html-postprocessor \
513+
html phobos-prerelease druntime-prerelease druntime-release phobos-release
514+
if [ ! -f $@ ]; then touch -t 197001010000 $@; fi
515+
find ${DOC_OUTPUT_DIR} -newer $@ -name '*.html' \
516+
-not \( -path '${DOC_OUTPUT_DIR}/library/*' -or -path '${DOC_OUTPUT_DIR}/library-prerelease/*' \) \
517+
| xargs ${HTML_POSTPROCESSOR}
518+
touch $@
519+
496520
################################################################################
497521
# Dman tags
498522
################################################################################

spec/iasm.dd

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ $(DL
461461

462462
$(H2 Opcodes Supported)
463463

464-
$(LONGTABLE_5COLS Opcodes, ,
464+
$(DIVC donthyphenate, $(LONGTABLE_5COLS Opcodes, ,
465465
$(TROW $(TT aaa)
466466
, $(TT aad)
467467
, $(TT aam)
@@ -1013,11 +1013,11 @@ $(H2 Opcodes Supported)
10131013
, $(TT )
10141014
, $(TT )
10151015
)
1016-
)
1016+
))
10171017

10181018
$(H3 Pentium 4 (Prescott) Opcodes Supported)
10191019

1020-
$(LONGTABLE_5COLS Pentium 4 Opcodes, ,
1020+
$(DIVC donthyphenate, $(LONGTABLE_5COLS Pentium 4 Opcodes, ,
10211021
$(TROW $(TT addsubpd)
10221022
, $(TT addsubps)
10231023
, $(TT fisttp)
@@ -1034,11 +1034,11 @@ $(H3 Pentium 4 (Prescott) Opcodes Supported)
10341034
, $(TT )
10351035
, $(TT )
10361036
)
1037-
)
1037+
))
10381038

10391039
$(H3 AMD Opcodes Supported)
10401040

1041-
$(LONGTABLE_5COLS AMD Opcodes, ,
1041+
$(DIVC donthyphenate, $(LONGTABLE_5COLS AMD Opcodes, ,
10421042
$(TROW $(TT pavgusb)
10431043
, $(TT pf2id)
10441044
, $(TT pfacc)
@@ -1065,7 +1065,7 @@ $(H3 AMD Opcodes Supported)
10651065
, $(TT )
10661066
, $(TT )
10671067
)
1068-
)
1068+
))
10691069

10701070
$(H3 SIMD)
10711071

@@ -1164,4 +1164,3 @@ getsec
11641164
Macros:
11651165
TITLE=Inline Assembler
11661166
WIKI=IAsm
1167-

0 commit comments

Comments
 (0)