aboutsummaryrefslogtreecommitdiff
path: root/lib/raw-text.js
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2021-08-01 10:45:01 +0100
committerMichael Williamson <mike@zwobble.org>2021-08-01 10:45:01 +0100
commit8e88d605ae84ff3a55baf6a8c881d102e9ea1045 (patch)
treeb2f6cf39c97bdeb4c7e359175f6a22256c841b10 /lib/raw-text.js
parente82bdbdd8ac45f41839889188be9455100a1c17d (diff)
Extract raw-text module
Diffstat (limited to 'lib/raw-text.js')
-rw-r--r--lib/raw-text.js10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/raw-text.js b/lib/raw-text.js
new file mode 100644
index 0000000..da9a640
--- /dev/null
+++ b/lib/raw-text.js
@@ -0,0 +1,10 @@
+function convertElementToRawText(element) {
+ if (element.type === "text") {
+ return element.value;
+ } else {
+ var tail = element.type === "paragraph" ? "\n\n" : "";
+ return (element.children || []).map(convertElementToRawText).join("") + tail;
+ }
+}
+
+exports.convertElementToRawText = convertElementToRawText;