aboutsummaryrefslogtreecommitdiff
path: root/lib/docx
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2024-11-30 11:20:20 +0000
committerMichael Williamson <mike@zwobble.org>2024-11-30 11:20:20 +0000
commit3751195339954f49f525446de0795d2acad2c234 (patch)
treefb177eed0d2ad356f438cbfb35ff045760c87f0e /lib/docx
parentf79db6f1dd40c5ff0325e2a5ea4d99485ce18bf4 (diff)
Read complex field checkboxes, always unchecked
Diffstat (limited to 'lib/docx')
-rw-r--r--lib/docx/body-reader.js25
1 files changed, 16 insertions, 9 deletions
diff --git a/lib/docx/body-reader.js b/lib/docx/body-reader.js
index 28bd2ef..a4a6c0c 100644
--- a/lib/docx/body-reader.js
+++ b/lib/docx/body-reader.js
@@ -165,10 +165,12 @@ function BodyReader(options) {
complexFieldStack.push(unknownComplexField);
currentInstrText = [];
} else if (type === "end") {
- complexFieldStack.pop();
+ var complexFieldEnd = complexFieldStack.pop();
+ if (complexFieldEnd.type === "checkbox") {
+ return elementResult(documents.checkbox({checked: false}));
+ }
} else if (type === "separate") {
- var hyperlinkOptions = parseHyperlinkFieldCode(currentInstrText.join(''));
- var complexField = hyperlinkOptions === null ? unknownComplexField : {type: "hyperlink", options: hyperlinkOptions};
+ var complexField = parseInstrText(currentInstrText.join(''));
complexFieldStack.pop();
complexFieldStack.push(complexField);
}
@@ -182,18 +184,23 @@ function BodyReader(options) {
return topHyperlink ? topHyperlink.options : null;
}
- function parseHyperlinkFieldCode(code) {
- var externalLinkResult = /\s*HYPERLINK "(.*)"/.exec(code);
+ function parseInstrText(instrText) {
+ var externalLinkResult = /\s*HYPERLINK "(.*)"/.exec(instrText);
if (externalLinkResult) {
- return {href: externalLinkResult[1]};
+ return {type: "hyperlink", options: {href: externalLinkResult[1]}};
}
- var internalLinkResult = /\s*HYPERLINK\s+\\l\s+"(.*)"/.exec(code);
+ var internalLinkResult = /\s*HYPERLINK\s+\\l\s+"(.*)"/.exec(instrText);
if (internalLinkResult) {
- return {anchor: internalLinkResult[1]};
+ return {type: "hyperlink", options: {anchor: internalLinkResult[1]}};
+ }
+
+ var checkboxResult = /\s*FORMCHECKBOX\s*/.exec(instrText);
+ if (checkboxResult) {
+ return {type: "checkbox"};
}
- return null;
+ return unknownComplexField;
}
function readInstrText(element) {