Repository: zestedesavoir/zmarkdown
Pull request #296 (2018-11-09 16:58:04)

fix(live-demo): Fix external dependencies


Patch:
diff --git a/packages/remark-grid-tables/dist/index.js b/packages/remark-grid-tables/dist/index.js
index 8babd76f..5c332455 100644
--- a/packages/remark-grid-tables/dist/index.js
+++ b/packages/remark-grid-tables/dist/index.js
@@ -271,19 +271,21 @@ function computeColumnStartingPositions(lines) {
 
 function extractTable(value, eat, tokenizer) {
   // Extract lines before the grid table
-  var possibleGridTable = value.split('\n').map(function (line) {
-    return trimEnd(line);
-  });
+  var markdownLines = value.split('\n');
 
   var i = 0;
   var before = [];
-  for (; i < possibleGridTable.length; i++) {
-    var line = possibleGridTable[i];
+  for (; i < markdownLines.length; i++) {
+    var line = markdownLines[i];
     if (isSeparationLine(line)) break;
     if (line.length === 0) break;
     before.push(line);
   }
 
+  var possibleGridTable = markdownLines.map(function (line) {
+    return trimEnd(line);
+  });
+
   // Extract table
   if (!possibleGridTable[i + 1]) return [null, null, null, null];
   var lineLength = possibleGridTable[i + 1].length;
diff --git a/packages/remark-grid-tables/src/index.js b/packages/remark-grid-tables/src/index.js
index 167f9cd2..1bc486c4 100644
--- a/packages/remark-grid-tables/src/index.js
+++ b/packages/remark-grid-tables/src/index.js
@@ -227,19 +227,21 @@ function computeColumnStartingPositions (lines) {
 
 function extractTable (value, eat, tokenizer) {
   // Extract lines before the grid table
-  const possibleGridTable = value
+  const markdownLines = value
     .split('\n')
-    .map(line => trimEnd(line))
 
   let i = 0
   const before = []
-  for (; i < possibleGridTable.length; i++) {
-    const line = possibleGridTable[i]
+  for (; i < markdownLines.length; i++) {
+    const line = markdownLines[i]
     if (isSeparationLine(line)) break
     if (line.length === 0) break
     before.push(line)
   }
 
+  const possibleGridTable = markdownLines
+    .map(line => trimEnd(line))
+
   // Extract table
   if (!possibleGridTable[i + 1]) return [null, null, null, null]
   const lineLength = possibleGridTable[i + 1].length
diff --git a/packages/zmarkdown/public/index.html b/packages/zmarkdown/public/index.html
index fd0a8aff..ccdc1579 100644
--- a/packages/zmarkdown/public/index.html
+++ b/packages/zmarkdown/public/index.html
@@ -195,7 +195,7 @@ Markdown[^mdown] est une syntaxe légère d'écriture de documents. Pandoc[^pand
 <script src="./js/zmarkdown.js"></script>
 <script src="./js/zmarkdown-zhtml.js"></script>
 <script src="./js/zmarkdown-zlatex.js"></script>
-<script src="https://unpkg.com/split.js/split.min.js"></script>
+<script src="https://unpkg.com/split.js/dist/split.min.js"></script>
 <script src="./script.js"></script>
 </body>
 </html>


Test patch:
diff --git a/packages/remark-grid-tables/__tests__/index.js b/packages/remark-grid-tables/__tests__/index.js
index ff7d866c..bf3c90f5 100644
--- a/packages/remark-grid-tables/__tests__/index.js
+++ b/packages/remark-grid-tables/__tests__/index.js
@@ -89,6 +89,29 @@ test('regression: should be parsed with two spaces on last line', () => {
   expect(contents).toBe(base)
 })
 
+test('regression: should not crash with leading space', () => {
+  const {contents: base} = render(dedent`
+    ax
+    +---+
+    | b |
+    +---+
+
+    hello
+    `)
+
+  const {contents} = render(dedent`
+    a·
+    +---+
+    | b |
+    +---+
+
+    hello
+    `.replace(/·/g, ' '))
+
+  expect(contents).toBe(base.replace('x', ' '))
+})
+
+
 test('stringify', () => {
   const fileExample = file(join(__dirname, 'grid-tables.md'))
   const {contents} = render(fileExample)