Skip to content

Commit

Permalink
Add hyphenation hints on compile time & use text justification
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
koraa committed Jun 20, 2019
1 parent 994d122 commit 4e86467
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
"devDependencies": {
"jsdoc": "latest",
"browser-sync": "latest",
"watch-run": "latest"
"watch-run": "latest",
"hyphenation.en-gb": "^0.2.1",
"hypher": "^0.2.5",
"jsdom": "^15.1.1"
},
"author": "Clement Moron <clement.moron@gmail.com>",
"license": "Apache-2.0",
Expand Down
39 changes: 37 additions & 2 deletions publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ var path = require('jsdoc/path');
var taffy = require('taffydb').taffy;
var template = require('jsdoc/template');
var util = require('util');
var jsdom = require('jsdom');
var Hypher = require('hypher');
var hypher_en = require('hyphenation.en-gb');

var hypher = new Hypher(hypher_en);
var htmlsafe = helper.htmlsafe;
var linkto = helper.linkto;
var resolveAuthorLinks = helper.resolveAuthorLinks;
Expand Down Expand Up @@ -475,6 +479,35 @@ function buildNav(members) {
return nav;
}

function hyphenate_dom(node) {
if (node.nodeName === '#text') {
node.nodeValue = hypher.hyphenateText(node.nodeValue);
}
for (const child of node.childNodes) {
hyphenate_dom(child);
}
}

function hyphenate_prop(obj, prop) {
var dom = new jsdom.JSDOM(obj[prop]);
hyphenate_dom(dom.window.document.body);
obj[prop] = dom.window.document.body.innerHTML;
}

function hyphenate_doclet(doclet) {
hyphenate_prop(doclet, 'classdoc');
hyphenate_prop(doclet, 'description');
for (const param of doclet.params || []) {
hyphenate_prop(param, 'description');
}
for (const prop of doclet.properties || []) {
hyphenate_prop(prop, 'description');
}
for (const ret of doclet.returns || []) {
hyphenate_prop(ret, 'description');
}
}

/**
@param {TAFFY} taffyData See <http://taffydb.com/>.
@param {object} opts
Expand Down Expand Up @@ -536,8 +569,10 @@ exports.publish = function(taffyData, opts, tutorials) {
doclet.longname = doclet.longname.replace(/^'(.*)'$/, '$1');
}
}
}
doclet.attribs = '';
}
doclet.attribs = '';

hyphenate_doclet(doclet);

if (doclet.examples) {
doclet.examples = doclet.examples.map(function(example) {
Expand Down
1 change: 1 addition & 0 deletions static/styles/jsdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ article .description a {
p, ul, ol, blockquote {
margin-bottom: 1em;
line-height: 160%;
text-align: justify;
}

h1, h2, h3, h4, h5, h6 {
Expand Down

0 comments on commit 4e86467

Please sign in to comment.