diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-09-18 10:50:23 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-09-18 10:50:23 +0100 |
| commit | ca39228d7235ce0d498d47819a1779b62ceeaa54 (patch) | |
| tree | 6198a6d95042e44e63094203d83ea17571d216d8 /lib | |
| parent | 58a6c62fc9f4b8c775216db2b54ba211648fb929 (diff) | |
Distinguish context from options in document-to-html
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/document-to-html.js | 78 |
1 files changed, 39 insertions, 39 deletions
diff --git a/lib/document-to-html.js b/lib/document-to-html.js index 9e85c8e..0cd5a8f 100644 --- a/lib/document-to-html.js +++ b/lib/document-to-html.js @@ -80,27 +80,27 @@ function DocumentConversion(options, comments) { }); } - function convertElements(elements, messages, options) { + function convertElements(elements, messages, context) { return flatMap(elements, function(element) { - return elementToHtml(element, messages, options); + return elementToHtml(element, messages, context); }); } - function elementToHtml(element, messages, options) { - if (!options) { - throw new Error("options not set"); + function elementToHtml(element, messages, context) { + if (!context) { + throw new Error("context not set"); } var handler = elementConverters[element.type]; if (handler) { - return handler(element, messages, options); + return handler(element, messages, context); } else { return []; } } - function convertParagraph(element, messages, options) { + function convertParagraph(element, messages, context) { return htmlPathForParagraph(element, messages).wrap(function() { - var content = convertElements(element.children, messages, options); + var content = convertElements(element.children, messages, context); if (ignoreEmptyParagraphs) { return content; } else { @@ -122,9 +122,9 @@ function DocumentConversion(options, comments) { } } - function convertRun(run, messages, options) { + function convertRun(run, messages, context) { var nodes = function() { - return convertElements(run.children, messages, options); + return convertElements(run.children, messages, context); }; var paths = []; if (run.highlight !== null) { @@ -232,13 +232,13 @@ function DocumentConversion(options, comments) { htmlPaths.element("table", {}, {fresh: true}) ]); - function convertTable(element, messages, options) { + function convertTable(element, messages, context) { return findHtmlPath(element, defaultTablePath).wrap(function() { - return convertTableChildren(element, messages, options); + return convertTableChildren(element, messages, context); }); } - function convertTableChildren(element, messages, options) { + function convertTableChildren(element, messages, context) { var bodyIndex = _.findIndex(element.children, function(child) { return !child.type === documents.types.tableRow || !child.isHeader; }); @@ -250,18 +250,18 @@ function DocumentConversion(options, comments) { children = convertElements( element.children, messages, - _.extend({}, options, {isTableHeader: false}) + _.extend({}, context, {isTableHeader: false}) ); } else { var headRows = convertElements( element.children.slice(0, bodyIndex), messages, - _.extend({}, options, {isTableHeader: true}) + _.extend({}, context, {isTableHeader: true}) ); var bodyRows = convertElements( element.children.slice(bodyIndex), messages, - _.extend({}, options, {isTableHeader: false}) + _.extend({}, context, {isTableHeader: false}) ); children = [ Html.freshElement("thead", {}, headRows), @@ -271,16 +271,16 @@ function DocumentConversion(options, comments) { return [Html.forceWrite].concat(children); } - function convertTableRow(element, messages, options) { - var children = convertElements(element.children, messages, options); + function convertTableRow(element, messages, context) { + var children = convertElements(element.children, messages, context); return [ Html.freshElement("tr", {}, [Html.forceWrite].concat(children)) ]; } - function convertTableCell(element, messages, options) { - var tagName = options.isTableHeader ? "th" : "td"; - var children = convertElements(element.children, messages, options); + function convertTableCell(element, messages, context) { + var tagName = context.isTableHeader ? "th" : "td"; + var children = convertElements(element.children, messages, context); var attributes = {}; if (element.colSpan !== 1) { attributes.colspan = element.colSpan.toString(); @@ -294,7 +294,7 @@ function DocumentConversion(options, comments) { ]; } - function convertCommentReference(reference, messages, options) { + function convertCommentReference(reference, messages, context) { return findHtmlPath(reference, htmlPaths.ignore).wrap(function() { var comment = comments[reference.commentId]; var count = referencedComments.length + 1; @@ -310,12 +310,12 @@ function DocumentConversion(options, comments) { }); } - function convertComment(referencedComment, messages, options) { + function convertComment(referencedComment, messages, context) { // TODO: remove duplication with note references var label = referencedComment.label; var comment = referencedComment.comment; - var body = convertElements(comment.body, messages, options).concat([ + var body = convertElements(comment.body, messages, context).concat([ Html.nonFreshElement("p", {}, [ Html.text(" "), Html.freshElement("a", {"href": "#" + referenceHtmlId("comment", comment.commentId)}, [ @@ -334,7 +334,7 @@ function DocumentConversion(options, comments) { ]; } - function convertBreak(element, messages, options) { + function convertBreak(element, messages, context) { return htmlPathForBreak(element).wrap(function() { return []; }); @@ -352,35 +352,35 @@ function DocumentConversion(options, comments) { } var elementConverters = { - "document": function(document, messages, options) { - var children = convertElements(document.children, messages, options); + "document": function(document, messages, context) { + var children = convertElements(document.children, messages, context); var notes = noteReferences.map(function(noteReference) { return document.notes.resolve(noteReference); }); - var notesNodes = convertElements(notes, messages, options); + var notesNodes = convertElements(notes, messages, context); return children.concat([ Html.freshElement("ol", {}, notesNodes), Html.freshElement("dl", {}, flatMap(referencedComments, function(referencedComment) { - return convertComment(referencedComment, messages, options); + return convertComment(referencedComment, messages, context); })) ]); }, "paragraph": convertParagraph, "run": convertRun, - "text": function(element, messages, options) { + "text": function(element, messages, context) { return [Html.text(element.value)]; }, - "tab": function(element, messages, options) { + "tab": function(element, messages, context) { return [Html.text("\t")]; }, - "hyperlink": function(element, messages, options) { + "hyperlink": function(element, messages, context) { var href = element.anchor ? "#" + htmlId(element.anchor) : element.href; var attributes = {href: href}; if (element.targetFrame != null) { attributes.target = element.targetFrame; } - var children = convertElements(element.children, messages, options); + var children = convertElements(element.children, messages, context); return [Html.nonFreshElement("a", attributes, children)]; }, "checkbox": function(element) { @@ -390,13 +390,13 @@ function DocumentConversion(options, comments) { } return [Html.freshElement("input", attributes)]; }, - "bookmarkStart": function(element, messages, options) { + "bookmarkStart": function(element, messages, context) { var anchor = Html.freshElement("a", { id: htmlId(element.name) }, [Html.forceWrite]); return [anchor]; }, - "noteReference": function(element, messages, options) { + "noteReference": function(element, messages, context) { noteReferences.push(element); var anchor = Html.freshElement("a", { href: "#" + noteHtmlId(element), @@ -405,8 +405,8 @@ function DocumentConversion(options, comments) { return [Html.freshElement("sup", {}, [anchor])]; }, - "note": function(element, messages, options) { - var children = convertElements(element.body, messages, options); + "note": function(element, messages, context) { + var children = convertElements(element.body, messages, context); var backLink = Html.elementWithTag(htmlPaths.element("p", {}, {fresh: false}), [ Html.text(" "), Html.freshElement("a", {href: "#" + noteRefHtmlId(element)}, [Html.text("↑")]) @@ -431,13 +431,13 @@ function DocumentConversion(options, comments) { var deferredId = 1; function deferredConversion(func) { - return function(element, messages, options) { + return function(element, messages, context) { return [ { type: "deferred", id: deferredId++, value: function() { - return func(element, messages, options); + return func(element, messages, context); } } ]; |
