From ce02a30441daba0a6f6c2a0eb1ae3874f7a87c86 Mon Sep 17 00:00:00 2001
From: Subhra264 <59690052+Subhra264@users.noreply.github.com>
Date: Tue, 8 Jun 2021 23:53:10 +0530
Subject: [PATCH] Desktop, Mobile: Fixes #5025: Inline Katex gets broken when
editing in Rich Text editor (#5052)
---
packages/app-cli/tests/html_to_md/joplin_source_1.html | 2 +-
packages/app-cli/tests/html_to_md/joplin_source_1.md | 2 +-
packages/app-cli/tests/html_to_md/joplin_source_2.html | 9 ++++++++-
packages/app-cli/tests/html_to_md/joplin_source_2.md | 4 +++-
packages/turndown/src/commonmark-rules.js | 6 +++++-
5 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/packages/app-cli/tests/html_to_md/joplin_source_1.html b/packages/app-cli/tests/html_to_md/joplin_source_1.html
index b063e72627..42ab20a731 100644
--- a/packages/app-cli/tests/html_to_md/joplin_source_1.html
+++ b/packages/app-cli/tests/html_to_md/joplin_source_1.html
@@ -1 +1 @@
-katexcode
f(x)=∫−∞∞f^(ξ)e2πiξxdξ
\ No newline at end of file
+
Hello World:katexcodef(x)=∫−∞∞f^(ξ)e2πiξxdξ
\ No newline at end of file
diff --git a/packages/app-cli/tests/html_to_md/joplin_source_1.md b/packages/app-cli/tests/html_to_md/joplin_source_1.md
index 5e53b8c9dc..e02891356c 100644
--- a/packages/app-cli/tests/html_to_md/joplin_source_1.md
+++ b/packages/app-cli/tests/html_to_md/joplin_source_1.md
@@ -1 +1 @@
-$katexcode$
\ No newline at end of file
+Hello World:$katexcode$
\ No newline at end of file
diff --git a/packages/app-cli/tests/html_to_md/joplin_source_2.html b/packages/app-cli/tests/html_to_md/joplin_source_2.html
index 92b3e00f28..9f8d1a8575 100644
--- a/packages/app-cli/tests/html_to_md/joplin_source_2.html
+++ b/packages/app-cli/tests/html_to_md/joplin_source_2.html
@@ -1 +1,8 @@
-katexcode
f(x)=∫−∞∞f^(ξ)e2πiξxdξ
\ No newline at end of file
+Hello World :
+
+
\sqrt{3x}
+
f(x)=∫−∞∞f^(ξ)e2πiξxdξ
+
\ No newline at end of file
diff --git a/packages/app-cli/tests/html_to_md/joplin_source_2.md b/packages/app-cli/tests/html_to_md/joplin_source_2.md
index 3cca001b07..c2fa4e6b08 100644
--- a/packages/app-cli/tests/html_to_md/joplin_source_2.md
+++ b/packages/app-cli/tests/html_to_md/joplin_source_2.md
@@ -1,3 +1,5 @@
+Hello World :
+
$$
-katexcode
+\sqrt{3x}
$$
\ No newline at end of file
diff --git a/packages/turndown/src/commonmark-rules.js b/packages/turndown/src/commonmark-rules.js
index 2d0fa2aaa2..fda46b78aa 100644
--- a/packages/turndown/src/commonmark-rules.js
+++ b/packages/turndown/src/commonmark-rules.js
@@ -608,6 +608,7 @@ function joplinEditableBlockInfo(node) {
if (!node.classList.contains('joplin-editable')) return null;
let sourceNode = null;
+ let isInline = false;
for (const childNode of node.childNodes) {
if (childNode.classList.contains('joplin-source')) {
sourceNode = childNode;
@@ -616,11 +617,13 @@ function joplinEditableBlockInfo(node) {
}
if (!sourceNode) return null;
+ if (!node.isBlock) isInline = true;
return {
openCharacters: sourceNode.getAttribute('data-joplin-source-open'),
closeCharacters: sourceNode.getAttribute('data-joplin-source-close'),
content: sourceNode.textContent,
+ isInline
};
}
@@ -637,7 +640,8 @@ rules.joplinSourceBlock = {
const info = joplinEditableBlockInfo(node);
if (!info) return;
- return '\n\n' + info.openCharacters + info.content + info.closeCharacters + '\n\n';
+ const surroundingCharacter = info.isInline? '' : '\n\n';
+ return surroundingCharacter + info.openCharacters + info.content + info.closeCharacters + surroundingCharacter;
}
}