Skip to content

Commit cbd92c2

Browse files
committed
Add tests for parsing SVG, MathML and Tex annotations.
1 parent 92c2df2 commit cbd92c2

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

tests/js/htmlparser.test.js

+31-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {expect, test} from '@jest/globals';
22
import {parseEditorContent} from './src/htmlparser.mjs';
33

4-
test('html 1', () => {
4+
test('Language markers spread via several block elements.', () => {
55
const html = '<p class="clo">{mlang de}</p><div>Foo bar {mlang}</div>';
66
const parsed = '<p class="clo"><span contenteditable="false" class="multilang-begin mceNonEditable" '
77
+ 'data-mce-contenteditable="false" lang="de" xml:lang="de">{mlang de}</span>'
@@ -12,15 +12,15 @@ test('html 1', () => {
1212
expect(parseEditorContent(html)).toEqual(parsed);
1313
});
1414

15-
test('html 2', () => {
15+
test('Only one closing language tag.', () => {
1616
const html = '<div>Foo bar {mlang}</div>';
1717
const parsed = '<div>Foo bar <span contenteditable="false" class="multilang-begin mceNonEditable" '
1818
+ 'data-mce-contenteditable="false" lang="other" xml:lang="other">{mlang other}</span>'
1919
+ '<span contenteditable="false" class="multilang-end mceNonEditable" data-mce-contenteditable="false">{mlang}</span>';
2020
expect(parseEditorContent(html)).toEqual(parsed);
2121
});
2222

23-
test('html 3', () => {
23+
test('Language tags in text and attribures, attributes without value.', () => {
2424
const html = '<p>{mlang en}This is a test{mlang}{mlang de}Das ist ein Test{mlang}.</p>\n'
2525
+ '<p>This is a multilang link: <a\n'
2626
+ ' href="https://google.com?lang={mlang de}de-DE{mlang}{mlang en}en-EN{mlang}" target="_blank">{mlang\n'
@@ -66,7 +66,7 @@ test('html 3', () => {
6666
+ 'contenteditable="false" class="multilang-end mceNonEditable" data-mce-contenteditable="false">{mlang}</span></p>';
6767
expect(parseEditorContent(html)).toEqual(parsed);
6868
});
69-
test('html 4', () => {
69+
test('Already containing tiny tags for language markers.', () => {
7070
const html = '<p><span contenteditable="false" class="multilang-begin mceNonEditable"\n'
7171
+ 'data-mce-contenteditable="false" lang="en" xml:lang="en">{mlang en}</span>English rules'
7272
+ '<span contenteditable="false" class="multilang-end mceNonEditable" data-mce-contenteditable="false">{mlang}'
@@ -76,7 +76,7 @@ test('html 4', () => {
7676
+ 'contenteditable="false" class="multilang-end mceNonEditable" data-mce-contenteditable="false">{mlang}</span></p>';
7777
expect(parseEditorContent(html)).toEqual(parsed);
7878
});
79-
test('html 5', () => {
79+
test('Html containing comments.', () => {
8080
const html = '<p><!-- {mlang de}</p>\n'
8181
+ '<p>Hallo</p>\n'
8282
+ '<p>{mlang}--></p>\n'
@@ -91,4 +91,30 @@ test('html 5', () => {
9191
+ 'data-mce-contenteditable="false">{mlang}</span></p>\n'
9292
+ '<p>Done</p>\n';
9393
expect(parseEditorContent(html)).toEqual(parsed);
94+
});
95+
test('Html containing a svg.', () => {
96+
const html = '<p>Resistor: <svg xmlns="http://www.w3.org/2000/svg"\n'
97+
+ ' version="1.1" baseProfile="full"\n'
98+
+ ' width="700px" height="400px" viewBox="0 0 700 400">\n'
99+
+ '\n'
100+
+ '<!-- Connectors left and right -->\n'
101+
+ '<line x1="0" y1="200" x2="700" y2="200" stroke="black" stroke-width="20px"/>\n'
102+
+ '<!-- The rectangle -->\n'
103+
+ '<rect x="100" y="100" width="500" height="200" fill="white" stroke="black" stroke-width="20px"/>\n'
104+
+ '</svg></p>';
105+
expect(parseEditorContent(html)).toEqual(html);
106+
});
107+
test('Html with tex anotations.', () => {
108+
const html = '<p>The Quadratic Equation: <span class="math-tex">\\(ax^2 + bx + c = 0\\)</span></p>';
109+
expect(parseEditorContent(html)).toEqual(html);
110+
});
111+
test('Html containing mathml elements.', () => {
112+
const html = '<p>The Quadratic Equation: <span><math xmlns="http://www.w3.org/1998/Math/MathML">'
113+
+ ' <mrow>\n'
114+
+ ' <mi>a</mi> <mo>&InvisibleTimes;</mo> <msup><mi>x</mi><mn>2</mn></msup>\n'
115+
+ ' <mo>+</mo><mi>b</mi><mo>&InvisibleTimes;</mo><mi>x</mi>\n'
116+
+ ' <mo>+</mo><mi>c</mi>\n'
117+
+ ' </mrow>\n'
118+
+ '</math></span></p>';
119+
expect(parseEditorContent(html)).toEqual(html);
94120
});

0 commit comments

Comments
 (0)