word/edit: story column to store text descriptions
[sheet.git] / writer.js
index ebace02f376569c53a99f00a0ce6f342b5a51b4c..a958732274c5e43ecff87c2fe8c95ff16428a54a 100644 (file)
--- a/writer.js
+++ b/writer.js
@@ -36,10 +36,21 @@ document.addEventListener('DOMContentLoaded', () => {
                                        });
                                });
 
+                               // copy first paragraph to story
+                               let wptext = json.parse.text['*'];
+                               let storyinput = document.getElementById('story');
+                               if (storyinput && wptext) {
+                                       storyinput.innerHTML = wptext
+                                               .replace(/<h2.*/s, '') // prefix
+                                               .replace(/<table.*?<\/table>/sg, '') // ignore infobox
+                                               .match(/<p>(.*?)<\/p>/s)[0] // first paragraph
+                                               .replace(/<[^>]*>/g, '') // strip html tags
+                               }
+
                                // list images in article html
                                let imginput = document.getElementById('source');
                                if (!imginput || imginput.value) return;
-                               let wpimages = json.parse.text['*'].match(/<img\s[^>]+>/g);
+                               let wpimages = wptext.match(/<img\s[^>]+>/g);
                                let wpselect = wpinput.parentNode.appendChild(document.createElement('ul'));
                                wpselect.className = 'popup';
                                wpimages.forEach(img => {