aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJonathan Lehman <jonathan.lehman91@gmail.com>2017-02-03 17:00:21 -0500
committerJonathan Lehman <jonathan.lehman91@gmail.com>2017-02-03 17:00:21 -0500
commitee0baa36779e3ae2f2da9abe7e1c1c83fdcdf8fb (patch)
tree8594358f5a542453c35c1083b875f9d8fce5ef6e /lib
parent15f4381cf54901895836551a30f66c0cee974a0c (diff)
Enable hyperlinks that are not defined with w:hyperlink
Diffstat (limited to 'lib')
-rw-r--r--lib/docx/body-reader.js32
1 files changed, 27 insertions, 5 deletions
diff --git a/lib/docx/body-reader.js b/lib/docx/body-reader.js
index 529d6f2..8e71aa6 100644
--- a/lib/docx/body-reader.js
+++ b/lib/docx/body-reader.js
@@ -6,6 +6,7 @@ var documents = require("../documents");
var Result = require("../results").Result;
var warning = require("../results").warning;
var uriToZipEntryName = require("./uris").uriToZipEntryName;
+var lastInstrText = null;
function BodyReader(options) {
@@ -133,14 +134,27 @@ function BodyReader(options) {
return readXmlElements(element.children)
.map(function(children) {
var properties = _.find(children, isRunProperties);
-
- return new documents.Run(
- children.filter(negate(isRunProperties)),
- properties
- );
+ var filteredChildren = children.filter(negate(isRunProperties));
+
+ if (properties && properties.styleName === 'Hyperlink' && lastInstrText) {
+ return new documents.Hyperlink(filteredChildren, {href: parseHyperlink(lastInstrText)});
+ }
+
+ return new documents.Run(filteredChildren, properties);
});
},
"w:rPr": readRunProperties,
+ "w:fldChar": function(element) {
+ var type = element.attributes["w:fldCharType"];
+ if (type === 'end') {
+ clearState();
+ }
+ return emptyResult();
+ },
+ "w:instrText": function(element) {
+ lastInstrText = (element.children[0] || {}).value || '';
+ return emptyResult();
+ },
"w:t": function(element) {
return elementResult(new documents.Text(element.text()));
},
@@ -491,3 +505,11 @@ function joinElements(first, second) {
function identity(value) {
return value;
}
+
+function clearState() {
+ lastInstrText = null;
+}
+
+function parseHyperlink(instrText) {
+ return (instrText.match(/HYPERLINK "(.*)"/) || [])[1];
+}