fixed parts detection
This commit is contained in:
+4
-5
@@ -17,7 +17,6 @@ module.exports = (config) => {
|
||||
while ((match = /```/m.exec(data.slice(i)))) {
|
||||
parts.push({
|
||||
index: i,
|
||||
end: i + match.index,
|
||||
text: data.slice(i, i + match.index),
|
||||
});
|
||||
i += match.index + match[0].length;
|
||||
@@ -25,7 +24,6 @@ module.exports = (config) => {
|
||||
if (i < data.length)
|
||||
parts.push({
|
||||
index: i,
|
||||
end: data.length,
|
||||
text: data.slice(i, data.length),
|
||||
});
|
||||
|
||||
@@ -38,7 +36,6 @@ module.exports = (config) => {
|
||||
while ((match = /(<script>((?:(?!<\/script>)[\s\S])*)<\/script>)/gm.exec(p.text.slice(i)))) {
|
||||
subParts.push({
|
||||
index: p.index + i,
|
||||
end: i + match.index,
|
||||
text: p.text.slice(i, i + match.index),
|
||||
});
|
||||
i += match.index + match[0].length;
|
||||
@@ -46,11 +43,13 @@ module.exports = (config) => {
|
||||
if (i < p.text.length)
|
||||
subParts.push({
|
||||
index: p.index + i,
|
||||
end: p.text.length,
|
||||
text: p.text.slice(i, p.text.length),
|
||||
});
|
||||
parts.splice(pi, 1, ...subParts);
|
||||
});
|
||||
|
||||
parts.forEach(part => part.end = part.index + part.text.length);
|
||||
|
||||
return parts;
|
||||
};
|
||||
|
||||
@@ -139,7 +138,7 @@ module.exports = (config) => {
|
||||
const eqRegex = /\$\$((?:(?!\$\$)[\s\S])*)\$\$/m;
|
||||
const inlineEqRegex = /\$([^$\n]*)\$/;
|
||||
|
||||
for (let i = 0; i < parts.length; i += 2) {
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
let match;
|
||||
if ((match = eqRegex.exec(parts[i].text))) {
|
||||
return doMJ(match, 'TeX', i);
|
||||
|
||||
+31
-7
@@ -55,8 +55,32 @@ describe('get parts', () => {
|
||||
test('lot of stuff', () => {
|
||||
const data = 'Hello\nthere\n```code```\ngeneral<script>script</script>\n<script>script2</script>\n```<script>script3</script>```kenobi';
|
||||
const parts = renderer.getParts(data);
|
||||
expect(parts.map(p => p.text)).toEqual([
|
||||
'Hello\nthere\n', '\ngeneral', '\n', '\n', 'kenobi'
|
||||
expect(parts).toEqual([
|
||||
{
|
||||
index: 0,
|
||||
end: 12,
|
||||
text: 'Hello\nthere\n'
|
||||
},
|
||||
{
|
||||
index: 22,
|
||||
end: 30,
|
||||
text: '\ngeneral'
|
||||
},
|
||||
{
|
||||
index: 53,
|
||||
end: 54,
|
||||
text: '\n'
|
||||
},
|
||||
{
|
||||
index: 78,
|
||||
end: 79,
|
||||
text: '\n'
|
||||
},
|
||||
{
|
||||
index: 109,
|
||||
end: 115,
|
||||
text: 'kenobi'
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -132,8 +156,8 @@ describe('Test PlantUML', () => {
|
||||
});
|
||||
|
||||
test('plantuml ignored in code', (done) => {
|
||||
renderer.renderPlantUML('code:\n```@startuml\nBob -> Alice : hello\n@enduml```', (data) => {
|
||||
expect(data).toBe('code:\n```@startuml\nBob -> Alice : hello\n@enduml```');
|
||||
renderer.renderPlantUML('code:\n```@startuml\nBob -> Alice : hello\n@enduml```\n ```@startuml``` @enduml', (data) => {
|
||||
expect(data).toBe('code:\n```@startuml\nBob -> Alice : hello\n@enduml```\n ```@startuml``` @enduml');
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -183,9 +207,9 @@ describe('Test MathJax', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
test('no eq in code', (done) => {
|
||||
renderer.renderMathJax('this code is ```start $a$ end $$hello$$``` beautiful', (data) => {
|
||||
expect(data).toBe('this code is ```start $a$ end $$hello$$``` beautiful');
|
||||
test('no eq in code / script', (done) => {
|
||||
renderer.renderMathJax('this code is ```start $a$ end $$hello$$``` beautiful <script>$A$</script>\n```$no eq$```', (data) => {
|
||||
expect(data).toBe('this code is ```start $a$ end $$hello$$``` beautiful <script>$A$</script>\n```$no eq$```');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user