diff options
| author | Jonathan Lehman <jonathan.lehman91@gmail.com> | 2017-02-17 12:35:26 -0500 |
|---|---|---|
| committer | Jonathan Lehman <jonathan.lehman91@gmail.com> | 2017-02-17 12:35:26 -0500 |
| commit | c044f44f404bb4e38d38082d2989c5686604bb3e (patch) | |
| tree | 3bd786e0bbdbcca1448fedd3ea6922d072e3cb3f /lib | |
| parent | 75e327ddfff69d7bdbaff994e4662f7c37cc2b85 (diff) | |
Handle nested complex fields
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/docx/body-reader.js | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/lib/docx/body-reader.js b/lib/docx/body-reader.js index 9345e02..e671f53 100644 --- a/lib/docx/body-reader.js +++ b/lib/docx/body-reader.js @@ -20,7 +20,7 @@ function createBodyReader(options) { } function BodyReader(options) { - var fieldHyperlink = null; + var fieldHyperlinks = []; var currentInstrText = []; var relationships = options.relationships; var contentTypes = options.contentTypes; @@ -148,8 +148,9 @@ function BodyReader(options) { var properties = _.find(children, isRunProperties); children = children.filter(negate(isRunProperties)); - if (fieldHyperlink !== null) { - children = [new documents.Hyperlink(children, {href: fieldHyperlink})]; + var validFieldHyperlinks = _.compact(fieldHyperlinks); + if (validFieldHyperlinks.length !== 0) { + children = [new documents.Hyperlink(children, {href: _.last(validFieldHyperlinks)})]; } return new documents.Run(children, properties); @@ -159,12 +160,10 @@ function BodyReader(options) { "w:fldChar": function(element) { var type = element.attributes["w:fldCharType"]; if (type === "end") { - fieldHyperlink = null; + fieldHyperlinks.pop(); } else if (type === "separate") { var hyperlink = parseHyperlinkFieldCode(currentInstrText.join('')); - if (hyperlink !== null) { - fieldHyperlink = hyperlink; - } + fieldHyperlinks.push(hyperlink); currentInstrText = []; } return emptyResult(); |
