From a05d380fcfd9d86798d86ceadc3cf91c6136fc85 Mon Sep 17 00:00:00 2001 From: Klemek Date: Fri, 19 Jul 2019 10:41:01 +0200 Subject: [PATCH] fixed parts detection --- src/renderer.js | 9 ++++----- test/renderer.test.js | 38 +++++++++++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/renderer.js b/src/renderer.js index 266feb1..af8c3f5 100644 --- a/src/renderer.js +++ b/src/renderer.js @@ -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 = /(\n\n``````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 \n```$no eq$```', (data) => { + expect(data).toBe('this code is ```start $a$ end $$hello$$``` beautiful \n```$no eq$```'); done(); }); });