diff options
| author | Michael Williamson <mike@zwobble.org> | 2017-05-30 11:32:40 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2017-05-30 11:32:40 +0100 |
| commit | 9545703e5e3cd3f0cbce363eda1d2c92e4eb0da0 (patch) | |
| tree | e437db3c8f4a10d98e79e72469cc16cfa1486795 | |
| parent | a9661689a03cdaf3590250a0bd7887f07aeafa7e (diff) | |
Convert hyperlink target frame to anchor target
| -rw-r--r-- | lib/document-to-html.js | 6 | ||||
| -rw-r--r-- | test/document-to-html.tests.js | 11 |
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/document-to-html.js b/lib/document-to-html.js index 93f9524..d0197cb 100644 --- a/lib/document-to-html.js +++ b/lib/document-to-html.js @@ -359,9 +359,13 @@ function DocumentConversion(options, comments) { }, "hyperlink": function(element, messages, options) { 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); - return [Html.freshElement("a", {href: href}, children)]; + return [Html.freshElement("a", attributes, children)]; }, "bookmarkStart": function(element, messages, options) { var anchor = Html.freshElement("a", { diff --git a/test/document-to-html.tests.js b/test/document-to-html.tests.js index a55f9a2..bf6631f 100644 --- a/test/document-to-html.tests.js +++ b/test/document-to-html.tests.js @@ -343,6 +343,17 @@ test('docx hyperlink with anchor is converted to <a>', function() { }); }); +test('hyperlink target frame is used as anchor target', function() { + var hyperlink = new documents.Hyperlink( + [runOfText("Hello.")], + {anchor: "start", targetFrame: "_blank"} + ); + var converter = new DocumentConverter(); + return converter.convertToHtml(hyperlink).then(function(result) { + assert.equal(result.value, '<a href="#start" target="_blank">Hello.</a>'); + }); +}); + test('bookmarks are converted to anchors', function() { var bookmarkStart = new documents.BookmarkStart({name: "_Peter"}); var converter = new DocumentConverter({ |
