diff --git a/package.json b/package.json index 301d76d..7c59526 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "save-my-chatbot", - "version": "3.2.6", + "version": "3.4.0", "license": "RMD-C v1.0 License", "author": "Hugo COLLIN", "homepage": "https://save.hugocollin.com", diff --git a/public/files/updateNotes.md b/public/files/updateNotes.md index 17c5fd7..bda1762 100644 --- a/public/files/updateNotes.md +++ b/public/files/updateNotes.md @@ -1,8 +1,12 @@ # Update notes -# 3.3.0 -🐞 Facilitating bug reports -When an error occurs during the export process, a modal will appear inviting you report the bug. -Plus, an option is available in the icon context menu. +# 3.4.0 +🔢 Export math equations +LaTeX equations from Perplexity, ChatGPT and Phind are now correctly formatted! +Math lovers, enjoy! + +🐞 Facilitating bug reports (or feature requests 🚀) +When an error occurs during the export process, a modal will invite you to report the bug. +Plus, a new option is available in the icon context menu. # 3.2.6 🧩 Some bug fixes diff --git a/src/scripts/content/export/extractor/domains/ChatGPT.json b/src/scripts/content/export/extractor/domains/ChatGPT.json index 8d08971..f5c1ddb 100644 --- a/src/scripts/content/export/extractor/domains/ChatGPT.json +++ b/src/scripts/content/export/extractor/domains/ChatGPT.json @@ -21,6 +21,10 @@ "formatTables": { "filter": "filter_formatTables", "replacement": "replacement_formatTables" + }, + "formatKatex": { + "filter": "filter_formatKatex", + "replacement": "replacement_formatKatex" } } }, diff --git a/src/scripts/content/export/extractor/domains/Perplexity.json b/src/scripts/content/export/extractor/domains/Perplexity.json index 2cb1db0..c2cedf7 100644 --- a/src/scripts/content/export/extractor/domains/Perplexity.json +++ b/src/scripts/content/export/extractor/domains/Perplexity.json @@ -20,6 +20,10 @@ "formatTables": { "filter": "filter_formatTables", "replacement": "replacement_formatTables" + }, + "formatKatex": { + "filter": "filter_formatKatex", + "replacement": "replacement_formatKatex" } } }, diff --git a/src/scripts/content/export/extractor/domains/PerplexityPages.json b/src/scripts/content/export/extractor/domains/PerplexityPages.json index 90ae1d1..dd839d9 100644 --- a/src/scripts/content/export/extractor/domains/PerplexityPages.json +++ b/src/scripts/content/export/extractor/domains/PerplexityPages.json @@ -20,6 +20,10 @@ "formatTables": { "filter": "filter_formatTables", "replacement": "replacement_formatTables" + }, + "formatKatex": { + "filter": "filter_formatKatex", + "replacement": "replacement_formatKatex" } } }, diff --git a/src/scripts/content/export/extractor/domains/PhindChat.json b/src/scripts/content/export/extractor/domains/PhindChat.json index f526697..18ee833 100644 --- a/src/scripts/content/export/extractor/domains/PhindChat.json +++ b/src/scripts/content/export/extractor/domains/PhindChat.json @@ -25,6 +25,10 @@ "formatTables": { "filter": "filter_formatTables", "replacement": "replacement_formatTables" + }, + "formatKatex": { + "filter": "filter_formatKatex", + "replacement": "replacement_formatKatex" } } }, diff --git a/src/scripts/content/export/extractor/domains/PhindSearch.json b/src/scripts/content/export/extractor/domains/PhindSearch.json index fe66008..a1aaf94 100644 --- a/src/scripts/content/export/extractor/domains/PhindSearch.json +++ b/src/scripts/content/export/extractor/domains/PhindSearch.json @@ -21,6 +21,10 @@ "formatTables": { "filter": "filter_formatTables", "replacement": "replacement_formatTables" + }, + "formatKatex": { + "filter": "filter_formatKatex", + "replacement": "replacement_formatKatex" } } }, diff --git a/src/scripts/content/export/extractor/rules/rules.js b/src/scripts/content/export/extractor/rules/rules.js index 2e99966..8871d3b 100644 --- a/src/scripts/content/export/extractor/rules/rules.js +++ b/src/scripts/content/export/extractor/rules/rules.js @@ -153,6 +153,32 @@ export function replacement_formatBeforeLinks(content, node) { return content.trim(); } +/* + --- Format KateX --- + */ + +export function filter_formatKatex(node) { + return node.nodeName === 'SPAN' && node.classList.contains('katex'); +} + +export function replacement_formatKatex(content, node) { + // Cannot just select "math annotation" as it's missing in the node children (but rendered in the node.textContent !?!?) + const mrow = node.querySelector("math mrow")?.textContent ?? ""; + const htmlMath = node.querySelector(".katex-html")?.textContent ?? ""; + + // Remove mrow at start and htmlMath at end of node.textContent + const mathml = node.textContent + ?.replace(mrow, "") + .replace(htmlMath, "") + .trim() + ?? node.textContent; + + if (node.parentNode?.classList.contains('katex-display')) { + return '\n$$' + mathml + '$$\n'; + } + return '$' + mathml + '$'; +} + /* --- Phind rules --- */