diff --git a/package.json b/package.json index 9339482..aed1cb6 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,11 @@ "type": "git", "url": "https://github.com/clenemt/docdash.git" }, + "dependencies": { + "hyphenation.en-gb": "^0.2.1", + "hypher": "^0.2.5", + "jsdom": "^15.1.1" + }, "devDependencies": { "jsdoc": "latest", "browser-sync": "latest", diff --git a/publish.js b/publish.js index 74e721b..8bb0c04 100644 --- a/publish.js +++ b/publish.js @@ -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; @@ -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 . @param {object} opts @@ -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) { diff --git a/static/styles/jsdoc.css b/static/styles/jsdoc.css index 5c016d1..e947efb 100644 --- a/static/styles/jsdoc.css +++ b/static/styles/jsdoc.css @@ -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 {