Skip to content

Commit b45b595

Browse files
committed
Add hyphenation hints on compile time & use text justification
This commit adds proper hyphenation hints to the documentation at doc compile time; these hints can be used to portably use `text-align: justified` with nice hyphenation. This looks nice & fits more information, especially on small screens.
1 parent 994d122 commit b45b595

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
"type": "git",
1313
"url": "https://github.com/clenemt/docdash.git"
1414
},
15+
"dependencies": {
16+
"hyphenation.en-gb": "^0.2.1",
17+
"hypher": "^0.2.5",
18+
"jsdom": "^15.1.1"
19+
},
1520
"devDependencies": {
1621
"jsdoc": "latest",
1722
"browser-sync": "latest",

publish.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ var path = require('jsdoc/path');
99
var taffy = require('taffydb').taffy;
1010
var template = require('jsdoc/template');
1111
var util = require('util');
12+
var jsdom = require('jsdom');
13+
var Hypher = require('hypher');
14+
var hypher_en = require('hyphenation.en-gb');
1215

16+
var hypher = new Hypher(hypher_en);
1317
var htmlsafe = helper.htmlsafe;
1418
var linkto = helper.linkto;
1519
var resolveAuthorLinks = helper.resolveAuthorLinks;
@@ -475,6 +479,35 @@ function buildNav(members) {
475479
return nav;
476480
}
477481

482+
function hyphenate_dom(node) {
483+
if (node.nodeName === '#text') {
484+
node.nodeValue = hypher.hyphenateText(node.nodeValue);
485+
}
486+
for (const child of node.childNodes) {
487+
hyphenate_dom(child);
488+
}
489+
}
490+
491+
function hyphenate_prop(obj, prop) {
492+
var dom = new jsdom.JSDOM(obj[prop]);
493+
hyphenate_dom(dom.window.document.body);
494+
obj[prop] = dom.window.document.body.innerHTML;
495+
}
496+
497+
function hyphenate_doclet(doclet) {
498+
hyphenate_prop(doclet, 'classdoc');
499+
hyphenate_prop(doclet, 'description');
500+
for (const param of doclet.params || []) {
501+
hyphenate_prop(param, 'description');
502+
}
503+
for (const prop of doclet.properties || []) {
504+
hyphenate_prop(prop, 'description');
505+
}
506+
for (const ret of doclet.returns || []) {
507+
hyphenate_prop(ret, 'description');
508+
}
509+
}
510+
478511
/**
479512
@param {TAFFY} taffyData See <http://taffydb.com/>.
480513
@param {object} opts
@@ -536,8 +569,10 @@ exports.publish = function(taffyData, opts, tutorials) {
536569
doclet.longname = doclet.longname.replace(/^'(.*)'$/, '$1');
537570
}
538571
}
539-
}
540-
doclet.attribs = '';
572+
}
573+
doclet.attribs = '';
574+
575+
hyphenate_doclet(doclet);
541576

542577
if (doclet.examples) {
543578
doclet.examples = doclet.examples.map(function(example) {

static/styles/jsdoc.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ article .description a {
4747
p, ul, ol, blockquote {
4848
margin-bottom: 1em;
4949
line-height: 160%;
50+
text-align: justify;
5051
}
5152

5253
h1, h2, h3, h4, h5, h6 {

0 commit comments

Comments
 (0)