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