diff --git a/index.js b/index.js index c6fe5aa..49e32cf 100644 --- a/index.js +++ b/index.js @@ -1,14 +1,2 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast - * @fileoverview Transform MDAST to HAST. - */ - 'use strict'; - -/* eslint-env commonjs */ - -/* Expose. */ module.exports = require('./lib/index.js'); diff --git a/lib/all.js b/lib/all.js index b4b8862..b2541d3 100644 --- a/lib/all.js +++ b/lib/all.js @@ -1,29 +1,11 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:all - * @fileoverview Visit all MDAST nodes. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Expose. */ module.exports = all; -/* Dependencies. */ var trim = require('trim'); var one = require('./one'); -/** - * Transform the children of `parent`. - * - * @param {Function} h - Hyperscript DSL. - * @param {Node} parent - Parent to visit. - * @return {Array.} - HAST nodes. - */ +/* Transform the children of `parent`. */ function all(h, parent) { var nodes = parent.children || []; var length = nodes.length; diff --git a/lib/failsafe.js b/lib/failsafe.js index 87e7e9c..055ddc3 100644 --- a/lib/failsafe.js +++ b/lib/failsafe.js @@ -1,32 +1,12 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:failsafe - * @fileoverview Failsafe to stringify references - * without definitions back to markdown. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Expose. */ module.exports = failsafe; -/* Dependencies. */ var u = require('unist-builder'); var all = require('./all'); -/** - * Return the content of a reference without definition - * as markdown. - * - * @param {Function} h - Hyperscript DSL. - * @param {Node} node - Node to compile. - * @param {Node?} [definition] - Definition node. - * @return {Array.?} - Node, list of nodes, or nothing. - */ +/* Return the content of a reference without definition + * as markdown. */ function failsafe(h, node, definition) { var subtype = node.referenceType; diff --git a/lib/footer.js b/lib/footer.js index cbe94bf..201aec4 100644 --- a/lib/footer.js +++ b/lib/footer.js @@ -1,29 +1,12 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:footnotes - * @fileoverview Generate the footnote footer. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Expose. */ module.exports = generateFootnotes; -/* Dependencies. */ var thematicBreak = require('./handlers/thematic-break'); var list = require('./handlers/list'); var wrap = require('./wrap'); -/** - * Transform all footnote definitions, if any. - * - * @param {Function} h - Hyperscript DSL. - * @return {Node?} - Compiled footnotes, if any. - */ +/* Transform all footnote definitions, if any. */ function generateFootnotes(h) { var footnotes = h.footnotes; var length = footnotes.length; diff --git a/lib/handlers/blockquote.js b/lib/handlers/blockquote.js index 96c12aa..8ddb3de 100644 --- a/lib/handlers/blockquote.js +++ b/lib/handlers/blockquote.js @@ -1,29 +1,11 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:handlers:blockquote - * @fileoverview Handle a `blockquote`. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Expose. */ module.exports = blockquote; -/* Dependencies. */ var wrap = require('../wrap'); var all = require('../all'); -/** - * Transform a block quote. - * - * @param {Function} h - Hyperscript DSL. - * @param {Node} node - Node to compile. - * @return {Node} - HAST node. - */ +/* Transform a block quote. */ function blockquote(h, node) { return h(node, 'blockquote', wrap(all(h, node), true)); } diff --git a/lib/handlers/break.js b/lib/handlers/break.js index e86c758..f3d2cd3 100644 --- a/lib/handlers/break.js +++ b/lib/handlers/break.js @@ -1,28 +1,10 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:handlers:break - * @fileoverview Handle a `break`. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Expose. */ module.exports = hardBreak; -/* Dependencies. */ var u = require('unist-builder'); -/** - * Transform an inline break. - * - * @param {Function} h - Hyperscript DSL. - * @param {Node} node - Node to compile. - * @return {Array.} - HAST nodes. - */ +/* Transform an inline break. */ function hardBreak(h, node) { return [h(node, 'br'), u('text', '\n')]; } diff --git a/lib/handlers/code.js b/lib/handlers/code.js index fbc19aa..5032ddf 100644 --- a/lib/handlers/code.js +++ b/lib/handlers/code.js @@ -1,29 +1,11 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:handlers:code - * @fileoverview Handle `code`. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Expose. */ module.exports = code; -/* Dependencies. */ var detab = require('detab'); var u = require('unist-builder'); -/** - * Transform a code block. - * - * @param {Function} h - Hyperscript DSL. - * @param {Node} node - Node to compile. - * @return {Node} - HAST node. - */ +/* Transform a code block. */ function code(h, node) { var value = node.value ? detab(node.value + '\n') : ''; var lang = node.lang && node.lang.match(/^[^ \t]+(?=[ \t]|$)/); diff --git a/lib/handlers/delete.js b/lib/handlers/delete.js index 05f3734..2ad70ef 100644 --- a/lib/handlers/delete.js +++ b/lib/handlers/delete.js @@ -1,28 +1,10 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:handlers:delete - * @fileoverview Handle `delete`. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Expose. */ module.exports = strikethrough; -/* Dependencies. */ var all = require('../all'); -/** - * Transform deletions. - * - * @param {Function} h - Hyperscript DSL. - * @param {Node} node - Node to compile. - * @return {Node} - HAST node. - */ +/* Transform deletions. */ function strikethrough(h, node) { return h(node, 'del', all(h, node)); } diff --git a/lib/handlers/emphasis.js b/lib/handlers/emphasis.js index 819d155..6e885f3 100644 --- a/lib/handlers/emphasis.js +++ b/lib/handlers/emphasis.js @@ -1,28 +1,10 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:handlers:emphasis - * @fileoverview Handle `emphasis`. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Expose. */ module.exports = emphasis; -/* Dependencies. */ var all = require('../all'); -/** - * Transform emphasis - * - * @param {Function} h - Hyperscript DSL. - * @param {Node} node - Node to compile. - * @return {Node} - HAST node. - */ +/* Transform emphasis. */ function emphasis(h, node) { return h(node, 'em', all(h, node)); } diff --git a/lib/handlers/footnote-reference.js b/lib/handlers/footnote-reference.js index 3fd96bb..df6e1c1 100644 --- a/lib/handlers/footnote-reference.js +++ b/lib/handlers/footnote-reference.js @@ -1,28 +1,10 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:handlers:footnote-reference - * @fileoverview Handle `footnoteReference`. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Expose. */ module.exports = footnoteReference; -/* Dependencies. */ var u = require('unist-builder'); -/** - * Transform a reference to a footnote. - * - * @param {Function} h - Hyperscript DSL. - * @param {Node} node - Node to compile. - * @return {Node} - HAST node. - */ +/* Transform a reference to a footnote. */ function footnoteReference(h, node) { var identifier = node.identifier; diff --git a/lib/handlers/footnote.js b/lib/handlers/footnote.js index b6fe1c5..8f9e819 100644 --- a/lib/handlers/footnote.js +++ b/lib/handlers/footnote.js @@ -1,28 +1,10 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:handlers:footnote - * @fileoverview Handle `footnote`. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Expose. */ module.exports = footnote; -/* Dependencies. */ var footnoteReference = require('./footnote-reference'); -/** - * Transform an inline footnote. - * - * @param {Function} h - Hyperscript DSL. - * @param {Node} node - Node to compile. - * @return {Node} - HAST node. - */ +/* Transform an inline footnote. */ function footnote(h, node) { var identifiers = []; var identifier = 1; diff --git a/lib/handlers/heading.js b/lib/handlers/heading.js index 3601e28..1659352 100644 --- a/lib/handlers/heading.js +++ b/lib/handlers/heading.js @@ -1,28 +1,10 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:handlers:heading - * @fileoverview Handle `heading`. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Expose. */ module.exports = heading; -/* Dependencies. */ var all = require('../all'); -/** - * Transform a heading. - * - * @param {Function} h - Hyperscript DSL. - * @param {Node} node - Node to compile. - * @return {Node} - HAST node. - */ +/* Transform a heading. */ function heading(h, node) { return h(node, 'h' + node.depth, all(h, node)); } diff --git a/lib/handlers/html.js b/lib/handlers/html.js index 7037955..0fd326f 100644 --- a/lib/handlers/html.js +++ b/lib/handlers/html.js @@ -1,29 +1,11 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:handlers:html - * @fileoverview Handle `html`. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Expose. */ module.exports = html; -/* Dependencies. */ var u = require('unist-builder'); -/** - * Return either a `raw` node, in dangerous mode, or - * nothing. - * - * @param {Function} h - Hyperscript DSL. - * @param {Node} node - Node to compile. - * @return {Node|null} - Nothing. - */ +/* Return either a `raw` node, in dangerous mode, or + * nothing. */ function html(h, node) { return h.dangerous ? h.augment(node, u('raw', node.value)) : null; } diff --git a/lib/handlers/image-reference.js b/lib/handlers/image-reference.js index 9937599..99cd0e9 100644 --- a/lib/handlers/image-reference.js +++ b/lib/handlers/image-reference.js @@ -1,29 +1,11 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:handlers:image-reference - * @fileoverview Handle `imageReference`. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Expose. */ module.exports = imageReference; -/* Dependencies. */ var normalize = require('normalize-uri'); var failsafe = require('../failsafe'); -/** - * Transform a reference to an image. - * - * @param {Function} h - Hyperscript DSL. - * @param {Node} node - Node to compile. - * @return {Node} - HAST node. - */ +/* Transform a reference to an image. */ function imageReference(h, node) { var def = h.definition(node.identifier); var props = {src: normalize((def && def.url) || ''), alt: node.alt}; diff --git a/lib/handlers/image.js b/lib/handlers/image.js index 5730df5..456184c 100644 --- a/lib/handlers/image.js +++ b/lib/handlers/image.js @@ -1,28 +1,10 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:handlers:image - * @fileoverview Handle `image`. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Dependencies. */ var normalize = require('normalize-uri'); -/* Expose. */ module.exports = image; -/** - * Transform an image. - * - * @param {Function} h - Hyperscript DSL. - * @param {Node} node - Node to compile. - * @return {Node} - HAST node. - */ +/* Transform an image. */ function image(h, node) { var props = {src: normalize(node.url), alt: node.alt}; diff --git a/lib/handlers/index.js b/lib/handlers/index.js index 061dfe1..58836c2 100644 --- a/lib/handlers/index.js +++ b/lib/handlers/index.js @@ -1,16 +1,5 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:handlers - * @fileoverview Handle each node. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Handlers. */ module.exports = { blockquote: require('./blockquote'), break: require('./break'), @@ -39,11 +28,7 @@ module.exports = { footnoteDefinition: ignore }; -/** - * Return nothing for nodes which are ignored. - * - * @return {null} - Nothing. - */ +/* Return nothing for nodes which are ignored. */ function ignore() { return null; } diff --git a/lib/handlers/inline-code.js b/lib/handlers/inline-code.js index 772e969..45488ae 100644 --- a/lib/handlers/inline-code.js +++ b/lib/handlers/inline-code.js @@ -1,29 +1,11 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:handlers:inline-code - * @fileoverview Handle `inlineCode`. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Expose. */ module.exports = inlineCode; -/* Dependencies. */ var collapse = require('collapse-white-space'); var u = require('unist-builder'); -/** - * Transform inline code. - * - * @param {Function} h - Hyperscript DSL. - * @param {Node} node - Node to compile. - * @return {Node} - HAST node. - */ +/* Transform inline code. */ function inlineCode(h, node) { return h(node, 'code', [u('text', collapse(node.value))]); } diff --git a/lib/handlers/link-reference.js b/lib/handlers/link-reference.js index 4abcd17..c87eaa9 100644 --- a/lib/handlers/link-reference.js +++ b/lib/handlers/link-reference.js @@ -1,30 +1,12 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:handlers:link-reference - * @fileoverview Handle `linkReference`. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Expose. */ module.exports = linkReference; -/* Dependencies. */ var normalize = require('normalize-uri'); var failsafe = require('../failsafe'); var all = require('../all'); -/** - * Transform a reference to a link. - * - * @param {Function} h - Hyperscript DSL. - * @param {Node} node - Node to compile. - * @return {Node} - HAST node. - */ +/* Transform a reference to a link. */ function linkReference(h, node) { var def = h.definition(node.identifier); var props = {href: normalize((def && def.url) || '')}; diff --git a/lib/handlers/link.js b/lib/handlers/link.js index 0577bb5..d1e5f98 100644 --- a/lib/handlers/link.js +++ b/lib/handlers/link.js @@ -1,29 +1,11 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:handlers:link - * @fileoverview Handle `link`. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Dependencies. */ var normalize = require('normalize-uri'); var all = require('../all'); -/* Expose. */ module.exports = link; -/** - * Transform a link. - * - * @param {Function} h - Hyperscript DSL. - * @param {Node} node - Node to compile. - * @return {Node} - HAST node. - */ +/* Transform a link. */ function link(h, node) { var props = {href: normalize(node.url)}; diff --git a/lib/handlers/list-item.js b/lib/handlers/list-item.js index fd3f0a6..5e4bf50 100644 --- a/lib/handlers/list-item.js +++ b/lib/handlers/list-item.js @@ -1,31 +1,12 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:handlers:list-item - * @fileoverview Handle `listItem`. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Expose. */ module.exports = listItem; -/* Dependencies. */ var u = require('unist-builder'); var wrap = require('../wrap'); var all = require('../all'); -/** - * Transform a list-item. - * - * @param {Function} h - Hyperscript DSL. - * @param {Node} node - Node to compile. - * @param {Node} parent - Parent of `node`. - * @return {Node} - HAST node. - */ +/* Transform a list-item. */ function listItem(h, node, parent) { var children = node.children; var head = children[0]; @@ -41,7 +22,7 @@ function listItem(h, node, parent) { container = single ? result : result[0].children; - if (container.length) { + if (container.length !== 0) { container.unshift(u('text', ' ')); } @@ -55,7 +36,7 @@ function listItem(h, node, parent) { props.className = ['task-list-item']; } - if (!single && result.length) { + if (!single && result.length !== 0) { result = wrap(result, true); } diff --git a/lib/handlers/list.js b/lib/handlers/list.js index 7f22276..20eea70 100644 --- a/lib/handlers/list.js +++ b/lib/handlers/list.js @@ -1,29 +1,11 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:handlers:list - * @fileoverview Handle `list`. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Expose. */ module.exports = list; -/* Dependencies. */ var wrap = require('../wrap'); var all = require('../all'); -/** - * Transform a list. - * - * @param {Function} h - Hyperscript DSL. - * @param {Node} node - Node to compile. - * @return {Node} - HAST node. - */ +/* Transform a list. */ function list(h, node) { var props = {}; var name = node.ordered ? 'ol' : 'ul'; diff --git a/lib/handlers/paragraph.js b/lib/handlers/paragraph.js index 412e939..43209cd 100644 --- a/lib/handlers/paragraph.js +++ b/lib/handlers/paragraph.js @@ -1,28 +1,10 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:handlers:paragraph - * @fileoverview Handle `paragraph`. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Expose. */ module.exports = paragraph; -/* Dependencies. */ var all = require('../all'); -/** - * Transform a paragraph. - * - * @param {Function} h - Hyperscript DSL. - * @param {Node} node - Node to compile. - * @return {Node} - HAST node. - */ +/* Transform a paragraph. */ function paragraph(h, node) { return h(node, 'p', all(h, node)); } diff --git a/lib/handlers/root.js b/lib/handlers/root.js index 591d180..7bae56c 100644 --- a/lib/handlers/root.js +++ b/lib/handlers/root.js @@ -1,30 +1,12 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:handlers:root - * @fileoverview Handle `root`. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Expose. */ module.exports = root; -/* Dependencies. */ var u = require('unist-builder'); var wrap = require('../wrap'); var all = require('../all'); -/** - * Transform a `root`. - * - * @param {Function} h - Hyperscript DSL. - * @param {Node} node - Node to compile. - * @return {Node} - HAST node. - */ +/* Transform a `root`. */ function root(h, node) { return h.augment(node, u('root', wrap(all(h, node)))); } diff --git a/lib/handlers/strong.js b/lib/handlers/strong.js index 1216a11..1d159d9 100644 --- a/lib/handlers/strong.js +++ b/lib/handlers/strong.js @@ -1,28 +1,10 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:handlers:strong - * @fileoverview Handle `strong`. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Expose. */ module.exports = strong; -/* Dependencies. */ var all = require('../all'); -/** - * Transform importance. - * - * @param {Function} h - Hyperscript DSL. - * @param {Node} node - Node to compile. - * @return {Node} - HAST node. - */ +/* Transform importance. */ function strong(h, node) { return h(node, 'strong', all(h, node)); } diff --git a/lib/handlers/table.js b/lib/handlers/table.js index 4aaad80..bee3d58 100644 --- a/lib/handlers/table.js +++ b/lib/handlers/table.js @@ -1,30 +1,12 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:handlers:table - * @fileoverview Handle `table`. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Expose. */ module.exports = table; -/* Dependencies. */ var position = require('unist-util-position'); var wrap = require('../wrap'); var all = require('../all'); -/** - * Transform a table. - * - * @param {Function} h - Hyperscript DSL. - * @param {Node} node - Node to compile. - * @return {Node} - HAST node. - */ +/* Transform a table. */ function table(h, node) { var rows = node.children; var index = rows.length; diff --git a/lib/handlers/text.js b/lib/handlers/text.js index fb46db9..002574a 100644 --- a/lib/handlers/text.js +++ b/lib/handlers/text.js @@ -1,29 +1,11 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:handlers:text - * @fileoverview Handle `text`. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Expose. */ module.exports = text; -/* Dependencies. */ var u = require('unist-builder'); var trimLines = require('trim-lines'); -/** - * Transform text. - * - * @param {Function} h - Hyperscript DSL. - * @param {Node} node - Node to compile. - * @return {Node} - HAST text node. - */ +/* Transform text. */ function text(h, node) { return h.augment(node, u('text', trimLines(node.value))); } diff --git a/lib/handlers/thematic-break.js b/lib/handlers/thematic-break.js index 3cc17c8..9b721dd 100644 --- a/lib/handlers/thematic-break.js +++ b/lib/handlers/thematic-break.js @@ -1,25 +1,8 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:handlers:thematic-break - * @fileoverview Handle `thematicBreak`. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Expose. */ module.exports = thematicBreak; -/** - * Transform a thematic break / horizontal rule. - * - * @param {Function} h - Hyperscript DSL. - * @param {Node} node - Node to compile. - * @return {Node} - HAST node. - */ +/* Transform a thematic break / horizontal rule. */ function thematicBreak(h, node) { return h(node, 'hr'); } diff --git a/lib/index.js b/lib/index.js index 925a14e..f3901d4 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,19 +1,7 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast - * @fileoverview Transform MDAST to HAST. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Expose. */ module.exports = toHAST; -/* Dependencies. */ var xtend = require('xtend'); var u = require('unist-builder'); var visit = require('unist-util-visit'); @@ -22,23 +10,21 @@ var definitions = require('mdast-util-definitions'); var one = require('./one'); var footer = require('./footer'); -/** - * Factory to transform. - * - * @param {Node} tree - MDAST tree. - * @param {Object?} options - Configuration. - * @return {Function} - Hyperscript-like DSL. - */ +/* Factory to transform. */ function factory(tree, options) { var dangerous = (options || {}).allowDangerousHTML; - /** - * Finalise the created `right`, a HAST node, from - * `left`, an MDAST node. - * - * @param {Node} left - MDAST node. - * @param {Node} right - HAST node. - */ + h.dangerous = dangerous; + h.definition = definitions(tree); + h.footnotes = []; + h.augment = augment; + + visit(tree, 'footnoteDefinition', visitor); + + return h; + + /* Finalise the created `right`, a HAST node, from + * `left`, an MDAST node. */ function augment(left, right) { var data; var ctx; @@ -72,14 +58,7 @@ function factory(tree, options) { return right; } - /** - * Create an element for a `node`. - * - * @param {Node} node - MDAST node to compile for. - * @param {string} tagName - Proposed tag-name. - * @param {Object?} [props={}] - Properties. - * @param {Array.} children - HAST children. - */ + /* Create an element for a `node`. */ function h(node, tagName, props, children) { if ( children == null && @@ -98,25 +77,12 @@ function factory(tree, options) { }); } - h.dangerous = dangerous; - h.definition = definitions(tree); - h.footnotes = []; - h.augment = augment; - - visit(tree, 'footnoteDefinition', function (definition) { + function visitor(definition) { h.footnotes.push(definition); - }); - - return h; + } } -/** - * Transform `tree`, which is an MDAST node, to a HAST node. - * - * @param {Node} tree - MDAST Node. - * @param {Object} [options] - Configuration. - * @return {Node} - HAST Node. - */ +/* Transform `tree`, which is an MDAST node, to a HAST node. */ function toHAST(tree, options) { var h = factory(tree, options); var node = one(h, tree); diff --git a/lib/one.js b/lib/one.js index 8a907a5..230c306 100644 --- a/lib/one.js +++ b/lib/one.js @@ -1,31 +1,13 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:one - * @fileoverview Transform one MDAST node. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Expose. */ module.exports = one; -/* Dependencies. */ var u = require('unist-builder'); var has = require('has'); var all = require('./all'); var handlers = require('./handlers'); -/** - * Transform an unknown node. - * - * @param {Function} h - Hyperscript DSL. - * @param {Node} node - Node to compile. - * @return {Node} - HAST node. - */ +/* Transform an unknown node. */ function unknown(h, node) { if ('value' in node) { return h.augment(node, u('text', node.value)); @@ -34,15 +16,7 @@ function unknown(h, node) { return h(node, 'div', all(h, node)); } -/** - * Visit a node. - * - * @param {Function} h - Hyperscript DSL. - * @param {Object} node - Node. - * @param {Object?} [parent] - `node`s parent. - * @return {Node} - HAST node. - * @throws {Error} - When `node` is not an MDAST node. - */ +/* Visit a node. */ function one(h, node, parent) { var type = node && node.type; var fn = has(handlers, type) ? handlers[type] : null; diff --git a/lib/wrap.js b/lib/wrap.js index d5a0b7a..a35e9f1 100644 --- a/lib/wrap.js +++ b/lib/wrap.js @@ -1,30 +1,11 @@ -/** - * @author Titus Wormer - * @copyright 2015 Titus Wormer - * @license MIT - * @module mdast:to-hast:wrap - * @fileoverview Wrap a list of nodes in white-space. - */ - 'use strict'; -/* eslint-env commonjs */ - -/* Expose. */ module.exports = wrap; -/* Dependencies. */ var u = require('unist-builder'); -/** - * Wrap `nodes` with newlines between each entry. - * Optionally adds newlines at the start and end. - * - * @param {Array.} nodes - Nodes to wrap. - * @param {boolean} loose - Whether to inject newlines at - * the start, and end (in case nodes has entries). - * @return {Array.} - Wrapped nodes. - */ +/* Wrap `nodes` with newlines between each entry. + * Optionally adds newlines at the start and end. */ function wrap(nodes, loose) { var result = []; var index = -1; @@ -42,7 +23,7 @@ function wrap(nodes, loose) { result.push(nodes[index]); } - if (loose && nodes.length) { + if (loose && nodes.length !== 0) { result.push(u('text', '\n')); } diff --git a/test/blockquote.js b/test/blockquote.js index a8eb756..776fc23 100644 --- a/test/blockquote.js +++ b/test/blockquote.js @@ -1,21 +1,9 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module mdast-util-to-hast - * @fileoverview Test suite for `mdast-util-to-hast`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var u = require('unist-builder'); var to = require('..'); -/* Tests. */ test('Blockquote', function (t) { t.deepEqual( to(u('blockquote', [ diff --git a/test/break.js b/test/break.js index 7a70e3a..ffef2c0 100644 --- a/test/break.js +++ b/test/break.js @@ -1,21 +1,9 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module mdast-util-to-hast - * @fileoverview Test suite for `mdast-util-to-hast`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var u = require('unist-builder'); var to = require('..'); -/* Tests. */ test('Break', function (t) { t.deepEqual( to(u('paragraph', [ diff --git a/test/code.js b/test/code.js index 68b3374..ae91f43 100644 --- a/test/code.js +++ b/test/code.js @@ -1,21 +1,9 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module mdast-util-to-hast - * @fileoverview Test suite for `mdast-util-to-hast`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var u = require('unist-builder'); var to = require('..'); -/* Tests. */ test('Code', function (t) { t.deepEqual( to(u('code', 'foxtrot()\ngolf.hotel()')), diff --git a/test/core.js b/test/core.js index 81d6b92..4c6421e 100644 --- a/test/core.js +++ b/test/core.js @@ -1,21 +1,9 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module mdast-util-to-hast - * @fileoverview Test suite for `mdast-util-to-hast`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var u = require('unist-builder'); var to = require('..'); -/* Tests. */ test('toHAST()', function (t) { t.throws( function () { diff --git a/test/definition.js b/test/definition.js index 112040b..7bd5d02 100644 --- a/test/definition.js +++ b/test/definition.js @@ -1,21 +1,9 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module mdast-util-to-hast - * @fileoverview Test suite for `mdast-util-to-hast`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var u = require('unist-builder'); var to = require('..'); -/* Tests. */ test('Definition', function (t) { t.equal( to(u('definition', { diff --git a/test/delete.js b/test/delete.js index 5be98ce..a53dc2f 100644 --- a/test/delete.js +++ b/test/delete.js @@ -1,21 +1,9 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module mdast-util-to-hast - * @fileoverview Test suite for `mdast-util-to-hast`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var u = require('unist-builder'); var to = require('..'); -/* Tests. */ test('Delete', function (t) { t.deepEqual( to(u('delete', [u('text', 'foxtrot')])), diff --git a/test/emphasis.js b/test/emphasis.js index ea2f8e9..07a0ee0 100644 --- a/test/emphasis.js +++ b/test/emphasis.js @@ -1,21 +1,9 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module mdast-util-to-hast - * @fileoverview Test suite for `mdast-util-to-hast`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var u = require('unist-builder'); var to = require('..'); -/* Tests. */ test('Emphasis', function (t) { t.deepEqual( to(u('emphasis', [u('text', 'delta')])), diff --git a/test/footnote-definition.js b/test/footnote-definition.js index 84355da..fae9588 100644 --- a/test/footnote-definition.js +++ b/test/footnote-definition.js @@ -1,21 +1,9 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module mdast-util-to-hast - * @fileoverview Test suite for `mdast-util-to-hast`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var u = require('unist-builder'); var to = require('..'); -/* Tests. */ test('FootnoteDefinition', function (t) { t.equal( to(u('footnoteDefinition', { diff --git a/test/footnote-reference.js b/test/footnote-reference.js index 5ddfc47..20caa5c 100644 --- a/test/footnote-reference.js +++ b/test/footnote-reference.js @@ -1,21 +1,9 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module mdast-util-to-hast - * @fileoverview Test suite for `mdast-util-to-hast`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var u = require('unist-builder'); var to = require('..'); -/* Tests. */ test('FootnoteReference', function (t) { t.deepEqual( to(u('footnoteReference', { diff --git a/test/footnote.js b/test/footnote.js index ec50a13..a801a8b 100644 --- a/test/footnote.js +++ b/test/footnote.js @@ -1,21 +1,9 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module mdast-util-to-hast - * @fileoverview Test suite for `mdast-util-to-hast`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var u = require('unist-builder'); var to = require('..'); -/* Tests. */ test('Footnote', function (t) { t.deepEqual( to(u('root', [ diff --git a/test/heading.js b/test/heading.js index ed88c74..7c2fd24 100644 --- a/test/heading.js +++ b/test/heading.js @@ -1,21 +1,9 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module mdast-util-to-hast - * @fileoverview Test suite for `mdast-util-to-hast`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var u = require('unist-builder'); var to = require('..'); -/* Tests. */ test('Heading', function (t) { t.deepEqual( to(u('heading', {depth: 4}, [u('text', 'echo')])), diff --git a/test/html.js b/test/html.js index 14140cc..8b6b76d 100644 --- a/test/html.js +++ b/test/html.js @@ -1,21 +1,9 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module mdast-util-to-hast - * @fileoverview Test suite for `mdast-util-to-hast`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var u = require('unist-builder'); var to = require('..'); -/* Tests. */ test('HTML', function (t) { t.equal( to(u('html', '')), diff --git a/test/image-reference.js b/test/image-reference.js index e8e5770..85d1162 100644 --- a/test/image-reference.js +++ b/test/image-reference.js @@ -1,21 +1,9 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module mdast-util-to-hast - * @fileoverview Test suite for `mdast-util-to-hast`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var u = require('unist-builder'); var to = require('..'); -/* Tests. */ test('ImageReference', function (t) { t.deepEqual( to(u('imageReference', { diff --git a/test/image.js b/test/image.js index f0258c8..6f89baf 100644 --- a/test/image.js +++ b/test/image.js @@ -1,21 +1,9 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module mdast-util-to-hast - * @fileoverview Test suite for `mdast-util-to-hast`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var u = require('unist-builder'); var to = require('..'); -/* Tests. */ test('Image', function (t) { t.deepEqual( to(u('image', { diff --git a/test/index.js b/test/index.js index 11bb540..d9e3227 100644 --- a/test/index.js +++ b/test/index.js @@ -1,12 +1,7 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module mdast-util-to-hast - * @fileoverview Test suite for `mdast-util-to-hast`. - */ +'use strict'; + +/* eslint-disable import/no-unassigned-import */ -/* Subtests */ require('./core.js'); require('./blockquote.js'); require('./break.js'); diff --git a/test/inline-code.js b/test/inline-code.js index e0efe05..b7afdbd 100644 --- a/test/inline-code.js +++ b/test/inline-code.js @@ -1,21 +1,9 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module mdast-util-to-hast - * @fileoverview Test suite for `mdast-util-to-hast`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var u = require('unist-builder'); var to = require('..'); -/* Tests. */ test('InlineCode', function (t) { t.deepEqual( to(u('inlineCode', 'juliett()')), diff --git a/test/link-reference.js b/test/link-reference.js index 45c2805..d8c7858 100644 --- a/test/link-reference.js +++ b/test/link-reference.js @@ -1,21 +1,9 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module mdast-util-to-hast - * @fileoverview Test suite for `mdast-util-to-hast`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var u = require('unist-builder'); var to = require('..'); -/* Tests. */ test('LinkReference', function (t) { t.deepEqual( to(u('linkReference', { diff --git a/test/link.js b/test/link.js index 75b8812..2cd6d50 100644 --- a/test/link.js +++ b/test/link.js @@ -1,21 +1,9 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module mdast-util-to-hast - * @fileoverview Test suite for `mdast-util-to-hast`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var u = require('unist-builder'); var to = require('..'); -/* Tests. */ test('Link', function (t) { t.deepEqual( to(u('link', { diff --git a/test/list-item.js b/test/list-item.js index 4fc200a..0aba982 100644 --- a/test/list-item.js +++ b/test/list-item.js @@ -1,16 +1,5 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module mdast-util-to-hast - * @fileoverview Test suite for `mdast-util-to-hast`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var u = require('unist-builder'); var to = require('..'); diff --git a/test/list.js b/test/list.js index df973cf..6d74d95 100644 --- a/test/list.js +++ b/test/list.js @@ -1,21 +1,9 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module mdast-util-to-hast - * @fileoverview Test suite for `mdast-util-to-hast`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var u = require('unist-builder'); var to = require('..'); -/* Tests. */ test('List', function (t) { t.deepEqual( to(u('list', {ordered: true}, [ diff --git a/test/paragraph.js b/test/paragraph.js index 961bdd6..02dcadb 100644 --- a/test/paragraph.js +++ b/test/paragraph.js @@ -1,21 +1,9 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module mdast-util-to-hast - * @fileoverview Test suite for `mdast-util-to-hast`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var u = require('unist-builder'); var to = require('..'); -/* Tests. */ test('Paragraph', function (t) { t.deepEqual( to(u('paragraph', [u('text', 'bravo')])), diff --git a/test/root.js b/test/root.js index 0d21ef2..8b22554 100644 --- a/test/root.js +++ b/test/root.js @@ -1,21 +1,9 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module mdast-util-to-hast - * @fileoverview Test suite for `mdast-util-to-hast`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var u = require('unist-builder'); var to = require('..'); -/* Tests. */ test('Root', function (t) { t.deepEqual( to(u('root', [])), diff --git a/test/strong.js b/test/strong.js index a8dd061..390d052 100644 --- a/test/strong.js +++ b/test/strong.js @@ -1,21 +1,9 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module mdast-util-to-hast - * @fileoverview Test suite for `mdast-util-to-hast`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var u = require('unist-builder'); var to = require('..'); -/* Tests. */ test('Strong', function (t) { t.deepEqual( to(u('strong', [u('text', 'echo')])), diff --git a/test/table.js b/test/table.js index dcad19a..a975079 100644 --- a/test/table.js +++ b/test/table.js @@ -1,21 +1,9 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module mdast-util-to-hast - * @fileoverview Test suite for `mdast-util-to-hast`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var u = require('unist-builder'); var to = require('..'); -/* Tests. */ test('Table', function (t) { t.deepEqual( to(u('table', {align: ['left', 'right']}, [ diff --git a/test/text.js b/test/text.js index 414f4ee..000da1f 100644 --- a/test/text.js +++ b/test/text.js @@ -1,21 +1,9 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module mdast-util-to-hast - * @fileoverview Test suite for `mdast-util-to-hast`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var u = require('unist-builder'); var to = require('..'); -/* Tests. */ test('Nodes', function (t) { t.deepEqual( to(u('text', 'alpha')), diff --git a/test/thematic-break.js b/test/thematic-break.js index 4f8fd5d..0c6c1a0 100644 --- a/test/thematic-break.js +++ b/test/thematic-break.js @@ -1,21 +1,9 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module mdast-util-to-hast - * @fileoverview Test suite for `mdast-util-to-hast`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var u = require('unist-builder'); var to = require('..'); -/* Tests. */ test('ThematicBreak', function (t) { t.deepEqual( to(u('thematicBreak')), diff --git a/test/yaml.js b/test/yaml.js index a27dbd2..26d59cc 100644 --- a/test/yaml.js +++ b/test/yaml.js @@ -1,21 +1,9 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module mdast-util-to-hast - * @fileoverview Test suite for `mdast-util-to-hast`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var u = require('unist-builder'); var to = require('..'); -/* Tests. */ test('YAML', function (t) { t.equal( to(u('yaml', 'kilo: "lima"')),