Skip to content

Commit a679a69

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 c35d4a3 commit a679a69

File tree

8 files changed

+131
-29
lines changed

8 files changed

+131
-29
lines changed

css/style.css

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -520,17 +520,6 @@ body.std .subnav a.package
520520
text-align: justify;
521521
}
522522

523-
/* This is a CSS hack to only target Blink based browsers
524-
Targets Chrome 28 and later and Opera 14 and later
525-
*/
526-
@media all and (-webkit-min-device-pixel-ratio:0) and (min-resolution: .001dpcm) {
527-
#content
528-
{
529-
/* because Blink based browsers don't support hyphens */
530-
text-align: left;
531-
}
532-
}
533-
534523
.subnav + #content
535524
{
536525
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 the $(LINK2 $(ROOT)/foundation.html, D Language Foundation)
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)
@@ -161,7 +161,7 @@ GLINK2=$(DDSUBLINK spec/$1,$2,$(I $2))
161161
GLOSSARY = $(HTTP dlang.org/glossary.html#$0, $0)
162162
GLOSSARY2 = $(HTTP dlang.org/glossary.html#$1, $2)
163163
GNAME=<a id="$0">$(SPANC gname, $0)</a>
164-
GRAMMAR=$(TC pre, bnf notranslate, $0)
164+
GRAMMAR=$(TC pre, bnf donthyphenate notranslate, $0)
165165
GREEN=$(SPANC green, $0)
166166
GT=&gt;
167167
_=
@@ -199,7 +199,7 @@ MENU_W_SUBMENU_LINK = <li class='expand-container'><a class='expand-toggle' href
199199
MENU_W_SUBMENU_END = </li>
200200
META_KEYWORDS=D programming language
201201
META_DESCRIPTION=D Programming Language
202-
MODDEFFILE=$(TC pre, moddeffile notranslate, $0)
202+
MODDEFFILE=$(TC pre, moddeffile donthyphenate notranslate, $0)
203203
MULTICOL_CELL=<td colspan="$1">$+</td>
204204
MULTICOL_HEADER=<th colspan="$1">$+</th>
205205
MULTICOLS=$+
@@ -347,7 +347,7 @@ RELATIVE_LINK2=$(ALOCAL $1, $+)
347347
_=
348348

349349
SAMPLESRC=$(SPANC sample_src, $(AHTTPS github.com/dlang/dmd/blob/master/samples/$0, /dmd/samples/d/$0))
350-
SCINI=$(TC pre, scini notranslate, $0)
350+
SCINI=$(TC pre, scini donthyphenate notranslate, $0)
351351
SCRIPTLOAD=<script type="text/javascript" src="$0"></script>
352352
SEARCHDEFAULT_PHOBOS=
353353
SEARCHDEFAULT_FORUM=

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: 29 additions & 5 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/dlang
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 : dmd-prerelease phobos-prerelease druntime-prerelease druntime-release \
238240
phobos-release 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}
@@ -427,19 +431,19 @@ apidocs-prerelease : ${DOC_OUTPUT_DIR}/library-prerelease/sitemap.xml ${DOC_OUTP
427431
apidocs-release : ${DOC_OUTPUT_DIR}/library/sitemap.xml ${DOC_OUTPUT_DIR}/library/.htaccess
428432
apidocs-serve : docs-prerelease.json
429433
${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 \
430-
--override-macros=std-ddox-override.ddoc --package-order=std \
434+
--override-macros=std-ddox-override.ddoc --package-order=std --hyphenate \
431435
--git-target=master --web-file-dir=. docs-prerelease.json
432436

433437
${DOC_OUTPUT_DIR}/library-prerelease/sitemap.xml : docs-prerelease.json
434438
@mkdir -p $(dir $@)
435439
${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 \
436-
--override-macros=std-ddox-override.ddoc --package-order=std \
440+
--override-macros=std-ddox-override.ddoc --package-order=std --hyphenate \
437441
--git-target=master docs-prerelease.json ${DOC_OUTPUT_DIR}/library-prerelease
438442

439443
${DOC_OUTPUT_DIR}/library/sitemap.xml : docs.json
440444
@mkdir -p $(dir $@)
441445
${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 \
442-
--override-macros=std-ddox-override.ddoc --package-order=std \
446+
--override-macros=std-ddox-override.ddoc --package-order=std --hyphenate \
443447
--git-target=v${LATEST} docs.json ${DOC_OUTPUT_DIR}/library
444448

445449
${DOC_OUTPUT_DIR}/library/.htaccess : dpl_release_htaccess
@@ -506,6 +510,26 @@ ${DUB}: ${DUB_DIR} ${STABLE_DMD}
506510
chm-nav.json : $(DDOC) std.ddoc spec/spec.ddoc ${GENERATED}/modlist-${LATEST}.ddoc changelog/changelog.ddoc chm-nav.dd $(DMD)
507511
$(DMD) -conf= -c -o- -Df$@ $(filter-out $(DMD),$^)
508512

513+
################################################################################
514+
# HTML post-processing
515+
################################################################################
516+
517+
# binary
518+
.PHONY: html-postprocessor
519+
html-postprocessor: ${DUB} ${STABLE_DMD}
520+
DFLAGS="$(DPL_DOCS_DFLAGS)" ${DUB} build --root=${HTML_POSTPROCESSOR_PATH} \
521+
--compiler=${STABLE_DMD}
522+
523+
# post process html output (currently hyphenation)
524+
# process any html file that is newer than the rule's .done dummy file
525+
${HTML_POSTPROCESSOR_PATH}/.done: ${ALL_FILES} html-postprocessor \
526+
html phobos-prerelease druntime-prerelease druntime-release phobos-release
527+
if [ ! -f $@ ]; then touch -t 197001010000 $@; fi
528+
find ${DOC_OUTPUT_DIR} -newer $@ -name '*.html' \
529+
-not \( -path '${DOC_OUTPUT_DIR}/library/*' -or -path '${DOC_OUTPUT_DIR}/library-prerelease/*' \) \
530+
| xargs ${HTML_POSTPROCESSOR}
531+
touch $@
532+
509533
################################################################################
510534
# Dman tags
511535
################################################################################

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 $(LNAME2 supported_opcodes, 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 $(LNAME2 supported_opcodes, Opcodes Supported))
10131013
, $(TT )
10141014
, $(TT )
10151015
)
1016-
)
1016+
))
10171017

10181018
$(H3 $(LNAME2 P4_opcode_support, 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 $(LNAME2 P4_opcode_support, Pentium 4 (Prescott) Opcodes Supported))
10341034
, $(TT )
10351035
, $(TT )
10361036
)
1037-
)
1037+
))
10381038

10391039
$(H3 $(LNAME2 amd_opcode_support, 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 $(LNAME2 amd_opcode_support, AMD Opcodes Supported))
10651065
, $(TT )
10661066
, $(TT )
10671067
)
1068-
)
1068+
))
10691069

10701070
$(H3 $(LNAME2 simd, SIMD))
10711071

@@ -1163,4 +1163,3 @@ getsec
11631163

11641164
Macros:
11651165
TITLE=Inline Assembler
1166-

0 commit comments

Comments
 (0)