From fbcdff3c7d718d33fd826dada5477ba975d636c7 Mon Sep 17 00:00:00 2001 From: Aaron Choo Date: Sun, 6 Sep 2020 21:19:58 +0800 Subject: [PATCH 1/5] chore: update test markdown --- markdown/test.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/markdown/test.md b/markdown/test.md index f73179d..98d7c3c 100644 --- a/markdown/test.md +++ b/markdown/test.md @@ -1,5 +1,5 @@ # For testing purposes -Following should not render properly: +Following *should not* render properly: -$\text{H}_h + X_\text{x}$ +Some text before, the math: $\text{H}_h + X_\text{x}$, and some *italics after*. From bb27f18ed79b16e170cf7811a6d8085d18d0cf23 Mon Sep 17 00:00:00 2001 From: Aaron Choo Date: Sun, 6 Sep 2020 22:10:29 +0800 Subject: [PATCH 2/5] chore: update test markdown --- markdown/test.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/markdown/test.md b/markdown/test.md index 98d7c3c..af63645 100644 --- a/markdown/test.md +++ b/markdown/test.md @@ -3,3 +3,13 @@ Following *should not* render properly: Some text before, the math: $\text{H}_h + X_\text{x}$, and some *italics after*. + +An `inline block` and $\text{H}_h + X_\text{x}$. + +```js +// test code block +test(); +``` + +- A list +- Another problematic $\text{H}_h + X_\text{x}$ From 5cd082b1e8385932c0a2b3090045b1f5d0e411d4 Mon Sep 17 00:00:00 2001 From: Aaron Choo Date: Sun, 6 Sep 2020 22:54:29 +0800 Subject: [PATCH 3/5] chore: add problematic math block to test --- markdown/test.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/markdown/test.md b/markdown/test.md index af63645..8d3c6be 100644 --- a/markdown/test.md +++ b/markdown/test.md @@ -6,6 +6,13 @@ Some text before, the math: $\text{H}_h + X_\text{x}$, and some *italics after*. An `inline block` and $\text{H}_h + X_\text{x}$. +$$ +\begin{aligned} +&\frac{C}{C^*} \leq \rho(n) \rightarrow \text{ for minimisation, } \rho(n) \geq 1 \\ +&\frac{C}{C^*} \geq \rho(n) \rightarrow \text{ for maximisation, } \rho(n) \leq 1 +\end{aligned} +$$ + ```js // test code block test(); From 17fab44cb62a5bec85d391671dd42162249d4191 Mon Sep 17 00:00:00 2001 From: Aaron Choo Date: Mon, 7 Sep 2020 09:36:22 +0800 Subject: [PATCH 4/5] feat: add working prototype of stripping em tags --- src/index.js | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 82adc69..6372d2b 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,41 @@ import renderMathInElement from "katex/dist/contrib/auto-render"; import { Messages } from "./utils/constants"; +function stripEmTags() { + const readme = document.getElementById("readme"); + + if (!readme) { + return; + } + + let pos = 0; + while (pos >= 0) { + console.log(pos); + // find first pos of "}" + pos = readme.innerHTML.indexOf("}", pos); + // replace "}" and "" after pos + readme.innerHTML = + readme.innerHTML.slice(0, pos) + + readme.innerHTML + .slice(pos) + .replace("}", "}_") + .replace("", "_"); + } + + pos = 0; + while (pos >= 0) { + // find first pos of "^" + pos = readme.innerHTML.indexOf("^", pos); + // replace "^" and "" after pos + readme.innerHTML = + readme.innerHTML.slice(0, pos) + + readme.innerHTML + .slice(pos) + .replace("^", "^*") + .replace("", "*"); + } +} + function renderMath() { const readme = document.getElementById("readme"); @@ -47,7 +82,9 @@ const readmeObserver = new MutationObserver((mutations) => { for (const addedNode of mutation.addedNodes) { if (addedNode.id === "readme") { console.log("readme dom change detected"); - return renderMath(); + stripEmTags(); + renderMath(); + return; // break from all loops } } } @@ -58,10 +95,12 @@ readmeObserver.observe(document.body, { childList: true, subtree: true }); chrome.runtime.onMessage.addListener((request) => { if (request.type === Messages.ROUTE_CHANGED) { console.log("route change detected"); + stripEmTags(); renderMath(); } }); // on initial page load console.log("initial page load detected"); +stripEmTags(); renderMath(); From 44b583c2b11f8e6e2d8a2d80093289e7a7717337 Mon Sep 17 00:00:00 2001 From: Aaron Choo Date: Mon, 7 Sep 2020 10:05:38 +0800 Subject: [PATCH 5/5] fix: remove console statement --- src/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/index.js b/src/index.js index 6372d2b..f168851 100644 --- a/src/index.js +++ b/src/index.js @@ -10,7 +10,6 @@ function stripEmTags() { let pos = 0; while (pos >= 0) { - console.log(pos); // find first pos of "}" pos = readme.innerHTML.indexOf("}", pos); // replace "}" and "" after pos