Skip to content

Commit

Permalink
Add tests for parsing SVG, MathML and Tex annotations.
Browse files Browse the repository at this point in the history
  • Loading branch information
srobotta committed Dec 13, 2024
1 parent 92c2df2 commit cbd92c2
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions tests/js/htmlparser.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {expect, test} from '@jest/globals';
import {parseEditorContent} from './src/htmlparser.mjs';

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

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

test('html 3', () => {
test('Language tags in text and attribures, attributes without value.', () => {
const html = '<p>{mlang en}This is a test{mlang}{mlang de}Das ist ein Test{mlang}.</p>\n'
+ '<p>This is a multilang link: <a\n'
+ ' href="https://google.com?lang={mlang de}de-DE{mlang}{mlang en}en-EN{mlang}" target="_blank">{mlang\n'
Expand Down Expand Up @@ -66,7 +66,7 @@ test('html 3', () => {
+ 'contenteditable="false" class="multilang-end mceNonEditable" data-mce-contenteditable="false">{mlang}</span></p>';
expect(parseEditorContent(html)).toEqual(parsed);
});
test('html 4', () => {
test('Already containing tiny tags for language markers.', () => {
const html = '<p><span contenteditable="false" class="multilang-begin mceNonEditable"\n'
+ 'data-mce-contenteditable="false" lang="en" xml:lang="en">{mlang en}</span>English rules'
+ '<span contenteditable="false" class="multilang-end mceNonEditable" data-mce-contenteditable="false">{mlang}'
Expand All @@ -76,7 +76,7 @@ test('html 4', () => {
+ 'contenteditable="false" class="multilang-end mceNonEditable" data-mce-contenteditable="false">{mlang}</span></p>';
expect(parseEditorContent(html)).toEqual(parsed);
});
test('html 5', () => {
test('Html containing comments.', () => {
const html = '<p><!-- {mlang de}</p>\n'
+ '<p>Hallo</p>\n'
+ '<p>{mlang}--></p>\n'
Expand All @@ -91,4 +91,30 @@ test('html 5', () => {
+ 'data-mce-contenteditable="false">{mlang}</span></p>\n'
+ '<p>Done</p>\n';
expect(parseEditorContent(html)).toEqual(parsed);
});
test('Html containing a svg.', () => {
const html = '<p>Resistor: <svg xmlns="http://www.w3.org/2000/svg"\n'
+ ' version="1.1" baseProfile="full"\n'
+ ' width="700px" height="400px" viewBox="0 0 700 400">\n'
+ '\n'
+ '<!-- Connectors left and right -->\n'
+ '<line x1="0" y1="200" x2="700" y2="200" stroke="black" stroke-width="20px"/>\n'
+ '<!-- The rectangle -->\n'
+ '<rect x="100" y="100" width="500" height="200" fill="white" stroke="black" stroke-width="20px"/>\n'
+ '</svg></p>';
expect(parseEditorContent(html)).toEqual(html);
});
test('Html with tex anotations.', () => {
const html = '<p>The Quadratic Equation: <span class="math-tex">\\(ax^2 + bx + c = 0\\)</span></p>';
expect(parseEditorContent(html)).toEqual(html);
});
test('Html containing mathml elements.', () => {
const html = '<p>The Quadratic Equation: <span><math xmlns="http://www.w3.org/1998/Math/MathML">'
+ ' <mrow>\n'
+ ' <mi>a</mi> <mo>&InvisibleTimes;</mo> <msup><mi>x</mi><mn>2</mn></msup>\n'
+ ' <mo>+</mo><mi>b</mi><mo>&InvisibleTimes;</mo><mi>x</mi>\n'
+ ' <mo>+</mo><mi>c</mi>\n'
+ ' </mrow>\n'
+ '</math></span></p>';
expect(parseEditorContent(html)).toEqual(html);
});

0 comments on commit cbd92c2

Please sign in to comment.