securemark 0.257.2 → 0.257.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.257.3
4
+
5
+ - Fix styled table parser.
6
+
3
7
  ## 0.257.2
4
8
 
5
9
  - Fix operator precedence.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! securemark v0.257.2 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED License */
1
+ /*! securemark v0.257.3 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED License */
2
2
  (function webpackUniversalModuleDefinition(root, factory) {
3
3
  if(typeof exports === 'object' && typeof module === 'object')
4
4
  module.exports = factory(require("DOMPurify"), require("Prism"));
@@ -2851,6 +2851,7 @@ function inits(parsers) {
2851
2851
 
2852
2852
  for (let i = 0, len = parsers.length; i < len; ++i) {
2853
2853
  if (rest === '') break;
2854
+ if (context.delimiters?.match(rest, context.precedence)) break;
2854
2855
  const result = parsers[i](rest, context);
2855
2856
  if (!result) break;
2856
2857
  nodes = nodes ? (0, array_1.push)(nodes, (0, parser_1.eval)(result)) : (0, parser_1.eval)(result);
@@ -2890,6 +2891,7 @@ function sequence(parsers) {
2890
2891
 
2891
2892
  for (let i = 0, len = parsers.length; i < len; ++i) {
2892
2893
  if (rest === '') return;
2894
+ if (context.delimiters?.match(rest, context.precedence)) break;
2893
2895
  const result = parsers[i](rest, context);
2894
2896
  if (!result) return;
2895
2897
  nodes = nodes ? (0, array_1.push)(nodes, (0, parser_1.eval)(result)) : (0, parser_1.eval)(result);
@@ -5146,13 +5148,15 @@ const inline_1 = __webpack_require__(1160);
5146
5148
 
5147
5149
  const source_1 = __webpack_require__(6743);
5148
5150
 
5151
+ const util_1 = __webpack_require__(9437);
5152
+
5149
5153
  const dom_1 = __webpack_require__(3252);
5150
5154
 
5151
5155
  const array_1 = __webpack_require__(8112);
5152
5156
 
5153
5157
  exports.table = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.fmap)((0, combinator_1.validate)(/^\|[^\n]*(?:\n\|[^\n]*){2}/, (0, combinator_1.sequence)([row((0, combinator_1.some)(head), true), row((0, combinator_1.some)(align), false), (0, combinator_1.some)(row((0, combinator_1.some)(data), true))])), rows => [(0, dom_1.html)('table', [(0, dom_1.html)('thead', [rows.shift()]), (0, dom_1.html)('tbody', format(rows))])])));
5154
5158
 
5155
- const row = (parser, optional) => (0, combinator_1.creator)((0, combinator_1.fallback)((0, combinator_1.fmap)((0, combinator_1.line)((0, combinator_1.surround)(/^(?=\|)/, (0, combinator_1.some)((0, combinator_1.union)([parser])), /^\|?\s*$/, optional)), es => [(0, dom_1.html)('tr', es)]), (0, combinator_1.rewrite)(source_1.contentline, source => [[(0, dom_1.html)('tr', {
5159
+ const row = (parser, optional) => (0, combinator_1.creator)((0, combinator_1.fallback)((0, combinator_1.fmap)((0, combinator_1.line)((0, combinator_1.surround)(/^(?=\|)/, (0, combinator_1.some)((0, combinator_1.union)([parser])), /^[|\\]?\s*$/, optional)), es => [(0, dom_1.html)('tr', es)]), (0, combinator_1.rewrite)(source_1.contentline, source => [[(0, dom_1.html)('tr', {
5156
5160
  class: 'invalid',
5157
5161
  'data-invalid-syntax': 'table-row',
5158
5162
  'data-invalid-type': 'syntax',
@@ -5160,9 +5164,9 @@ const row = (parser, optional) => (0, combinator_1.creator)((0, combinator_1.fal
5160
5164
  }, [(0, dom_1.html)('td', source.replace('\n', ''))])], ''])));
5161
5165
 
5162
5166
  const align = (0, combinator_1.creator)((0, combinator_1.fmap)((0, combinator_1.open)('|', (0, combinator_1.union)([(0, combinator_1.focus)(/^:-+:/, () => [['center'], '']), (0, combinator_1.focus)(/^:-+/, () => [['start'], '']), (0, combinator_1.focus)(/^-+:/, () => [['end'], '']), (0, combinator_1.focus)(/^-+/, () => [[''], ''])])), ns => [(0, dom_1.html)('td', (0, dom_1.defrag)(ns))]));
5163
- const cell = (0, combinator_1.surround)(/^\|(?:\\?\s)*(?=\S)/, (0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]), /^(?:\\?\s)*(?=\||\\?$)/), /^[^|]*/, true);
5164
- const head = (0, combinator_1.creator)((0, combinator_1.fmap)(cell, ns => [(0, dom_1.html)('th', (0, dom_1.defrag)(ns))]));
5165
- const data = (0, combinator_1.creator)((0, combinator_1.fmap)(cell, ns => [(0, dom_1.html)('td', (0, dom_1.defrag)(ns))]));
5167
+ const cell = (0, combinator_1.surround)(/^\|\s*(?=\S)/, (0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]), /^\|/, [[/^[|\\]?\s*$/, 9]]), /^[^|]*/, true);
5168
+ const head = (0, combinator_1.creator)((0, combinator_1.fmap)(cell, ns => [(0, dom_1.html)('th', (0, util_1.trimNode)((0, dom_1.defrag)(ns)))]));
5169
+ const data = (0, combinator_1.creator)((0, combinator_1.fmap)(cell, ns => [(0, dom_1.html)('td', (0, util_1.trimNode)((0, dom_1.defrag)(ns)))]));
5166
5170
 
5167
5171
  function format(rows) {
5168
5172
  const aligns = rows[0].classList.contains('invalid') ? [] : (0, array_1.push)([], rows.shift().children).map(el => el.textContent);
@@ -7990,7 +7994,7 @@ function trimNodeStart(nodes) {
7990
7994
  const pos = node.trimStart().length;
7991
7995
 
7992
7996
  if (pos > 0) {
7993
- nodes[0] = node.slice(pos);
7997
+ nodes[0] = node.slice(-pos);
7994
7998
  break;
7995
7999
  }
7996
8000
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "securemark",
3
- "version": "0.257.2",
3
+ "version": "0.257.3",
4
4
  "description": "Secure markdown renderer working on browsers for user input data.",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/falsandtru/securemark",
@@ -11,10 +11,10 @@ export function inits<T, D extends Parser<T>[]>(parsers: D): Parser<T, Ctx, D> {
11
11
  let nodes: T[] | undefined;
12
12
  for (let i = 0, len = parsers.length; i < len; ++i) {
13
13
  if (rest === '') break;
14
+ if (context.delimiters?.match(rest, context.precedence)) break;
14
15
  const result = parsers[i](rest, context);
15
16
  assert(check(rest, result));
16
17
  if (!result) break;
17
- assert(!context?.delimiters?.match(rest, context.precedence));
18
18
  nodes = nodes
19
19
  ? push(nodes, eval(result))
20
20
  : eval(result);
@@ -11,10 +11,10 @@ export function sequence<T, D extends Parser<T>[]>(parsers: D): Parser<T, Ctx, D
11
11
  let nodes: T[] | undefined;
12
12
  for (let i = 0, len = parsers.length; i < len; ++i) {
13
13
  if (rest === '') return;
14
+ if (context.delimiters?.match(rest, context.precedence)) break;
14
15
  const result = parsers[i](rest, context);
15
16
  assert(check(rest, result));
16
17
  if (!result) return;
17
- assert(!context?.delimiters?.match(rest, context.precedence));
18
18
  nodes = nodes
19
19
  ? push(nodes, eval(result))
20
20
  : eval(result);
@@ -29,6 +29,11 @@ describe('Unit: parser/block/table', () => {
29
29
  assert.deepStrictEqual(inspect(parser('|\n|-\n|')), [['<table><thead><tr></tr></thead><tbody><tr></tr></tbody></table>'], '']);
30
30
  assert.deepStrictEqual(inspect(parser('||\n|-|\n||')), [['<table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table>'], '']);
31
31
  assert.deepStrictEqual(inspect(parser('|||\n|-|-|\n|||')), [['<table><thead><tr><th></th><th></th></tr></thead><tbody><tr><td></td><td></td></tr></tbody></table>'], '']);
32
+ assert.deepStrictEqual(inspect(parser('|"|\n|-\n|')), [['<table><thead><tr><th>"</th></tr></thead><tbody><tr></tr></tbody></table>'], '']);
33
+ assert.deepStrictEqual(inspect(parser('|`|\n|-\n|')), [['<table><thead><tr><th>`</th></tr></thead><tbody><tr></tr></tbody></table>'], '']);
34
+ assert.deepStrictEqual(inspect(parser('|`|`|\n|-\n|')), [['<table><thead><tr><th><code data-src="`|`">|</code></th></tr></thead><tbody><tr></tr></tbody></table>'], '']);
35
+ assert.deepStrictEqual(inspect(parser('|((|\n|-\n|')), [['<table><thead><tr><th>((</th></tr></thead><tbody><tr></tr></tbody></table>'], '']);
36
+ assert.deepStrictEqual(inspect(parser('|${|\n|-\n|')), [['<table><thead><tr><th>${</th></tr></thead><tbody><tr></tr></tbody></table>'], '']);
32
37
  assert.deepStrictEqual(inspect(parser('|a|b|\n|-|-|\n|1|2|')), [['<table><thead><tr><th>a</th><th>b</th></tr></thead><tbody><tr><td>1</td><td>2</td></tr></tbody></table>'], '']);
33
38
  assert.deepStrictEqual(inspect(parser('|a|b\n|-|-\n|1|2')), [['<table><thead><tr><th>a</th><th>b</th></tr></thead><tbody><tr><td>1</td><td>2</td></tr></tbody></table>'], '']);
34
39
  assert.deepStrictEqual(inspect(parser('|a|\n|-|\n|1|')), [['<table><thead><tr><th>a</th></tr></thead><tbody><tr><td>1</td></tr></tbody></table>'], '']);
@@ -2,6 +2,7 @@ import { TableParser } from '../block';
2
2
  import { union, sequence, some, block, line, validate, focus, rewrite, creator, surround, open, fallback, lazy, fmap } from '../../combinator';
3
3
  import { inline } from '../inline';
4
4
  import { contentline } from '../source';
5
+ import { trimNode } from '../util';
5
6
  import { html, defrag } from 'typed-dom/dom';
6
7
  import { push } from 'spica/array';
7
8
 
@@ -24,7 +25,7 @@ export const table: TableParser = lazy(() => block(fmap(validate(
24
25
  ])));
25
26
 
26
27
  const row = <P extends CellParser | AlignParser>(parser: P, optional: boolean): RowParser<P> => creator(fallback(fmap(
27
- line(surround(/^(?=\|)/, some(union([parser])), /^\|?\s*$/, optional)),
28
+ line(surround(/^(?=\|)/, some(union([parser])), /^[|\\]?\s*$/, optional)),
28
29
  es => [html('tr', es)]),
29
30
  rewrite(contentline, source => [[
30
31
  html('tr', {
@@ -46,17 +47,17 @@ const align: AlignParser = creator(fmap(open(
46
47
  ns => [html('td', defrag(ns))]));
47
48
 
48
49
  const cell: CellParser = surround(
49
- /^\|(?:\\?\s)*(?=\S)/,
50
- some(union([inline]), /^(?:\\?\s)*(?=\||\\?$)/),
50
+ /^\|\s*(?=\S)/,
51
+ some(union([inline]), /^\|/, [[/^[|\\]?\s*$/, 9]]),
51
52
  /^[^|]*/, true);
52
53
 
53
54
  const head: CellParser.HeadParser = creator(fmap(
54
55
  cell,
55
- ns => [html('th', defrag(ns))]));
56
+ ns => [html('th', trimNode(defrag(ns)))]));
56
57
 
57
58
  const data: CellParser.DataParser = creator(fmap(
58
59
  cell,
59
- ns => [html('td', defrag(ns))]));
60
+ ns => [html('td', trimNode(defrag(ns)))]));
60
61
 
61
62
  function format(rows: HTMLTableRowElement[]): HTMLTableRowElement[] {
62
63
  const aligns = rows[0].classList.contains('invalid')
@@ -191,7 +191,7 @@ function trimNodeStart<T extends HTMLElement | string>(nodes: T[]): T[] {
191
191
  if (typeof node === 'string') {
192
192
  const pos = node.trimStart().length;
193
193
  if (pos > 0) {
194
- nodes[0] = node.slice(pos) as T;
194
+ nodes[0] = node.slice(-pos) as T;
195
195
  break;
196
196
  }
197
197
  }