diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-02-09 20:44:09 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-02-09 20:54:02 +0000 |
| commit | 7a7d96213635a63986b45d74cb1c25bb834f9ca8 (patch) | |
| tree | ac9cc0068fe86682b94e08f63384ecf5e922a627 | |
| parent | dae5823ec141dd6e567a05f68db80efc5f728a08 (diff) | |
Include ID prefix when generating IDs for internal links
| -rw-r--r-- | lib/document-to-html.js | 14 | ||||
| -rw-r--r-- | tests/document-to-html.tests.js | 12 |
2 files changed, 17 insertions, 9 deletions
diff --git a/lib/document-to-html.js b/lib/document-to-html.js index 579a11b..8a6e080 100644 --- a/lib/document-to-html.js +++ b/lib/document-to-html.js @@ -147,11 +147,15 @@ function DocumentConversion(options) { }); function noteHtmlId(note) { - return idPrefix + "-" + note.noteType + "-" + note.noteId; + return htmlId(note.noteType + "-" + note.noteId); } function noteRefHtmlId(note) { - return idPrefix + "-" + note.noteType + "-ref-" + note.noteId; + return htmlId(note.noteType + "-ref-" + note.noteId); + } + + function htmlId(suffix) { + return idPrefix + "-" + suffix; } function convertTable(element, html, messages, callback) { @@ -234,7 +238,7 @@ function DocumentConversion(options) { callback(); }, "hyperlink": function(element, html, messages, callback) { - var href = element.anchor ? "#" + element.anchor : element.href; + var href = element.anchor ? "#" + htmlId(element.anchor) : element.href; html.open(htmlPaths.element("a", {href: href})); convertElements(element.children, html, messages, function(err) { @@ -284,8 +288,8 @@ function DocumentConversion(options) { callback(); }, "bookmarkStart": function(element, html, messages, callback) { - html.open(htmlPaths.element("span", { - id: element.name + html.open(htmlPaths.element("a", { + id: htmlId(element.name) }), {alwaysWrite: true}); html.close(); callback(); diff --git a/tests/document-to-html.tests.js b/tests/document-to-html.tests.js index 46f5649..cb2b3d3 100644 --- a/tests/document-to-html.tests.js +++ b/tests/document-to-html.tests.js @@ -245,9 +245,11 @@ describe('DocumentConverter', function() { [runOfText("Hello.")], {anchor: "_Peter"} ); - var converter = new DocumentConverter(); + var converter = new DocumentConverter({ + idPrefix: "doc-42" + }); return converter.convertToHtml(hyperlink).then(function(result) { - assert.equal(result.value, '<a href="#_Peter">Hello.</a>'); + assert.equal(result.value, '<a href="#doc-42-_Peter">Hello.</a>'); }); }); @@ -423,10 +425,12 @@ describe('DocumentConverter', function() { [runOfText("Hello.")], {anchor: "_Peter"} ); - var converter = new DocumentConverter(); + var converter = new DocumentConverter({ + idPrefix: "doc-42" + }); var document = new documents.Document([bookmarkStart, hyperlink]); return converter.convertToHtml(document).then(function(result) { - assert.equal(result.value, '<span id="_Peter"></span><a href="#_Peter">Hello.</a>'); + assert.equal(result.value, '<a id="doc-42-_Peter"></a><a href="#doc-42-_Peter">Hello.</a>'); }); }); }); |
