From 83221c31324d2d248d3c613f1142961f5b1c4c3d Mon Sep 17 00:00:00 2001 From: Aditya Date: Tue, 2 Dec 2025 23:45:55 +0530 Subject: [PATCH] fix: logic to construct SVG --- static/share.js | 63 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/static/share.js b/static/share.js index 7591233..359aa7d 100644 --- a/static/share.js +++ b/static/share.js @@ -25,11 +25,66 @@ async function screenshotDOM(el, opts = {}) { if (background !== 'transparent') clone.style.background = background; if (!clone.getAttribute('xmlns')) clone.setAttribute('xmlns', 'http://www.w3.org/1999/xhtml'); + const word = el.querySelector("h3").textContent.trim(); + const phonetic = el.querySelector(".pronun").textContent.trim(); + const [types, ...defs] = [...el.querySelectorAll("ol.defs li")].map(node => node.textContent.trim()); - const xhtml = new XMLSerializer().serializeToString(clone); - const svg = ` - ${xhtml} - `; + const vOffset = 48; + const svg = ` + + + + + + + + + + ${word} + + + ${phonetic} + + + ${types} + + + ${defs.map((def, idx) => ` + ${idx + 1}. + ${def} + `)} + + + `; const svgBlob = new Blob([svg], { type: 'image/svg+xml;charset=utf-8' }); const url = URL.createObjectURL(svgBlob);