securemark 0.258.6 → 0.258.7
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 +4 -0
- package/design.md +13 -5
- package/dist/index.js +8 -44
- package/package.json +1 -1
- package/src/combinator/data/parser/context/memo.ts +1 -1
- package/src/parser/inline/annotation.test.ts +1 -1
- package/src/parser/inline/annotation.ts +1 -3
- package/src/parser/inline/bracket.test.ts +1 -1
- package/src/parser/inline/extension/placeholder.ts +1 -1
- package/src/parser/inline/link.test.ts +2 -2
- package/src/parser/inline/link.ts +2 -30
- package/src/parser/inline/reference.test.ts +1 -1
- package/src/parser/inline/reference.ts +1 -3
- package/src/parser/inline/template.test.ts +1 -1
- package/src/parser/inline/template.ts +1 -3
- package/src/parser/inline.test.ts +5 -5
package/CHANGELOG.md
CHANGED
package/design.md
CHANGED
|
@@ -284,17 +284,25 @@ CodeMirrorが素では速いがVimModeでは数万文字程度でも耐え難く
|
|
|
284
284
|
|
|
285
285
|
### バックトラック
|
|
286
286
|
|
|
287
|
-
SecuremarkのAnnotation
|
|
288
|
-
CommonMarkはLink
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
287
|
+
SecuremarkのAnnotation構文に典型的であるように文脈を変更する構文の中にその文脈に依存し変更される他の構文が存在する場合一般に文脈の相違から解析結果を再利用不能な(`αA'β | αAB`)バックトラックが生じる。文脈依存構文の解析中に文脈により解釈の異なる字句(`[a[`)または現在の文脈を終了する字句(ただの括弧がスコープを作らない場合の`(([a))`)に遭遇したとき、現在の文脈での解析の継続を試行する解析方法はメモ化なしではバックトラックが再帰的に生じ線形時間で解析できず、現在の文脈での解析を中止し直前の文脈を継続または新たな文脈を開始する解析方法はバックトラックなしで線形時間で解析できる。
|
|
288
|
+
CommonMarkはLink構文から明らかなように後者の解析方法により重篤なバックトラックなしで(インラインでは)ほぼ1回の走査で解析できる言語であるが同時にこれは文脈依存構文の正当な入れ子表現(`[<a@b>]`)を解析できないか不正な表現(`[<a@b>]()`)を除外できず二重リンク(`<a><a></a></a>`)を生成する、文脈依存構文の存在する数に応じて多項式的(おそらく$n^{2+c}$)に構文の壊れやすさの増す脆く拡張性の低い言語であることを意味する(構文の決定を遅延できれば解決できるがこれにより他の構文の解釈が非決定的にならない場合に限られる)。この問題はおそらくメモ化により解決できるがCommonMarkは実行性能追及のためメモ化を廃止しており二重リンクも放置しているためメモ化により性能を低下させてまで解決するつもりはないと思われる(すなわちCommonMarkは機械を至上とし人間に制約を課す低水準の言語であり人間の需要を至上とするSecuremarkとは対極に位置する)。
|
|
289
|
+
従ってほぼ1回の走査で解析可能な文法に制約されるCommonMarkには文脈依存構文を入れ子表現の広範な制限ならびに構文の可読性および開始記号の信頼性の多項式的な低下と引き換えにしか追加できないという拡張性の欠陥が存在する。CommonMarkの仕様策定者が構文の拡張に(名称を維持するか否かにかかわらず)不自然なまでに消極的または進展がないのは正当な理由や怠慢からでなく文脈依存構文を追加するにつれて構文解析戦略の欠陥が明白になっていくためおよび現在の高い実行性能を低下させたくないためである。`~~a~~`のような文脈自由構文は容易に追加できるがこうしたマージンを失えばもはや後はない。
|
|
290
|
+
Securemarkは線形時間で解析不能な前者の解析方法を各種最適化によりおおよそ4n以下の最悪計算量に改善しさらに解析時間と解析範囲の局限により一定時間内で解析不能な入力の影響を局限することでこれらの問題を解決している。この解析方法はほとんどの自然な入力に対して線形に近い時間で効率的に動作し、最悪計算量で低速に動作させる少数の機械的攻撃入力に対してもサーバーで多数のユーザーのリクエストに応じるには低速で脆弱性となる可能性があるがクライアントで単一のユーザーの操作に応じるには十分高速であるためクライアントで解析する限り解析の効率または速度が実用上問題となることはない。
|
|
291
|
+
|
|
292
|
+
### メモ化
|
|
293
|
+
|
|
294
|
+
一部の文脈依存言語を線形時間で解析できるようになるとしても状態数に応じて複数回走査が必要なこと、これにより時間効率が定性的には改善されても定量的には文脈自由言語より数倍悪いこと、オーバーヘッドが有意に大きいこと、時間の代わりに空間効率が非線形に悪化する可能性があることなどから理論上同じ線形時間だとしても実用上文脈自由言語と同等の実行性能にはならず文脈依存言語を文脈自由言語と等価の選択肢にするものではない。
|
|
295
|
+
|
|
296
|
+
### 最適化
|
|
297
|
+
|
|
298
|
+
現在Securemarkのボトルネックはプロファイルによると単なるパーサーの呼び出しが並んでおり引数の入力文字列を値渡しのためコピーするコストである可能性が疑われる。アルゴリズムとしてはメモ化したパース結果を複製せず永続データ構造として使用できるようおよび後処理に必要となるノードを収集しやすいようCSTを木構造に置き換える必要がある。またDOM出力の分離によりバックトラックのコストを削減する。
|
|
292
299
|
|
|
293
300
|
### 標準化
|
|
294
301
|
|
|
295
302
|
Markdownのように自然言語と自身の文法を分離する汎用構造がないメタ言語は構文を拡張する際に旧構文を破壊する新構文が自然言語の中に潜在せざるをえず後方互換性を保証することが不可能である。
|
|
296
303
|
このためCommonMarkは拡張構文を標準化した次期標準仕様との互換性を確保する役には立たずその有用性は構文の拡張を考慮しない範囲での効率的な実装方法の例示およびテストケースの集積による個別実装の支援ならびにその結果としての限定的互換性にとどまる。
|
|
297
304
|
さらにCommonMarkは前述の解析時間の制約から拡張性が低く、高度な構文や機能の実装可能性を考慮していないことから拡張仕様において準拠すべき技術的正当性もない。
|
|
305
|
+
実際GFMが二種類のフェンスドブロックのセマンティクスを分けずCommonMarkに準拠して単なるエイリアスとして有用な記号を浪費したのは顕著かつ明白な失敗だったと言えよう(Securemarkでは入力文字列の無変換表示(シンタックスハイライト)用と変換表示(拡張構文)用に分かれている)。
|
|
298
306
|
|
|
299
307
|
よってMarkdownの標準化は後方互換性確保が不可能であることから発展性がなくスナップショット以上の技術的意味を持たない。
|
|
300
308
|
MarkdownはGFMのように最初から高機能で完成度の高い拡張不要な独自実装のほうが標準としての互換性を確保でき、構文に曖昧さがない形式言語と異なりまず最小限の標準仕様を策定しのちに拡張していく通常の標準化方法が適さない特殊な言語である。
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! securemark v0.258.
|
|
1
|
+
/*! securemark v0.258.7 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"));
|
|
@@ -3099,7 +3099,7 @@ class Memo {
|
|
|
3099
3099
|
|
|
3100
3100
|
for (let i = position + this.offset, len = memory.length; i < len; ++i) {
|
|
3101
3101
|
memory.pop();
|
|
3102
|
-
} //console.log('clear', position + 1);
|
|
3102
|
+
} //console.log('clear', position + this.offset + 1);
|
|
3103
3103
|
|
|
3104
3104
|
}
|
|
3105
3105
|
|
|
@@ -5694,8 +5694,6 @@ const combinator_1 = __webpack_require__(2087);
|
|
|
5694
5694
|
|
|
5695
5695
|
const inline_1 = __webpack_require__(1160);
|
|
5696
5696
|
|
|
5697
|
-
const link_1 = __webpack_require__(9628);
|
|
5698
|
-
|
|
5699
5697
|
const visibility_1 = __webpack_require__(7618);
|
|
5700
5698
|
|
|
5701
5699
|
const dom_1 = __webpack_require__(3252);
|
|
@@ -5712,7 +5710,7 @@ exports.annotation = (0, combinator_1.lazy)(() => (0, combinator_1.surround)('((
|
|
|
5712
5710
|
delimiters: global_1.undefined
|
|
5713
5711
|
}, (0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]), ')', [[/^\\?\n/, 9], [')', 2], ['))', 6]])), ')')))), '))', false, ([, ns], rest) => [[(0, dom_1.html)('sup', {
|
|
5714
5712
|
class: 'annotation'
|
|
5715
|
-
}, [(0, dom_1.html)('span', (0, visibility_1.trimNode)((0, dom_1.defrag)(ns)))])], rest]
|
|
5713
|
+
}, [(0, dom_1.html)('span', (0, visibility_1.trimNode)((0, dom_1.defrag)(ns)))])], rest]));
|
|
5716
5714
|
|
|
5717
5715
|
/***/ }),
|
|
5718
5716
|
|
|
@@ -6467,7 +6465,7 @@ const visibility_1 = __webpack_require__(7618);
|
|
|
6467
6465
|
|
|
6468
6466
|
const dom_1 = __webpack_require__(3252);
|
|
6469
6467
|
|
|
6470
|
-
const array_1 = __webpack_require__(8112); // Don't use the symbols already used:
|
|
6468
|
+
const array_1 = __webpack_require__(8112); // Don't use the symbols already used: !#$%@&*+~=
|
|
6471
6469
|
// All syntax surrounded by square brackets shouldn't contain line breaks.
|
|
6472
6470
|
|
|
6473
6471
|
|
|
@@ -6651,7 +6649,7 @@ exports.insertion = (0, combinator_1.lazy)(() => (0, combinator_1.surround)((0,
|
|
|
6651
6649
|
Object.defineProperty(exports, "__esModule", ({
|
|
6652
6650
|
value: true
|
|
6653
6651
|
}));
|
|
6654
|
-
exports.
|
|
6652
|
+
exports.resolve = exports.option = exports.uri = exports.textlink = exports.link = void 0;
|
|
6655
6653
|
|
|
6656
6654
|
const global_1 = __webpack_require__(4128);
|
|
6657
6655
|
|
|
@@ -6665,8 +6663,6 @@ const html_1 = __webpack_require__(5994);
|
|
|
6665
6663
|
|
|
6666
6664
|
const autolink_1 = __webpack_require__(6578);
|
|
6667
6665
|
|
|
6668
|
-
const bracket_1 = __webpack_require__(5196);
|
|
6669
|
-
|
|
6670
6666
|
const source_1 = __webpack_require__(6743);
|
|
6671
6667
|
|
|
6672
6668
|
const visibility_1 = __webpack_require__(7618);
|
|
@@ -6699,7 +6695,7 @@ exports.link = (0, combinator_1.lazy)(() => (0, combinator_1.validate)(['[', '{'
|
|
|
6699
6695
|
/* State.media */
|
|
6700
6696
|
| 1
|
|
6701
6697
|
/* State.autolink */
|
|
6702
|
-
, (0, combinator_1.some)(inline_1.inline, ']', [[/^\\?\n/, 9], [']', 2]])), ']', true
|
|
6698
|
+
, (0, combinator_1.some)(inline_1.inline, ']', [[/^\\?\n/, 9], [']', 2]])), ']', true)]))), (0, combinator_1.dup)((0, combinator_1.surround)(/^{(?![{}])/, (0, combinator_1.inits)([exports.uri, (0, combinator_1.some)(exports.option)]), /^[^\S\n]*}/))], nodes => nodes[0][0] !== ''), ([as, bs = []]) => bs[0] === '\r' && bs.shift() ? [as, bs] : as[0] === '\r' && as.shift() ? [[], as] : [as, []]))), ([content, params], rest, context) => {
|
|
6703
6699
|
if (content[0] === '') return [content, rest];
|
|
6704
6700
|
if (params.length === 0) return;
|
|
6705
6701
|
if (content.length !== 0 && (0, visibility_1.trimNode)(content).length === 0) return;
|
|
@@ -6799,34 +6795,6 @@ function decode(uri) {
|
|
|
6799
6795
|
}
|
|
6800
6796
|
}
|
|
6801
6797
|
|
|
6802
|
-
function optimize(opener, ns, rest, next, context) {
|
|
6803
|
-
if (next[+(next[0] === '\\')] === '\n') {
|
|
6804
|
-
if (rest[0] !== opener[0]) return;
|
|
6805
|
-
const delimiters = context.delimiters;
|
|
6806
|
-
delimiters?.push({
|
|
6807
|
-
signature: '!\n',
|
|
6808
|
-
matcher: source => !/^\\?\n/.test(source) && global_1.undefined,
|
|
6809
|
-
precedence: 9
|
|
6810
|
-
});
|
|
6811
|
-
const paired = (0, parser_1.eval)((0, combinator_1.state)(~0, bracket_1.bracket)(rest[0] + rest.slice(rest.search(`[^${rest[0]}]|$`)), context), [])[0] !== '';
|
|
6812
|
-
delimiters?.pop();
|
|
6813
|
-
if (paired) return;
|
|
6814
|
-
}
|
|
6815
|
-
|
|
6816
|
-
let count = 0;
|
|
6817
|
-
|
|
6818
|
-
for (let i = 0; i < ns.length - 1; i += 2) {
|
|
6819
|
-
const fst = ns[i];
|
|
6820
|
-
const snd = ns[i + 1];
|
|
6821
|
-
if (fst !== '' || snd[0] !== opener[0]) break;
|
|
6822
|
-
count += snd.length;
|
|
6823
|
-
}
|
|
6824
|
-
|
|
6825
|
-
return [['', opener[0].repeat(opener.length + count)], rest.slice(count)];
|
|
6826
|
-
}
|
|
6827
|
-
|
|
6828
|
-
exports.optimize = optimize;
|
|
6829
|
-
|
|
6830
6798
|
/***/ }),
|
|
6831
6799
|
|
|
6832
6800
|
/***/ 2480:
|
|
@@ -7022,8 +6990,6 @@ const combinator_1 = __webpack_require__(2087);
|
|
|
7022
6990
|
|
|
7023
6991
|
const inline_1 = __webpack_require__(1160);
|
|
7024
6992
|
|
|
7025
|
-
const link_1 = __webpack_require__(9628);
|
|
7026
|
-
|
|
7027
6993
|
const source_1 = __webpack_require__(6743);
|
|
7028
6994
|
|
|
7029
6995
|
const visibility_1 = __webpack_require__(7618);
|
|
@@ -7044,7 +7010,7 @@ exports.reference = (0, combinator_1.lazy)(() => (0, combinator_1.surround)('[['
|
|
|
7044
7010
|
/* State.media */
|
|
7045
7011
|
, (0, visibility_1.startLoose)((0, combinator_1.context)({
|
|
7046
7012
|
delimiters: global_1.undefined
|
|
7047
|
-
}, (0, combinator_1.subsequence)([abbr, (0, combinator_1.open)((0, source_1.stropt)(/^(?=\^)/), (0, combinator_1.some)(inline_1.inline, ']', [[/^\\?\n/, 9], [']', 2], [']]', 6]])), (0, combinator_1.some)(inline_1.inline, ']', [[/^\\?\n/, 9], [']', 2], [']]', 6]])])), ']')))), ']]', false, ([, ns], rest) => [[(0, dom_1.html)('sup', attributes(ns), [(0, dom_1.html)('span', (0, visibility_1.trimNode)((0, dom_1.defrag)(ns)))])], rest]
|
|
7013
|
+
}, (0, combinator_1.subsequence)([abbr, (0, combinator_1.open)((0, source_1.stropt)(/^(?=\^)/), (0, combinator_1.some)(inline_1.inline, ']', [[/^\\?\n/, 9], [']', 2], [']]', 6]])), (0, combinator_1.some)(inline_1.inline, ']', [[/^\\?\n/, 9], [']', 2], [']]', 6]])])), ']')))), ']]', false, ([, ns], rest) => [[(0, dom_1.html)('sup', attributes(ns), [(0, dom_1.html)('span', (0, visibility_1.trimNode)((0, dom_1.defrag)(ns)))])], rest]));
|
|
7048
7014
|
const abbr = (0, combinator_1.creation)((0, combinator_1.bind)((0, combinator_1.surround)('^', (0, combinator_1.union)([(0, source_1.str)(/^(?![0-9]+\s?[|\]])[0-9A-Za-z]+(?:(?:-|(?=\W)(?!'\d)'?(?!\.\d)\.?(?!,\S),? ?)[0-9A-Za-z]+)*(?:-|'?\.?,? ?)?/)]), /^\|?(?=]])|^\|[^\S\n]*/), ([source], rest) => [[(0, dom_1.html)('abbr', source)], rest.replace(visibility_1.regBlankStart, '')]));
|
|
7049
7015
|
|
|
7050
7016
|
function attributes(ns) {
|
|
@@ -7233,8 +7199,6 @@ const global_1 = __webpack_require__(4128);
|
|
|
7233
7199
|
|
|
7234
7200
|
const combinator_1 = __webpack_require__(2087);
|
|
7235
7201
|
|
|
7236
|
-
const link_1 = __webpack_require__(9628);
|
|
7237
|
-
|
|
7238
7202
|
const source_1 = __webpack_require__(6743);
|
|
7239
7203
|
|
|
7240
7204
|
const dom_1 = __webpack_require__(3252);
|
|
@@ -7245,7 +7209,7 @@ exports.template = (0, combinator_1.lazy)(() => (0, combinator_1.surround)('{{',
|
|
|
7245
7209
|
/* Syntax.none */
|
|
7246
7210
|
, 2, 1, (0, combinator_1.some)((0, combinator_1.union)([bracket, source_1.escsource]), '}')), '}}', true, ([, ns = []], rest) => [[(0, dom_1.html)('span', {
|
|
7247
7211
|
class: 'template'
|
|
7248
|
-
}, `{{${ns.join('').replace(/\x1B/g, '')}}}`)], rest]
|
|
7212
|
+
}, `{{${ns.join('').replace(/\x1B/g, '')}}}`)], rest]));
|
|
7249
7213
|
const bracket = (0, combinator_1.lazy)(() => (0, combinator_1.creation)((0, combinator_1.union)([(0, combinator_1.surround)((0, source_1.str)('('), (0, combinator_1.some)((0, combinator_1.union)([bracket, source_1.escsource]), ')'), (0, source_1.str)(')'), true, global_1.undefined, ([as, bs = []], rest) => [(0, array_1.unshift)(as, bs), rest]), (0, combinator_1.surround)((0, source_1.str)('['), (0, combinator_1.some)((0, combinator_1.union)([bracket, source_1.escsource]), ']'), (0, source_1.str)(']'), true, global_1.undefined, ([as, bs = []], rest) => [(0, array_1.unshift)(as, bs), rest]), (0, combinator_1.surround)((0, source_1.str)('{'), (0, combinator_1.some)((0, combinator_1.union)([bracket, source_1.escsource]), '}'), (0, source_1.str)('}'), true, global_1.undefined, ([as, bs = []], rest) => [(0, array_1.unshift)(as, bs), rest]), (0, combinator_1.surround)((0, source_1.str)('"'), (0, combinator_1.precedence)(8, (0, combinator_1.some)(source_1.escsource, /^"|^\\?\n/)), (0, source_1.str)('"'), true)])));
|
|
7250
7214
|
|
|
7251
7215
|
/***/ }),
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@ describe('Unit: parser/inline/annotation', () => {
|
|
|
14
14
|
assert.deepStrictEqual(inspect(parser('(())')), undefined);
|
|
15
15
|
assert.deepStrictEqual(inspect(parser('(()))')), undefined);
|
|
16
16
|
assert.deepStrictEqual(inspect(parser('(( ))')), undefined);
|
|
17
|
-
assert.deepStrictEqual(inspect(parser('(( (a')),
|
|
17
|
+
assert.deepStrictEqual(inspect(parser('(( (a')), undefined);
|
|
18
18
|
assert.deepStrictEqual(inspect(parser('((\n))')), undefined);
|
|
19
19
|
assert.deepStrictEqual(inspect(parser('((\na))')), undefined);
|
|
20
20
|
assert.deepStrictEqual(inspect(parser('((\\\na))')), undefined);
|
|
@@ -2,7 +2,6 @@ import { undefined } from 'spica/global';
|
|
|
2
2
|
import { AnnotationParser } from '../inline';
|
|
3
3
|
import { union, some, context, syntax, constraint, state, surround, lazy } from '../../combinator';
|
|
4
4
|
import { inline } from '../inline';
|
|
5
|
-
import { optimize } from './link';
|
|
6
5
|
import { Syntax, State } from '../context';
|
|
7
6
|
import { startLoose, trimNode } from '../visibility';
|
|
8
7
|
import { html, defrag } from 'typed-dom/dom';
|
|
@@ -17,5 +16,4 @@ export const annotation: AnnotationParser = lazy(() => surround(
|
|
|
17
16
|
some(union([inline]), ')', [[/^\\?\n/, 9], [')', 2], ['))', 6]])), ')')))),
|
|
18
17
|
'))',
|
|
19
18
|
false,
|
|
20
|
-
([, ns], rest) => [[html('sup', { class: 'annotation' }, [html('span', trimNode(defrag(ns)))])], rest]
|
|
21
|
-
([, ns, rest], next, context) => next[0] === ')' ? undefined : optimize('((', ns, rest, next, context)));
|
|
19
|
+
([, ns], rest) => [[html('sup', { class: 'annotation' }, [html('span', trimNode(defrag(ns)))])], rest]));
|
|
@@ -75,7 +75,7 @@ describe('Unit: parser/inline/bracket', () => {
|
|
|
75
75
|
assert.deepStrictEqual(inspect(parser('"a')), [['"', 'a'], '']);
|
|
76
76
|
assert.deepStrictEqual(inspect(parser('"a"')), [['"', 'a', '"'], '']);
|
|
77
77
|
assert.deepStrictEqual(inspect(parser('"(")"')), [['"', '', '(', '"'], ')"']);
|
|
78
|
-
assert.deepStrictEqual(inspect(parser('"(("')), [['"', '', '((', '"'], '']);
|
|
78
|
+
assert.deepStrictEqual(inspect(parser('"(("')), [['"', '', '(', '', '(', '"'], '']);
|
|
79
79
|
assert.deepStrictEqual(inspect(parser('"(\\")"')), [['"', '<span class="paren">(")</span>', '"'], '']);
|
|
80
80
|
assert.deepStrictEqual(inspect(parser('"(\n)"')), [['"', '<span class="paren">(<br>)</span>', '"'], '']);
|
|
81
81
|
assert.deepStrictEqual(inspect(parser('"(\\\n)"')), [['"', '<span class="paren">(<span class="linebreak"> </span>)</span>', '"'], '']);
|
|
@@ -7,7 +7,7 @@ import { startTight } from '../../visibility';
|
|
|
7
7
|
import { html, defrag } from 'typed-dom/dom';
|
|
8
8
|
import { unshift } from 'spica/array';
|
|
9
9
|
|
|
10
|
-
// Don't use the symbols already used:
|
|
10
|
+
// Don't use the symbols already used: !#$%@&*+~=
|
|
11
11
|
|
|
12
12
|
// All syntax surrounded by square brackets shouldn't contain line breaks.
|
|
13
13
|
|
|
@@ -45,7 +45,7 @@ describe('Unit: parser/inline/link', () => {
|
|
|
45
45
|
it('invalid', () => {
|
|
46
46
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
47
47
|
assert.deepStrictEqual(inspect(parser('{}')), undefined);
|
|
48
|
-
assert.deepStrictEqual(inspect(parser('[{b}')),
|
|
48
|
+
assert.deepStrictEqual(inspect(parser('[{b}')), undefined);
|
|
49
49
|
assert.deepStrictEqual(inspect(parser('[]')), undefined);
|
|
50
50
|
assert.deepStrictEqual(inspect(parser('[]{}')), undefined);
|
|
51
51
|
assert.deepStrictEqual(inspect(parser('[]{ }')), undefined);
|
|
@@ -65,7 +65,7 @@ describe('Unit: parser/inline/link', () => {
|
|
|
65
65
|
assert.deepStrictEqual(inspect(parser('[\\ ]{b}')), undefined);
|
|
66
66
|
assert.deepStrictEqual(inspect(parser('[\\\n]{b}')), undefined);
|
|
67
67
|
assert.deepStrictEqual(inspect(parser('[	]{b}')), undefined);
|
|
68
|
-
assert.deepStrictEqual(inspect(parser('[[]{b}')),
|
|
68
|
+
assert.deepStrictEqual(inspect(parser('[[]{b}')), undefined);
|
|
69
69
|
assert.deepStrictEqual(inspect(parser('[]]{b}')), undefined);
|
|
70
70
|
assert.deepStrictEqual(inspect(parser('[a]{}')), undefined);
|
|
71
71
|
assert.deepStrictEqual(inspect(parser('[a\nb]{b}')), undefined);
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { undefined, location, encodeURI, decodeURI, Location } from 'spica/global';
|
|
2
|
-
import { MarkdownParser } from '../../../markdown';
|
|
3
2
|
import { LinkParser, TextLinkParser } from '../inline';
|
|
4
|
-
import {
|
|
3
|
+
import { eval, exec } from '../../combinator/data/parser';
|
|
5
4
|
import { union, inits, tails, subsequence, some, constraint, syntax, creation, precedence, state, validate, surround, open, dup, reverse, lazy, fmap, bind } from '../../combinator';
|
|
6
5
|
import { inline, media, shortmedia } from '../inline';
|
|
7
6
|
import { attributes } from './html';
|
|
8
7
|
import { autolink } from '../autolink';
|
|
9
|
-
import { bracket } from './bracket';
|
|
10
8
|
import { unescsource, str } from '../source';
|
|
11
9
|
import { Syntax, State } from '../context';
|
|
12
10
|
import { trimNode } from '../visibility';
|
|
@@ -32,9 +30,7 @@ export const link: LinkParser = lazy(() => validate(['[', '{'], bind(
|
|
|
32
30
|
state(State.annotation | State.reference | State.index | State.label | State.media | State.autolink,
|
|
33
31
|
some(inline, ']', [[/^\\?\n/, 9], [']', 2]])),
|
|
34
32
|
']',
|
|
35
|
-
true,
|
|
36
|
-
undefined,
|
|
37
|
-
([, ns = [], rest], next, context) => next[0] === ']' ? undefined : optimize('[', ns, rest, next, context)),
|
|
33
|
+
true),
|
|
38
34
|
]))),
|
|
39
35
|
dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]*}/)),
|
|
40
36
|
], nodes => nodes[0][0] !== ''),
|
|
@@ -193,27 +189,3 @@ function decode(uri: string): string {
|
|
|
193
189
|
return uri.replace(/\s+/g, encodeURI);
|
|
194
190
|
}
|
|
195
191
|
}
|
|
196
|
-
|
|
197
|
-
export function optimize(opener: string, ns: readonly (string | HTMLElement)[], rest: string, next: string, context: MarkdownParser.Context): Result<string> {
|
|
198
|
-
if (next[+(next[0] === '\\')] === '\n') {
|
|
199
|
-
if (rest[0] !== opener[0]) return;
|
|
200
|
-
const delimiters = context.delimiters;
|
|
201
|
-
delimiters?.push({
|
|
202
|
-
signature: '!\n',
|
|
203
|
-
matcher: source => !/^\\?\n/.test(source) && undefined,
|
|
204
|
-
precedence: 9,
|
|
205
|
-
});
|
|
206
|
-
const paired = eval(state(~0, bracket)(rest[0] + rest.slice(rest.search(`[^${rest[0]}]|$`)), context), [])[0] !== '';
|
|
207
|
-
delimiters?.pop();
|
|
208
|
-
if (paired) return;
|
|
209
|
-
}
|
|
210
|
-
let count = 0;
|
|
211
|
-
for (let i = 0; i < ns.length - 1; i += 2) {
|
|
212
|
-
const fst = ns[i];
|
|
213
|
-
const snd = ns[i + 1] as string;
|
|
214
|
-
assert(typeof snd === 'string');
|
|
215
|
-
if (fst !== '' || snd[0] !== opener[0]) break;
|
|
216
|
-
count += snd.length;
|
|
217
|
-
}
|
|
218
|
-
return [['', opener[0].repeat(opener.length + count)], rest.slice(count)];
|
|
219
|
-
}
|
|
@@ -14,7 +14,7 @@ describe('Unit: parser/inline/reference', () => {
|
|
|
14
14
|
assert.deepStrictEqual(inspect(parser('[[]]')), undefined);
|
|
15
15
|
assert.deepStrictEqual(inspect(parser('[[]]]')), undefined);
|
|
16
16
|
assert.deepStrictEqual(inspect(parser('[[ ]]')), undefined);
|
|
17
|
-
assert.deepStrictEqual(inspect(parser('[[ [a')),
|
|
17
|
+
assert.deepStrictEqual(inspect(parser('[[ [a')), undefined);
|
|
18
18
|
assert.deepStrictEqual(inspect(parser('[[\n]]')), undefined);
|
|
19
19
|
assert.deepStrictEqual(inspect(parser('[[\na]]')), undefined);
|
|
20
20
|
assert.deepStrictEqual(inspect(parser('[[\\\na]]')), undefined);
|
|
@@ -2,7 +2,6 @@ import { undefined } from 'spica/global';
|
|
|
2
2
|
import { ReferenceParser } from '../inline';
|
|
3
3
|
import { union, subsequence, some, context, syntax, creation, constraint, state, surround, open, lazy, bind } from '../../combinator';
|
|
4
4
|
import { inline } from '../inline';
|
|
5
|
-
import { optimize } from './link';
|
|
6
5
|
import { str, stropt } from '../source';
|
|
7
6
|
import { Syntax, State } from '../context';
|
|
8
7
|
import { regBlankStart, startLoose, trimNode } from '../visibility';
|
|
@@ -23,8 +22,7 @@ export const reference: ReferenceParser = lazy(() => surround(
|
|
|
23
22
|
])), ']')))),
|
|
24
23
|
']]',
|
|
25
24
|
false,
|
|
26
|
-
([, ns], rest) => [[html('sup', attributes(ns), [html('span', trimNode(defrag(ns)))])], rest]
|
|
27
|
-
([, ns, rest], next, context) => next[0] === ']' ? undefined : optimize('[[', ns, rest, next, context)));
|
|
25
|
+
([, ns], rest) => [[html('sup', attributes(ns), [html('span', trimNode(defrag(ns)))])], rest]));
|
|
28
26
|
|
|
29
27
|
const abbr: ReferenceParser.AbbrParser = creation(bind(surround(
|
|
30
28
|
'^',
|
|
@@ -10,7 +10,7 @@ describe('Unit: parser/inline/template', () => {
|
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
11
11
|
assert.deepStrictEqual(inspect(parser('{')), undefined);
|
|
12
12
|
assert.deepStrictEqual(inspect(parser('{}')), undefined);
|
|
13
|
-
assert.deepStrictEqual(inspect(parser('{{')),
|
|
13
|
+
assert.deepStrictEqual(inspect(parser('{{')), undefined);
|
|
14
14
|
assert.deepStrictEqual(inspect(parser('{{\\}}')), undefined);
|
|
15
15
|
assert.deepStrictEqual(inspect(parser('{{a}b}')), undefined);
|
|
16
16
|
assert.deepStrictEqual(inspect(parser('{{{a}}')), undefined);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { undefined } from 'spica/global';
|
|
2
2
|
import { TemplateParser } from '../inline';
|
|
3
3
|
import { union, some, syntax, creation, precedence, surround, lazy } from '../../combinator';
|
|
4
|
-
import { optimize } from './link';
|
|
5
4
|
import { escsource, str } from '../source';
|
|
6
5
|
import { Syntax } from '../context';
|
|
7
6
|
import { html } from 'typed-dom/dom';
|
|
@@ -9,8 +8,7 @@ import { unshift } from 'spica/array';
|
|
|
9
8
|
|
|
10
9
|
export const template: TemplateParser = lazy(() => surround(
|
|
11
10
|
'{{', syntax(Syntax.none, 2, 1, some(union([bracket, escsource]), '}')), '}}', true,
|
|
12
|
-
([, ns = []], rest) => [[html('span', { class: 'template' }, `{{${ns.join('').replace(/\x1B/g, '')}}}`)], rest]
|
|
13
|
-
([, ns = [], rest], next, context) => next[0] === '}' ? undefined : optimize('{{', ns, rest, next, context)));
|
|
11
|
+
([, ns = []], rest) => [[html('span', { class: 'template' }, `{{${ns.join('').replace(/\x1B/g, '')}}}`)], rest]));
|
|
14
12
|
|
|
15
13
|
const bracket: TemplateParser.BracketParser = lazy(() => creation(union([
|
|
16
14
|
surround(str('('), some(union([bracket, escsource]), ')'), str(')'), true, undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
@@ -143,23 +143,23 @@ describe('Unit: parser/inline', () => {
|
|
|
143
143
|
assert.deepStrictEqual(inspect(parser('Di$ney Micro$oft')), [['Di', '$', 'ney', ' ', 'Micro', '$', 'oft'], '']);
|
|
144
144
|
assert.deepStrictEqual(inspect(parser('Di$ney, Micro$oft')), [['Di', '$', 'ney', ',', ' ', 'Micro', '$', 'oft'], '']);
|
|
145
145
|
assert.deepStrictEqual(inspect(parser('(((a))')), [['', '(', '<sup class="annotation"><span>a</span></sup>'], '']);
|
|
146
|
-
assert.deepStrictEqual(inspect(parser('((((a))')), [['', '((', '<sup class="annotation"><span>a</span></sup>'], '']);
|
|
146
|
+
assert.deepStrictEqual(inspect(parser('((((a))')), [['', '(', '', '(', '<sup class="annotation"><span>a</span></sup>'], '']);
|
|
147
147
|
assert.deepStrictEqual(inspect(parser('((((a))))')), [['<sup class="annotation"><span><span class="paren">((a))</span></span></sup>'], '']);
|
|
148
148
|
assert.deepStrictEqual(inspect(parser('((<bdi>))')), [['<sup class="annotation"><span><span class="invalid"><bdi></span></span></sup>'], '']);
|
|
149
|
-
assert.deepStrictEqual(inspect(parser('((${))}$')), [['', '((', '<span class="math" translate="no" data-src="${))}$">${))}$</span>'], '']);
|
|
149
|
+
assert.deepStrictEqual(inspect(parser('((${))}$')), [['', '(', '', '(', '<span class="math" translate="no" data-src="${))}$">${))}$</span>'], '']);
|
|
150
150
|
assert.deepStrictEqual(inspect(parser('"((""))')), [['"', '<sup class="annotation"><span>""</span></sup>'], '']);
|
|
151
151
|
assert.deepStrictEqual(inspect(parser('[[[a]]')), [['', '[', '<sup class="reference"><span>a</span></sup>'], '']);
|
|
152
|
-
assert.deepStrictEqual(inspect(parser('[[[[a]]')), [['', '[[', '<sup class="reference"><span>a</span></sup>'], '']);
|
|
152
|
+
assert.deepStrictEqual(inspect(parser('[[[[a]]')), [['', '[', '', '[', '<sup class="reference"><span>a</span></sup>'], '']);
|
|
153
153
|
assert.deepStrictEqual(inspect(parser('[[[[a]]]]')), [['<sup class="reference"><span>[[a]]</span></sup>'], '']);
|
|
154
154
|
assert.deepStrictEqual(inspect(parser('[[[$-1]]]')), [['<sup class="reference"><span><a class="label" data-label="$-1">$-1</a></span></sup>'], '']);
|
|
155
155
|
assert.deepStrictEqual(inspect(parser('[[[]{a}]]')), [['<sup class="reference"><span><a href="a">a</a></span></sup>'], '']);
|
|
156
156
|
assert.deepStrictEqual(inspect(parser('[[[a]{b}]]')), [['<sup class="reference"><span><a href="b">a</a></span></sup>'], '']);
|
|
157
157
|
assert.deepStrictEqual(inspect(parser('[(([a]{#}))]{#}')), [['<a href="#"><span class="paren">(<span class="paren">([a]{#})</span>)</span></a>'], '']);
|
|
158
158
|
assert.deepStrictEqual(inspect(parser('[[<bdi>]]')), [['<sup class="reference"><span><span class="invalid"><bdi></span></span></sup>'], '']);
|
|
159
|
-
assert.deepStrictEqual(inspect(parser('[[${]]}$')), [['', '[[', '<span class="math" translate="no" data-src="${]]}$">${]]}$</span>'], '']);
|
|
159
|
+
assert.deepStrictEqual(inspect(parser('[[${]]}$')), [['', '[', '', '[', '<span class="math" translate="no" data-src="${]]}$">${]]}$</span>'], '']);
|
|
160
160
|
assert.deepStrictEqual(inspect(parser('"[[""]]')), [['"', '<sup class="reference"><span>""</span></sup>'], '']);
|
|
161
161
|
assert.deepStrictEqual(inspect(parser('[[a](b)]{c}')), [['<a href="c"><ruby>a<rp>(</rp><rt>b</rt><rp>)</rp></ruby></a>'], '']);
|
|
162
|
-
assert.deepStrictEqual(inspect(parser('[[[[[[[{a}')), [['', '[[[[[[[', '<a href="a">a</a>'], '']);
|
|
162
|
+
assert.deepStrictEqual(inspect(parser('[[[[[[[{a}')), [['', '[', '', '[', '', '[', '', '[', '', '[', '', '[', '', '[', '<a href="a">a</a>'], '']);
|
|
163
163
|
assert.deepStrictEqual(inspect(parser('<http://host>')), [['<', '<a href="http://host" target="_blank">http://host</a>', '>'], '']);
|
|
164
164
|
assert.deepStrictEqual(inspect(parser('[~http://host')), [['', '[', '~', '<a href="http://host" target="_blank">http://host</a>'], '']);
|
|
165
165
|
assert.deepStrictEqual(inspect(parser('[~a@b')), [['', '[', '~', '<a class="email" href="mailto:a@b">a@b</a>'], '']);
|