Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
compose: Support to convert math html to markdown.
apoorvapendse3fd5673bbd5a
diff --git a/web/src/copy_and_paste.ts b/web/src/copy_and_paste.tsindex 4e6877d4193..95650a71ad8 100644--- a/web/src/copy_and_paste.ts+++ b/web/src/copy_and_paste.ts@@ -443,6 +443,27 @@ export function paste_handler_converter(.parseFromString(paste_html, "text/html").querySelector("body");assert(copied_html_fragment !== null);++ const para_elements = copied_html_fragment.querySelectorAll("p");++ for (const element of para_elements) {+ const children = [...element.childNodes];+ /*+ The aim behind doing this is to convert the intermediate text nodes+ between two katex spans into spans.++ This is done because filter() function only processes HTMLElements+ */+ for (const child of children) {+ if (child.nodeType === Node.TEXT_NODE) {+ const span = document.createElement("span");+ span.classList.add("zulip-paste-parser-text-node");+ span.textContent = child.textContent;+ child.replaceWith(span);+ }+ }+ }+const copied_within_single_element = within_single_element(copied_html_fragment);const outer_elements_to_retain = ["PRE", "UL", "OL", "A", "CODE"];// If the entire selection copied is within a single HTML element (like an@@ -513,6 +534,170 @@ export function paste_handler_converter(return prefix + content + (node.nextSibling && !content.endsWith("\n") ? "\n" : "");},});++ /*+ Below lies the the thought process behind the parsing for math blocks and inline math expressions.++ The general structure of the katex-displays i.e. math blocks is:+ <p>+ span.katex-display(start expression 1)+ span.katex+ nested stuff we don't really care about while parsing+ annotation(contains the expression)+ span.katex-display(start expression 2)+ (same as above)+ '+ '+ '+ </p>+ A katex-display is present for every expression that is separated by two or more newlines in md.+ We also have to adjust our markdown for empty katex-displays generated due to excessive newlines between two+ expressions.++ The trick in case of the math blocks is approving all the katex displays+ instead of just the first one.+ This helps prevent the remaining katex display texts being addressed as+ text nodes and getting appended to the end unnecessarily.+ Then in the replacement function only process the parent <p> tag's immediate children only once.+ See : https://github.com/user-attachments/files/18058052/katex-display-logic.pdf for an example.++ We make use of a set to keep track whether the parent p is already processed in both the cases.++ In case of inline math expressions, the structure is same as math blocks.+ Instead of katex-displays being the immediate children of p, we have span.katex or+ textnodes(which are converted into spans before parsing) as the immediate children.+ Newlines in markdown are translated into <br> instead of empty katex-displays here.++ For more information:+ https://chat.zulip.org/#narrow/channel/9-issues/topic/Replying.20to.20highlighted.20text.2C.20LaTeX.20is.20not.20preserved.20.2331608/near/1991687+ */++ const processed_math_block_parents = new Set();+ const processed_inline_math_block_parents = new Set();+ turndownService.addRule("katex-math-block", {+ filter(node) {+ if (+ node.classList.contains("katex-display") &&+ !node.closest(".katex-display > .katex-display")+ ) {+ return true;+ }++ return false;+ },+ replacement(content: string, node) {+ assert(node instanceof HTMLElement);+ let math_block_markdown = "```math\n";+ const parent = node.parentElement!;+ if (processed_math_block_parents.has(parent)) {+ return "";+ }+ processed_math_block_parents.add(parent);+ let consecutive_empty_display_count = 0;+ for (const child of parent.children) {+ const annotation_element = child.querySelector(+ '.katex-mathml annotation[encoding="application/x-tex"]',+ );+ if (annotation_element?.textContent) {+ const katex_source = annotation_element.textContent.trim();+ math_block_markdown += katex_source + "\n\n";+ consecutive_empty_display_count = 0;+ } else {+ // Handling cases where math block is selected directly without any preceding text.+ // The initial katex display doesn't have the annotation when selection is done in this manner.+ if (+ child.classList.contains("katex-display") &&+ child.querySelector("math")?.textContent !== ""+ ) {+ math_block_markdown += content;+ continue;+ }+ if (consecutive_empty_display_count === 0) {+ math_block_markdown += "\n\n\n";+ } else {+ math_block_markdown += "\n\n";+ }+ consecutive_empty_display_count += 1;+ }+ }+ // Don't add extra newline at the end+ math_block_markdown = math_block_markdown.slice(0, -1);+ return (math_block_markdown += "```");+ },+ });+ const inlineTags = new Set(["em", "strong"]);++ function is_inline_tag(node: HTMLElement): boolean {+ return node.nodeType === 1 && inlineTags.has(node.tagName.toLowerCase());+ }++ turndownService.addRule("katex-inline-math", {+ filter(node) {+ // Allow the intermediate text blocks, so that they don't get appended to the end.+ if (node.classList.contains("zulip-paste-parser-text-node") || is_inline_tag(node)) {+ return true;+ }+ if (node.classList.contains("katex") && !node.classList.contains("katex-display")) {+ // Should explicitly be an inline expression+ const parent = node.parentElement;+ if (parent?.classList.contains("katex-display")) {+ return false;+ }+ return true;+ }++ return false;+ },+ replacement(content, node: Node) {+ let parsed_inline_expression = "";+ if (node !== null) {+ const parent = node.parentElement!;+ if (processed_inline_math_block_parents.has(parent)) {+ return "";+ }+ processed_inline_math_block_parents.add(parent);+ for (const child of parent.children) {+ let is_strong_ele = false;+ let is_emphasized_ele = false;+ if (child.nodeName.toLocaleLowerCase() === "strong") {+ is_strong_ele = true;+ parsed_inline_expression += "**";+ }+ if (child.nodeName.toLocaleLowerCase() === "em") {+ is_emphasized_ele = true;+ parsed_inline_expression += "*";+ }+ if (child.nodeName === "BR") {+ parsed_inline_expression += "\n";+ continue;+ }+ const annotation_element = child.querySelector(+ `.katex-mathml annotation[encoding="application/x-tex"]`,+ );+ if (annotation_element?.textContent) {+ const katex_source = annotation_element.textContent;+ parsed_inline_expression += `$$${katex_source}$$`;+ continue;+ }+ if (child.classList.contains("katex")) {+ parsed_inline_expression += `$$${content}$$`;+ continue;+ }+ // It is a text node that is not between two katex spans+ parsed_inline_expression += child.textContent;+ if (is_strong_ele) {+ parsed_inline_expression += "**";+ }+ if (is_emphasized_ele) {+ parsed_inline_expression += "*";+ }+ continue;+ }+ }+ return parsed_inline_expression;+ },+ });+turndownService.addRule("zulipImagePreview", {filter(node) {// select image previews in Zulip messages@@ -644,7 +829,6 @@ export function paste_handler_converter();},});-let markdown_text = turndownService.turndown(paste_html);// Checks for escaped ordered list syntax.diff --git a/web/tests/copy_and_paste.test.cjs b/web/tests/copy_and_paste.test.cjsindex c01689596a8..dfa95d2f664 100644--- a/web/tests/copy_and_paste.test.cjs+++ b/web/tests/copy_and_paste.test.cjs@@ -2,12 +2,19 @@const assert = require("node:assert/strict");-const {zrequire} = require("./lib/namespace.cjs");+const {JSDOM} = require("jsdom");++const katex_tests = require("../../zerver/tests/fixtures/katex_test_cases.json");++const {zrequire, set_global} = require("./lib/namespace.cjs");const {run_test} = require("./lib/test.cjs");+const {window} = new JSDOM();+const copy_and_paste = zrequire("copy_and_paste");const stream_data = zrequire("stream_data");+set_global("document", {});stream_data.add_sub({stream_id: 4,name: "Rome",@@ -116,6 +123,9 @@ run_test("paste_handler_converter", () => {assert.equal(copy_and_paste.paste_handler_converter(input), "The `JSDOM` constructor");// A python code block+ global.document = window.document;+ global.window = window;+ global.Node = window.Node;input = `<meta http-equiv="content-type" content="text/html; charset=utf-8"><p>zulip code block in python</p><div class="codehilite zulip-code-block" data-code-language="Python"><pre><span></span><code><span class="nb">print</span><span class="p">(</span><span class="s2">"hello"</span><span class="p">)</span>\n<span class="nb">print</span><span class="p">(</span><span class="s2">"world"</span><span class="p">)</span></code></pre></div></meta>`;assert.equal(copy_and_paste.paste_handler_converter(input),@@ -239,4 +249,22 @@ run_test("paste_handler_converter", () => {// Pasting from Excel using ^⇧V should paste formatted text.assert.equal(copy_and_paste.paste_handler_converter(input), " \n\n$ 20.00\n\n$ 7.00");++ // Math block tests+ for (const math_block_test of katex_tests.math_block_tests) {+ input = math_block_test.input;+ assert.equal(+ copy_and_paste.paste_handler_converter(input),+ math_block_test.expected_output,+ );+ }++ // Inline Math Expression tests+ for (const inline_math_expression_test of katex_tests.inline_math_expression_tests) {+ input = inline_math_expression_test.input;+ assert.equal(+ copy_and_paste.paste_handler_converter(input),+ inline_math_expression_test.expected_output,+ );+ }});diff --git a/zerver/tests/fixtures/katex_test_cases.json b/zerver/tests/fixtures/katex_test_cases.jsonnew file mode 100644index 00000000000..cbae73b4255--- /dev/null+++ b/zerver/tests/fixtures/katex_test_cases.json@@ -0,0 +1,49 @@+{+ "math_block_tests": [+ {+ "original_markup":"intro text\n\n```math\na + b = 33\n\n\n\n\n\n\n\nd+x = 44\n``` \n\nend",+ "description": "Math block containing expressions with absurd number of newlines between each other. Notice how eight newlines are replaced with nine newlines",+ "input": "<p>intro text</p>\n<p><span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow><mi>a</mi><mo>+</mo><mi>b</mi><mo>=</mo><mn>33</mn></mrow><annotation encoding=\"application/x-tex\">a + b = 33</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:0.6667em;vertical-align:-0.0833em;\"></span><span class=\"mord mathnormal\">a</span><span class=\"mspace\" style=\"margin-right:0.2222em;\"></span><span class=\"mbin\">+</span><span class=\"mspace\" style=\"margin-right:0.2222em;\"></span></span><span class=\"base\"><span class=\"strut\" style=\"height:0.6944em;\"></span><span class=\"mord mathnormal\">b</span><span class=\"mspace\" style=\"margin-right:0.2778em;\"></span><span class=\"mrel\">=</span><span class=\"mspace\" style=\"margin-right:0.2778em;\"></span></span><span class=\"base\"><span class=\"strut\" style=\"height:0.6444em;\"></span><span class=\"mord\">33</span></span></span></span></span></span>\n\n<span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow></mrow><annotation encoding=\"application/x-tex\"></annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"></span></span></span>\n\n<span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow></mrow><annotation encoding=\"application/x-tex\"></annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"></span></span></span>\n\n<span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow></mrow><annotation encoding=\"application/x-tex\"></annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"></span></span></span>\n\n<span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow><mi>d</mi><mo>+</mo><mi>x</mi><mo>=</mo><mn>44</mn></mrow><annotation encoding=\"application/x-tex\">d+x = 44</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:0.7778em;vertical-align:-0.0833em;\"></span><span class=\"mord mathnormal\">d</span><span class=\"mspace\" style=\"margin-right:0.2222em;\"></span><span class=\"mbin\">+</span><span class=\"mspace\" style=\"margin-right:0.2222em;\"></span></span><span class=\"base\"><span class=\"strut\" style=\"height:0.4306em;\"></span><span class=\"mord mathnormal\">x</span><span class=\"mspace\" style=\"margin-right:0.2778em;\"></span><span class=\"mrel\">=</span><span class=\"mspace\" style=\"margin-right:0.2778em;\"></span></span><span class=\"base\"><span class=\"strut\" style=\"height:0.6444em;\"></span><span class=\"mord\">44</span></span></span></span></span>\n<p>end</p>",+ "expected_output": "intro text\n\n```math\na + b = 33\n\n\n\n\n\n\n\n\nd+x = 44\n``` \n\nend"+ },+ {+ "original_markup":"hello world\n\n```math\nc + x = 6\n\nc + a = 00\n```\n\nhi there\n\n```math\nc + xy = 55\n```",+ "input": "<p>hello world</p><p><span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow><mi>c</mi><mo>+</mo><mi>x</mi><mo>=</mo><mn>6</mn></mrow><annotation encoding=\"application/x-tex\">c + x = 6</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:0.6667em;vertical-align:-0.0833em;\"></span><span class=\"mord mathnormal\">c</span><span class=\"mspace\" style=\"margin-right:0.2222em;\"></span><span class=\"mbin\">+</span><span class=\"mspace\" style=\"margin-right:0.2222em;\"></span></span><span class=\"base\"><span class=\"strut\" style=\"height:0.4306em;\"></span><span class=\"mord mathnormal\">x</span><span class=\"mspace\" style=\"margin-right:0.2778em;\"></span><span class=\"mrel\">=</span><span class=\"mspace\" style=\"margin-right:0.2778em;\"></span></span><span class=\"base\"><span class=\"strut\" style=\"height:0.6444em;\"></span><span class=\"mord\">6</span></span></span></span></span></span><span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow><mi>c</mi><mo>+</mo><mi>a</mi><mo>=</mo><mn>00</mn></mrow><annotation encoding=\"application/x-tex\">c + a = 00</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:0.6667em;vertical-align:-0.0833em;\"></span><span class=\"mord mathnormal\">c</span><span class=\"mspace\" style=\"margin-right:0.2222em;\"></span><span class=\"mbin\">+</span><span class=\"mspace\" style=\"margin-right:0.2222em;\"></span></span><span class=\"base\"><span class=\"strut\" style=\"height:0.4306em;\"></span><span class=\"mord mathnormal\">a</span><span class=\"mspace\" style=\"margin-right:0.2778em;\"></span><span class=\"mrel\">=</span><span class=\"mspace\" style=\"margin-right:0.2778em;\"></span></span><span class=\"base\"><span class=\"strut\" style=\"height:0.6444em;\"></span><span class=\"mord\">00</span></span></span></span></span></p><p>hi there</p><p><span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow><mi>c</mi><mo>+</mo><mi>x</mi><mi>y</mi><mo>=</mo><mn>55</mn></mrow><annotation encoding=\"application/x-tex\">c + xy = 55</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:0.6667em;vertical-align:-0.0833em;\"></span><span class=\"mord mathnormal\">c</span><span class=\"mspace\" style=\"margin-right:0.2222em;\"></span><span class=\"mbin\">+</span><span class=\"mspace\" style=\"margin-right:0.2222em;\"></span></span><span class=\"base\"><span class=\"strut\" style=\"height:0.625em;vertical-align:-0.1944em;\"></span><span class=\"mord mathnormal\">x</span><span class=\"mord mathnormal\" style=\"margin-right:0.03588em;\">y</span><span class=\"mspace\" style=\"margin-right:0.2778em;\"></span><span class=\"mrel\">=</span><span class=\"mspace\" style=\"margin-right:0.2778em;\"></span></span><span class=\"base\"><span class=\"strut\" style=\"height:0.6444em;\"></span><span class=\"mord\">55</span></span></span></span></span></p>",+ "description": "Normal math block.",+ "expected_output": "hello world\n\n```math\nc + x = 6\n\nc + a = 00\n```\n\nhi there\n\n```math\nc + xy = 55\n```"+ },+ {+ "original_markup":"```math\nc+d=55\n\n\nx + y = 99\n```",+ "description": "Selecting only math expression in math block.",+ "input": "<p><span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"mord mathnormal\">c</span><span class=\"mspace\" style=\"margin-right:0.2222em;\"></span><span class=\"mbin\">+</span><span class=\"mspace\" style=\"margin-right:0.2222em;\"></span></span><span class=\"base\"><span class=\"strut\" style=\"height:0.6944em;\"></span><span class=\"mord mathnormal\">d</span><span class=\"mspace\" style=\"margin-right:0.2778em;\"></span><span class=\"mrel\">=</span><span class=\"mspace\" style=\"margin-right:0.2778em;\"></span></span><span class=\"base\"><span class=\"strut\" style=\"height:0.6444em;\"></span><span class=\"mord\">55</span></span></span></span></span>\n\n<span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics><mrow><mi>x</mi><mo>+</mo><mi>y</mi><mo>=</mo><mn>99</mn></mrow><annotation encoding=\"application/x-tex\">x + y = 99</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:0.6667em;vertical-align:-0.0833em;\"></span><span class=\"mord mathnormal\">x</span><span class=\"mspace\" style=\"margin-right:0.2222em;\"></span><span class=\"mbin\">+</span><span class=\"mspace\" style=\"margin-right:0.2222em;\"></span></span><span class=\"base\"><span class=\"strut\" style=\"height:0.625em;vertical-align:-0.1944em;\"></span><span class=\"mord mathnormal\" style=\"margin-right:0.03588em;\">y</span><span class=\"mspace\" style=\"margin-right:0.2778em;\"></span><span class=\"mrel\">=</span><span class=\"mspace\" style=\"margin-right:0.2778em;\"></span></span><span class=\"base\"><span class=\"strut\" style=\"height:0.6444em;\"></span><span class=\"mord\">99</span></span></span></span></span></p>",+ "expected_output": "```math\nc+d=55\n\n\nx + y = 99\n```"+ }+ ],+ "inline_math_expression_tests": [+ {+ "original_markup":"intro text\n$$p+q =4$$",+ "description": "Inline Expression 1.",+ "input": "<p>intro text<br>\n<span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><semantics><mrow><mi>p</mi><mo>+</mo><mi>q</mi><mo>=</mo><mn>4</mn></mrow><annotation encoding=\"application/x-tex\">p+q =4</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:0.7778em;vertical-align:-0.1944em;\"></span><span class=\"mord mathnormal\">p</span><span class=\"mspace\" style=\"margin-right:0.2222em;\"></span><span class=\"mbin\">+</span><span class=\"mspace\" style=\"margin-right:0.2222em;\"></span></span><span class=\"base\"><span class=\"strut\" style=\"height:0.625em;vertical-align:-0.1944em;\"></span><span class=\"mord mathnormal\" style=\"margin-right:0.03588em;\">q</span><span class=\"mspace\" style=\"margin-right:0.2778em;\"></span><span class=\"mrel\">=</span><span class=\"mspace\" style=\"margin-right:0.2778em;\"></span></span><span class=\"base\"><span class=\"strut\" style=\"height:0.6444em;\"></span><span class=\"mord\">4</span></span></span></span></p>",+ "expected_output": "intro text\n$$p+q =4$$"+ },+ {+ "original_markup":"intro text\n$$p+q =4$$\n$$x+y=z$$\nhello world",+ "description": "Inline Expression 2 (multiline).",+ "input": "<p>intro text<br>\n <span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><semantics><mrow><mi>p</mi><mo>+</mo><mi>q</mi><mo>=</mo><mn>4</mn></mrow><annotation encoding=\"application/x-tex\">p+q =4</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:0.7778em;vertical-align:-0.1944em;\"></span><span class=\"mord mathnormal\">p</span><span class=\"mspace\" style=\"margin-right:0.2222em;\"></span><span class=\"mbin\">+</span><span class=\"mspace\" style=\"margin-right:0.2222em;\"></span></span><span class=\"base\"><span class=\"strut\" style=\"height:0.625em;vertical-align:-0.1944em;\"></span><span class=\"mord mathnormal\" style=\"margin-right:0.03588em;\">q</span><span class=\"mspace\" style=\"margin-right:0.2778em;\"></span><span class=\"mrel\">=</span><span class=\"mspace\" style=\"margin-right:0.2778em;\"></span></span><span class=\"base\"><span class=\"strut\" style=\"height:0.6444em;\"></span><span class=\"mord\">4</span></span></span></span><br>\n <span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><semantics><mrow><mi>x</mi><mo>+</mo><mi>y</mi><mo>=</mo><mi>z</mi></mrow><annotation encoding=\"application/x-tex\">x+y=z</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:0.6667em;vertical-align:-0.0833em;\"></span><span class=\"mord mathnormal\">x</span><span class=\"mspace\" style=\"margin-right:0.2222em;\"></span><span class=\"mbin\">+</span><span class=\"mspace\" style=\"margin-right:0.2222em;\"></span></span><span class=\"base\"><span class=\"strut\" style=\"height:0.625em;vertical-align:-0.1944em;\"></span><span class=\"mord mathnormal\" style=\"margin-right:0.03588em;\">y</span><span class=\"mspace\" style=\"margin-right:0.2778em;\"></span><span class=\"mrel\">=</span><span class=\"mspace\" style=\"margin-right:0.2778em;\"></span></span><span class=\"base\"><span class=\"strut\" style=\"height:0.4306em;\"></span><span class=\"mord mathnormal\" style=\"margin-right:0.04398em;\">z</span></span></span></span><br>\n hello world</p>",+ "expected_output": "intro text\n$$p+q =4$$\n$$x+y=z$$\nhello world"+ },+ {+ "original_markup":"hey there\n$$a+b$$ some text $$c+d$$\nhow",+ "description": "Inline expression with intermediate text node between two inline expressions.",+ "input": "<p>hey there<br>\n<span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><semantics><mrow><mi>a</mi><mo>+</mo><mi>b</mi></mrow><annotation encoding=\"application/x-tex\">a+b</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:0.6667em;vertical-align:-0.0833em;\"></span><span class=\"mord mathnormal\">a</span><span class=\"mspace\" style=\"margin-right:0.2222em;\"></span><span class=\"mbin\">+</span><span class=\"mspace\" style=\"margin-right:0.2222em;\"></span></span><span class=\"base\"><span class=\"strut\" style=\"height:0.6944em;\"></span><span class=\"mord mathnormal\">b</span></span></span></span> some text <span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><semantics><mrow><mi>c</mi><mo>+</mo><mi>d</mi></mrow><annotation encoding=\"application/x-tex\">c+d</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:0.6667em;vertical-align:-0.0833em;\"></span><span class=\"mord mathnormal\">c</span><span class=\"mspace\" style=\"margin-right:0.2222em;\"></span><span class=\"mbin\">+</span><span class=\"mspace\" style=\"margin-right:0.2222em;\"></span></span><span class=\"base\"><span class=\"strut\" style=\"height:0.6944em;\"></span><span class=\"mord mathnormal\">d</span></span></span></span><br>\nhow </p>",+ "expected_output": "hey there\n$$a+b$$ some text $$c+d$$\nhow"+ },+ {+ "original_markup":"I *think* $$e^{i\\pi} = -1$$ is the **coolest** thing I've seen since $$x^2 + y^2 = z^2$$ blew my mind.",+ "description": "Inline expression with bold and emphasized text.",+ "input": "<div class=\"message_content rendered_markdown\"><p>I <em>think</em> <span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><semantics><mrow><msup><mi>e</mi><mrow><mi>i</mi><mi>π</mi></mrow></msup><mo>=</mo><mo>−</mo><mn>1</mn></mrow><annotation encoding=\"application/x-tex\">e^{i\\pi} = -1</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:0.8247em;\"></span><span class=\"mord\"><span class=\"mord mathnormal\">e</span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.8247em;\"><span style=\"top:-3.063em;margin-right:0.05em;\"><span class=\"pstrut\" style=\"height:2.7em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathnormal mtight\" style=\"margin-right:0.03588em;\">iπ</span></span></span></span></span></span></span></span></span><span class=\"mspace\" style=\"margin-right:0.2778em;\"></span><span class=\"mrel\">=</span><span class=\"mspace\" style=\"margin-right:0.2778em;\"></span></span><span class=\"base\"><span class=\"strut\" style=\"height:0.7278em;vertical-align:-0.0833em;\"></span><span class=\"mord\">−</span><span class=\"mord\">1</span></span></span></span> is the <strong>coolest</strong> thing I've seen since <span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><semantics><mrow><msup><mi>x</mi><mn>2</mn></msup><mo>+</mo><msup><mi>y</mi><mn>2</mn></msup><mo>=</mo><msup><mi>z</mi><mn>2</mn></msup></mrow><annotation encoding=\"application/x-tex\">x^2 + y^2 = z^2</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:0.8974em;vertical-align:-0.0833em;\"></span><span class=\"mord\"><span class=\"mord mathnormal\">x</span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.8141em;\"><span style=\"top:-3.063em;margin-right:0.05em;\"><span class=\"pstrut\" style=\"height:2.7em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\">2</span></span></span></span></span></span></span></span><span class=\"mspace\" style=\"margin-right:0.2222em;\"></span><span class=\"mbin\">+</span><span class=\"mspace\" style=\"margin-right:0.2222em;\"></span></span><span class=\"base\"><span class=\"strut\" style=\"height:1.0085em;vertical-align:-0.1944em;\"></span><span class=\"mord\"><span class=\"mord mathnormal\" style=\"margin-right:0.03588em;\">y</span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.8141em;\"><span style=\"top:-3.063em;margin-right:0.05em;\"><span class=\"pstrut\" style=\"height:2.7em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\">2</span></span></span></span></span></span></span></span><span class=\"mspace\" style=\"margin-right:0.2778em;\"></span><span class=\"mrel\">=</span><span class=\"mspace\" style=\"margin-right:0.2778em;\"></span></span><span class=\"base\"><span class=\"strut\" style=\"height:0.8141em;\"></span><span class=\"mord\"><span class=\"mord mathnormal\" style=\"margin-right:0.04398em;\">z</span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.8141em;\"><span style=\"top:-3.063em;margin-right:0.05em;\"><span class=\"pstrut\" style=\"height:2.7em;\"></span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\">2</span></span></span></span></span></span></span></span></span></span></span> blew my mind.</p></div>",+ "expected_output":"I *think* $$e^{i\\pi} = -1$$ is the **coolest** thing I've seen since $$x^2 + y^2 = z^2$$ blew my mind."++ }+ ]+}