securemark 0.295.9 → 0.296.1

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,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.296.1
4
+
5
+ - Fix parsers to disallow leading blank characters.
6
+
7
+ ## 0.296.0
8
+
9
+ - Change link, media, annotation, and reference parsers to disallow leading invisible characters.
10
+
3
11
  ## 0.295.9
4
12
 
5
13
  - Refactoring.
package/design.md CHANGED
@@ -296,7 +296,7 @@ CommonMarkは初手設計ミスったせいで構文一つで最悪計算量32n
296
296
  SecuremarkのAnnotation構文に典型的であるように文脈を変更する構文の中にその文脈に依存し変更される他の構文が存在する場合文脈の相違から解析結果を再利用不能(`αAβ | αA'B`)なバックトラックが生じる。またこの結果再帰的バックトラックが生じる可能性があり再帰的バックトラックは一般的にメモ化により解決されるがCommonMarkは最小計算量と実行性能を追及するためメモ化を廃止していることからメモ化により性能を低下させてまで文脈依存構文の問題を解決するつもりはないと思われる(すなわちCommonMarkは機械を至上とし人間に制約を課す低水準の言語であり人間の需要と生産性を至上とする高水準の言語であるSecuremarkの対極に位置する)。従ってCommonMarkは再帰的バックトラックなしで解析可能な構文と最小計算量に制約され基本的に再帰的バックトラックが生じるものである文脈依存構文を追加できないという拡張性の欠陥が存在する(CommonMarkは文脈を変えず`*A*`の記号と解釈を変更しただけの`~~A~~`のような文脈自由構文は容易に追加できるが他の構文を包含可能な文脈依存構文はリンク構文で発生している再帰的バックトラックまたはその修正のために激増した計算量を組み合わせ爆発により指数関数的に致命的に悪化させるため追加できない。例えばすでに最悪計算量32nであるリンク構文を包含した追加構文が1回バックトラックするだけで最悪計算量が32n\*2=64nに悪化し追加構文がリンク構文と同じく最悪計算量32nなら全体の最悪計算量は32n\*32=n\*32^2=1024nとなる。すなわちCommonMarkの最悪計算量は再帰的バックトラックが生じる構文の数mに対してO(n\*32^m)と驚異的かつ絶望的に劣悪な計算量であり構文数が一つであろうと自己再帰可能ならば入れ子数mに対して同じくO(n\*32^m)となる。なお一般的に実用可能な計算量の上限はO(n^3)であるためCommonMarkは文脈依存構文数または入れ子数m>3になるだけで実用可能な計算量の上限を超える。すなわちCommonMarkは自己再帰可能な文脈依存構文を定義することが不可能である。この事実に開発開始から数年後に直面し再帰数の上限を32回に制限することで指数計算量を防ぐも依然として32nという非常識な計算量になっているのがリンク構文とイメージ構文である。なおリンク構文とイメージ構文を入れ子にできているのはイメージ構文を入れる角括弧部分が文脈自由部分だからであり文脈依存部分である丸括弧部分は入れ子になっておらず文脈依存部分の入れ子が生じていないからである。しかし文脈依存構文を追加してリンク構文を包含すれば丸括弧部分を包含し文脈依存部分が入れ子になり計算量の爆発を避けられない)。CommonMarkの仕様策定者が構文の拡張に(名称を維持するか否かにかかわらず)不自然なまでに消極的であり進展がないのは正当な理由や単なる怠慢からでなく構文追加可否を議論すればCommonMarkは理論的欠陥により最悪計算量が絶望的に劣悪であるため文脈依存構文を追加できないというCommonMarkの設計の破綻と失敗が明らかになることが避けられないためおよび最小計算量を放棄して現在の高い実行性能を低下させたくないためであり陳腐な自尊心を守るためにこのような計算量と拡張性の根本的欠陥を秘匿しCommonMarkとその仕様策定者である自分の評価が下がらないよう画策しているからである。でなければこの計算量と拡張性の根本的欠陥を何年も隠蔽せず速やかに公表して助力を求めていなければならず不都合な事実を隠し陳腐な自尊心を守るために全Markdown利用者および開発者を不必要に足止めした罪は重い。
297
297
  CommonMarkは小さく単純であるうちだけ破綻せずに正しく見せかけられる象牙の塔であり仕様策定者はこの見せかけの正しさを失わず正しいままでいたいがために象牙の塔に引きこもり小さな表面的正しさに固執し続けているに過ぎない。しかしCommonMarkは実際にはすでに致命的に破綻しており本来文脈依存言語であるMarkdownを文脈自由言語として解析しようとして失敗したことで指数計算量(正確には指数計算量より悪い階乗計算量)になっており実際のところCommonMarkは最初から最後までずっと壊れている。CommonMarkは可能な限り文脈自由言語として設計することでバックトラックなく最小計算量で解析しようとしているが実際には文脈依存言語であるMarkdownから文脈依存構文を文脈自由構文に変換して再帰的バックトラックを除去することに失敗しているためCommonMarkは最初の数年間は再帰的バックトラックに気づかず最悪計算量が指数計算量になっており修正後も依然として最悪計算量が当初の想定の1nから32nへと劇的に悪化している(より正確にはCommonMarkは少なくともCode構文とHTML構文により+2nされるが説明の簡略化のため省略しこれら以外のInline構文のみを比較する)。CommonMarkが最初の数年間他人に指摘され修正されるまで指数計算量であった事実(https://github.com/commonmark/cmark/commit/45f4fc9b917c11221aa03e70a41e3046335a235d)はCommonMarkが初歩的な再帰的バックトラックの原理すら理解していないド素人により設計された素人仕事である事実を証明しておりたかが強調構文の解析のためにメモ化を行い(https://github.com/commonmark/commonmark.js/commit/6d7d6cf150dedb53b7f0972b79313df3364ebbed https://github.com/commonmark/commonmark.js/blob/ac8529c9f55da7fdc1186e3f34313cf411de6e71/js/stmd.js )他人にメモ化を使わない正しい実装に修正された事実(https://github.com/commonmark/commonmark.js/commit/8837f199608ac2e321f75653736747b1e692072f)もまたCommonMarkの仕様策定者がその任に堪える能力のないド素人である事実を証明している。スタックを使う代わりにメモ化するド素人の能力を誰が擁護できるのか?ド素人が作った結果初歩的な再帰的バックトラックすら他人に指摘されるまで気づかず修正後も最悪計算量が32nにまで著しく悪化した設計が正しいと言えるのか?不可能である。一貫してド素人により設計開発仕様策定されているCommonMarkは仕様策定が停滞し未だに1nの最小計算量に固執しているがそんなものはCommonMarkの破綻と失敗が露呈するを恐れて隠蔽しまたとっくの昔に破綻している最小計算量のための設計に未練がましく執着しているだけである。32nという最悪計算量は適切に設計し計算量が抑制された文脈依存言語の最悪計算量より悪く最初から文脈依存言語として適切に設計するほうが自然で破綻がなく拡張性を確保できていた。たった一つの構文だけで最悪計算量が32nも増加するクソ言語に拡張性がないことは明らかである。さらにSecuremarkは再帰的バックトラックを予め対策して設計されているため文脈依存構文数が増えても最悪計算量はたかだか構文数に比例して線形にしか増加しないのに対してCommonMarkは再帰的バックトラックに根本的対策を取れないため文脈依存構文数が増えると最悪計算量が指数関数的に致命的に爆発する。または計算量を組み合わせ爆発させないために文脈依存構文の入れ子使用を制限する、存在自体が破綻と失敗の宣言に等しい制限が必要になる。文脈依存構文を強引に文脈自由構文として解析しようとして失敗したために最悪計算量が当初の想定の1nから32nに劇的に悪化し結局文脈依存言語の妥当な最悪計算量より悪い水準に落ちていることおよび文脈依存構文を追加すると最悪計算量が指数関数的に悪化することから文脈自由化に失敗したCommonMarkの破綻と失敗は明らかでありCommonMarkは文脈自由構文に固執せず最初から多少の文脈依存構文を許容するよう設計しなければならなかった。実際には文脈依存言語であるにもかかわらず文脈自由言語の範囲でしか構文解析できなければ構文解析が破綻し構文が増えるほど破綻が拡大することは自明でありすでに破綻済みで失敗済みのCommonMarkに未来などない。文脈依存言語であるMarkdownに対して文脈自由構文解析器として作られたCommonMarkは最初から開発戦略と技術選択を間違え失敗しており最初から破綻していた。CommonMarkが文脈依存言語を文脈自由言語として最小計算量で解析するために使用した手法は邪道の小手先の技術に過ぎずCommonMarkは邪道を選んだ挙句失敗に終わったのである。文脈依存言語を文脈依存言語のまま解析する正道を選んだSecuremarkが正着し文脈依存言語を文脈自由言語に歪める邪道を選んだCommonMarkが失着に終わったのは当然の帰結であり最初の解析戦略時選択の時点で決まっていたことである。文脈依存言語であるMarkdownを文脈自由言語として解析しようとした結果行き詰ったCommonMarkとその閉塞に技術的合理性はなくCommonMarkは最初からの失敗していた過去の遺物であり廃棄すべき負債である。CommonMarkに動きがないのはすでに破綻しており死んでいることに気付かれないように死んでいるからに過ぎない。このようにCommonMarkは完全に破綻し失敗に終わっているためCommonMarkの拡張や発展を期待しても無駄であり既存の文脈依存構文の最悪計算量を健全化し新たに文脈依存構文を追加可能な拡張性の高いMarkdown仕様は新しく作り直さなければ作れない。しかしCommonMarkの仕様策定者は独自の新しい仕様においても依然としてMarkdownを文脈自由化して文脈自由言語として設計しているため文脈依存構文を追加すると指数計算量になり救いようがない。しかもその構文と仕様は機械可読性を至上としているため非常に醜く人間が書くことも読むことも困難で人間に対する実用性が欠如している。
298
298
  Securemarkはスーパークラス構文が解析に失敗した入力をサブクラス構文で解析しないことにより再帰的バックトラックを回避する(解析中の構文自身はスーパークラスとサブクラスの両方に含まれるものとする)。スーパークラス構文A(`αAβ`)の解析が失敗すればサブクラス構文B(`α'Aβ'`)の解析も失敗することは自明であり試みるまでもなく解析を省略できる。これは二つの構文の文法が生成する各言語空間がスーパーセットとサブセットの関係にあるならスーパーセットの言語空間の外にある文字列はサブセットの言語空間の内に入る余地がないことからも自明である(この解析法は事前解析によっても可能だが文脈内外のオートリンクURLの括弧解析などを高速に行うこともバックトラックなしで解析することも困難であり本解析に近い解析コストを要するためMarkdownをこの事前解析により高速化することは難しい)。メモ化は解析結果の再利用による高速化の副次的または追加的効果として再帰的バックトラックを回避しているのでありメモ化は再帰的バックトラックを回避するだけなら過剰であり不要である(メモ化はバックトラックがなければ使用されないためバックトラックが少ないほとんどの入力に対してはほとんど使用されず無駄であり空間計算量を不必要に常時数倍以上増加させることから構文解析において必須にも標準にもできない。再帰的バックトラック回避のためにメモ化するとバックトラックなしで解析可能な場合も常に不必要に空間計算量が増加し平均計算量が有意に悪化することがメモ化の最大の欠点である(この問題は解析失敗時のみメモ化すれば解消可能のはずだが基本的にはこうなる)。特に文脈自由構文解析器におけるメモ化の使用は完全に無駄でありバグである。バックトラックが発生しないか他の方法で解決されるならば使用されず破棄されるメモ化は無駄である。複数の文脈で解析結果が同一である文脈独立性のある構文ならメモ化した解析結果を異なる文脈で再利用でき有用だがそのような構文は基本的に少数であるため効果が限定的であり最悪計算量は改善されない。文脈依存構文の解析を困難にするメモ化のコストの重さは解析に本来不要な高速化のために生じており不要な高速化とこのためのコストを除去すれば再帰的バックトラック回避機能だけを低コストで標準的に使用しこれまで高コストであったため敷居が高く使用困難であった文脈依存言語を低コストで手軽に定義および解析できるようになる)。この解析法により、CommonMarkならば最悪計算量がn\*32^5=33,554,432nとなる拡張Markdown言語をSecuremarkはメモ化なしで6nの最悪時間計算量で解析している。言語差を考慮せず直接比較してさえ単純なCommonMarkの最悪計算量32nに対して複雑なSecuremarkは6nに過ぎずSecuremarkはCommonMarkより最悪計算量が非常に小さい。またSecuremarkはメモ化を行っていないため空間計算量も小さい。時間計算量と空間計算量を合わせてO(n, n)と表記すると文脈依存言語の通常の最悪計算量はO(n^2, n)、メモ化により効率化できた場合もO(nm, nm)(S(m)>=m byte)(解析結果の位置や構文木等を記録するため空間使用量S(m)>はm byte以上となり数値一つやポインタ一つだけでも8byteを消費する)に過ぎないがSecuremarkのマーキング法はO(nm, nm)(S(m)=m bit)(解析の失敗フラグしか記録しないためS(m)=m bit。また包含文字列を含め全体でn byteの構文1つに対して解析結果の構文木を保持するメモ化は少なくとも構文木のサイズn byteを消費するがマーキング法のメモリ消費量は構文全体のサイズにかかわらず1bit固定である。よって100KBの構文1つに対してメモ化は100KB以上消費するがこの場合もマーキング法は1bitしか消費しない。なお成功フラグによる解析は成功フラグがないのが失敗したからか未到達だからかを判別するための情報と処理が追加で必要になり処理が複雑化しさらに成功フラグは解析のほとんどを占める成功した解析に対してメモリ消費と追加処理が発生し解析効率が全体として悪化するが失敗フラグは少数の失敗した解析でしか解析効率が悪化しないため失敗フラグを記録するほうが全体および平均として解析効率が高く優れている)と極めて効率的であり最も優れている。以上のようにSecuremarkの構文解析アルゴリズムの優位性は理論と実践いずれにおいても圧倒的である。現在のSecuremarkは開発効率と安全性優先の実装により実行性能が大きく低下しているがクライアントで個別のユーザーの操作に応じるには十分高速であるためクライアントで解析するなら解析の効率または速度が実用上問題となることはなく仕様が固まり実行効率優先の高速な実装に移れば他の環境での懸念もないだろう。またSecuremarkの再帰数制限はパーサーコンビネーターの使用による再帰的関数呼び出しに対する実装方式依存の制限であるため計算量と無関係であり再帰的関数呼び出しが生じないよう書き換えれば再帰数制限もない。従ってCommonMarkは再帰上限数と最悪計算量が一致し再帰上限数32回と最悪計算量32nが一致するがSecuremarkの最悪計算量は再帰上限数が100回だろうと100万回だろうと6n固定である。SecuremarkをCommonMarkのような再帰数制限のない実装に変換することは設計上および理論的に何の問題もないがCommonMarkをSecuremarkのような正常な文脈依存言語解析器に変更することは現在の異常な解析規則の破壊的変更による修正なしに不可能である。具体的には二重リンク`[[]()]()`を解析するときCommonMarkはバックトラックと計算量を最小化すべく文脈自由構文解析器として設計されているためリンク構文内をリンク構文が定義されていない異なる文脈として解析せず外側のリンク構文の解析を破棄して内側のみリンク構文として解析するがSecuremarkは文脈依存構文解析器とし設計されているためリンク構文内にリンク構文が定義されておらず外側のみリンクとして解析し他のMarkdown構文解析器もこのように解析しなければならない(ここでCommonMarkはリンク構文`[]()`のバックトラック除去ひいては文脈自由化に角括弧部分`[]`に対しては成功したが丸括弧部分`()`に対しては失敗したことで最悪計算量が指数計算量ないし32nに悪化した。リンク構文を本来通り文脈依存構文として解析すればリンク構文の最悪計算量が2nとなり角括弧部分に限っては1nから2nに悪化するが丸括弧部分は32nから2nに著しく改善する。ここがCommonMarkの根本的な欠陥と失敗が最も明瞭に表出している部分である)。この問題はイメージ構文においてさらに顕著でありリンク構文と同じ問題が正当な表現`![![]()]()`で発生しさらにHTMLのaltはプレーンテキストとして表示されるためMarkdownのaltもプレーンテキストとしてそのまま表示されなければならないにもかかわらず文脈を一致させ再帰的バックトラックを防ぐためにMarkdown文字列として解析しaltに`*a*`と書かれたものを`a`に不正に変換して表示する。無論新しい文脈依存構文を追加する場合も同じ制約が永遠についてまわり構文内文字列をMarkdownとして解析する文脈依存構文においてこの制約を破ると最悪計算量が32\*2^mないし32^mで指数関数的に増加する。すなわちCommonMarkは文脈依存構文を追加すると最悪計算量が32\*2^mないし32^mで指数関数的に悪化するという拡張性の致命的欠陥が存在する。こんな最悪計算量が32^mで組み合わせ爆発する欠陥言語を拡張できるわけがないことはもはや明白である。また大多数のプログラミング言語を見ても明らかなように文脈依存言語は構文内で使用可能な構文を定義しその他の構文は使用できず例外処理するのが通常でありCommonMarkのように本来使用不能な構文を外側の構文を無効化して使用可能に変える異常な言語はほとんどの人間はCommonMark以外に見たことがないだろう。ほぼすべての人間において他のすべての言語が同じ一貫した規則を持ち同じ規則で統一的に使用できるのに対してCommonMarkだけが他と異なる異常な挙動をして使用者に認知的負荷をかけるのである。破壊的変更を避けるため旧構文だけ従来通り文脈自由構文として解析し新構文を文脈依存構文として解析すればキメラ的な非常に不自然かつ歪で一貫性のない解析規則によりCommonMarkという一つの言語の中だけでもユーザーを混乱させるものとなり旧構文で使用した苦肉の策を不必要に新構文でも使用して一貫させれば文脈依存言語なのに文脈自由言語の苦肉の策の解析規則で解析されるこれもまたキメラ的な非常に不自然かつ理論的に設計ミスが明白で実用的にも認知的負荷の高い言語となる。正しく設計された言語と解析器にはありえないこのような解析規則の根本的不整合はその不整合の存在そのものが言語と解析器が誤った設計による失敗作であることを証明しており不整合が存在する限りその不整合により自らが失敗作であることを宣言し続けることになる。CommonMarkとはそういう失敗した言語と解析器なのである。このようにCommonMarkは新構文だけまたは解析器だけ文脈依存に変更しても理論的齟齬が解析結果と使用感の不自然さと違和感に明白に表れるためCommonMarkが失敗した言語である事実は到底隠し切れるものではない。Markdownはもはや負債以外の何物でもないCommonMarkの異常な解析規則を捨てて素直な文脈依存構文言語として新しい仕様を作り直すのが賢明である。
299
- 文脈依存言語を再帰的バックトラックなしで解析可能な方法は2つある。一つは解釈を予言的に決定する方法、もう一つは予備的または中間的その他事前の解析結果に対する解釈を事後に決定する方法である。前者は構文を峻別するための制約が強く後者は共通構造の適切な設計が必要でありいずれも再帰的バックトラックを防ぐために未終端の構文も受理する必要がある。しかし予言的解析は類似の異文脈構文へのバックトラックが不可能になるため共通構造についての事前解析結果のような追加情報を利用できるのでなければ類似の異文脈構文の定義が不可能になる。また共通構造をバックトラックなしで解析するにはそのための言語設計が必要であることに変わりなく任意の文字列を使用可能である必要があるURL、コード、数式などに含まれる任意の文字列が他の構文と文脈で解釈される際に共通構造を破壊するためこのような文字列を構造的に決定的に解釈する基本構造(バックトラック可能だが入力に対する解析結果がすべての文脈で構造的に共通すなわち決定的でなければならない。構文が解析されない場合も構文全体が包含されれば問題ない)を共通構造に定義しなければ構造的共通化は不可能であり分離構造は終端不要な開放可能構文としての予言的構文でなければバックトラックが不可避となる。共通構造の事前解析は一見すると最悪計算量を2nに削減できるように見えるが実際には共通構造をバックトラックなしで解析することが元の言語より容易にはなっても依然として難しくバックトラックなしで解析できたとしてもすべての解析ひいては平均計算量が+1nされるため平均的にはむしろ計算量を悪化させる方法であり仮に最悪計算量32nを事前解析により2nに抑えられたとしても平均計算量が1nならば平均計算量が2nに倍加し実行性能が半減および実行コストが倍加するため明らかに事前解析を行うべきでない。実用的なアルゴリズムの計算量において重要なのは最悪計算量がO(n^3)相当以下の実用的な計算量であるかと平均計算量でありその他は重要ではない。メモ化が空間計算量を代償に悪化させる最悪時間計算量線形化手法であるのに対して事前解析は平均時間計算量を代償に悪化させる最悪時間計算量線形化手法でありマーキング法は何も代償に悪化させない最悪時間計算量線形化手法である(無論ゼロコストではないが解析の他の部分やASTに要するコストより小さいため無視できる)。なおマーキング法を使用するSecuremarkは本来の構文解析と共通構造解析を統合し同時解析することで計算量の増加なく共通構造解析を行い共通構造を利用して最悪時間計算量を指数計算量から6nへ削減している。
299
+ 文脈依存言語を再帰的バックトラックなしで解析可能な方法は2つある。一つは解釈を予言的に決定する方法、もう一つは予備的または中間的その他事前の解析結果に対する解釈を事後に決定する方法である。前者は構文を峻別するための制約が強く後者は共通構造の適切な設計が必要でありいずれも再帰的バックトラックを防ぐために未終端の構文も受理する必要がある。しかし予言的解析は類似の異文脈構文へのバックトラックが不可能になるため共通構造についての事前解析結果のような追加情報を利用できるのでなければ類似の異文脈構文の定義が不可能になる。また共通構造をバックトラックなしで解析するにはそのための言語設計が必要であることに変わりなく任意の文字列を使用可能である必要があるURL、コード、数式などに含まれる任意の文字列が他の構文と文脈で解釈される際に共通構造を破壊するためこのような文字列を構造的に決定的に解釈する基本構造(バックトラック可能だが入力に対する解析結果がすべての文脈で構造的に共通すなわち決定的でなければならない。構文が解析されない場合も構文全体が包含されれば問題ない)を共通構造に定義しなければ構造的共通化は不可能であり分離構造は終端不要な開放可能構文としての予言的構文でなければバックトラックが不可避となる。共通構造の事前解析は一見すると最悪計算量を2nに削減できるように見えるが実際には共通構造をバックトラックなしで解析することが元の言語より容易にはなっても依然として難しくバックトラックなしで解析できたとしてもすべての解析ひいては平均計算量が+1nされるため平均的にはむしろ計算量を悪化させる方法であり仮に最悪計算量32nを事前解析により2nに抑えられたとしても平均計算量が1nならば平均計算量が2nに倍加し実行性能が半減および実行コストが倍加するため明らかに事前解析を行うべきでない。実用的なアルゴリズムの計算量において重要なのは最悪計算量がO(n^3)相当以下の実用的な計算量であるかと平均計算量でありその他は重要ではない。メモ化が空間計算量を代償に悪化させる最悪時間計算量線形化手法であるのに対して事前解析は平均時間計算量を代償に悪化させる最悪時間計算量線形化手法でありマーキング法は何も代償に悪化させない最悪時間計算量線形化手法である(無論ゼロコストではないが解析の他の部分やASTに要するコストより小さいため無視できる。空間計算量は実際にはASTにより容易に数倍になりメモリ使用量は入力サイズと並列数に制約されるため空間計算量自体はさほど重要ではなく空間計算量を増加させる処理により生じる時間オーバーヘッドのほうが本質的に重要となる。メモ化が常時記録かつ実データ記録ゆえデータ数もデータサイズも大きいのに対してマーキング法は失敗時記録かつフラグのみ記録ゆえデータ数もデータサイズも小さいことでオーバーヘッドが最小化されバックトラック率の低い入力が大多数を占める場合の平均解析速度が高速化される。平均性能すなわち重要指標が向上するならばその他の指標は許容範囲内で悪化させることができ不要な指標値を必要な指標値に変換できるならばそうしなければならない)。なおマーキング法を使用するSecuremarkは本来の構文解析と共通構造解析を統合し同時解析することで計算量の増加なく共通構造解析を行い共通構造を利用して最悪時間計算量を指数計算量から6nへ削減している。
300
300
 
301
301
  ### 実行性能
302
302
 
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! securemark v0.295.9 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED License */
1
+ /*! securemark v0.296.1 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("Prism"), require("DOMPurify"));
@@ -2585,7 +2585,7 @@ function block(parser, separation = true) {
2585
2585
  if (position === source.length) return;
2586
2586
  const result = parser(input);
2587
2587
  if (result === undefined) return;
2588
- if (separation && !(0, line_1.isBlankline)(source, context.position)) return;
2588
+ if (separation && !(0, line_1.isEmptyline)(source, context.position)) return;
2589
2589
  return context.position === source.length || source[context.position - 1] === '\n' ? result : undefined;
2590
2590
  });
2591
2591
  }
@@ -2629,7 +2629,7 @@ exports.verify = verify;
2629
2629
  Object.defineProperty(exports, "__esModule", ({
2630
2630
  value: true
2631
2631
  }));
2632
- exports.isBlankline = exports.firstline = exports.line = void 0;
2632
+ exports.isEmptyline = exports.firstline = exports.line = void 0;
2633
2633
  const parser_1 = __webpack_require__(605);
2634
2634
  function line(parser) {
2635
2635
  return (0, parser_1.failsafe)(({
@@ -2648,7 +2648,7 @@ function line(parser) {
2648
2648
  context.source = source;
2649
2649
  context.offset -= position;
2650
2650
  if (result === undefined) return;
2651
- if (context.position < position + line.length && !isBlankline(source, context.position)) return;
2651
+ if (context.position < position + line.length && !isEmptyline(source, context.position)) return;
2652
2652
  context.position = position + line.length;
2653
2653
  return result;
2654
2654
  });
@@ -2659,12 +2659,12 @@ function firstline(source, position) {
2659
2659
  return i === -1 ? source.slice(position) : source.slice(position, i + 1);
2660
2660
  }
2661
2661
  exports.firstline = firstline;
2662
- const blankline = /[^\S\n]*(?:$|\n)/y;
2663
- function isBlankline(source, position) {
2664
- blankline.lastIndex = position;
2665
- return source.length === position || source[position] === '\n' || blankline.test(source);
2662
+ const emptyline = /[^\S\n]*(?:$|\n)/y;
2663
+ function isEmptyline(source, position) {
2664
+ emptyline.lastIndex = position;
2665
+ return source.length === position || source[position] === '\n' || emptyline.test(source);
2666
2666
  }
2667
- exports.isBlankline = isBlankline;
2667
+ exports.isEmptyline = isEmptyline;
2668
2668
 
2669
2669
  /***/ },
2670
2670
 
@@ -2796,20 +2796,20 @@ function fence(opener, limit, separation = true) {
2796
2796
  context.position += matches[0].length;
2797
2797
  // Prevent annoying parsing in editing.
2798
2798
  const secondline = (0, line_1.firstline)(source, context.position);
2799
- if ((0, line_1.isBlankline)(secondline, 0) && (0, line_1.firstline)(source, context.position + secondline.length).trimEnd() !== delim) return;
2799
+ if ((0, line_1.isEmptyline)(secondline, 0) && (0, line_1.firstline)(source, context.position + secondline.length).trimEnd() !== delim) return;
2800
2800
  let block = '';
2801
2801
  let closer = '';
2802
2802
  let overflow = '';
2803
2803
  for (let count = 1;; ++count) {
2804
2804
  if (context.position === source.length) break;
2805
2805
  const line = (0, line_1.firstline)(source, context.position);
2806
- if ((closer || count > limit + 1) && (0, line_1.isBlankline)(line, 0)) break;
2806
+ if ((closer || count > limit + 1) && (0, line_1.isEmptyline)(line, 0)) break;
2807
2807
  if (closer) {
2808
2808
  overflow += line;
2809
2809
  }
2810
2810
  if (!closer && count <= limit + 1 && line.slice(0, delim.length) === delim && line.trimEnd() === delim) {
2811
2811
  closer = line;
2812
- if ((0, line_1.isBlankline)(source, context.position + line.length)) {
2812
+ if ((0, line_1.isEmptyline)(source, context.position + line.length)) {
2813
2813
  context.position += line.length;
2814
2814
  break;
2815
2815
  }
@@ -4386,10 +4386,8 @@ function parse(source) {
4386
4386
  Object.defineProperty(exports, "__esModule", ({
4387
4387
  value: true
4388
4388
  }));
4389
- exports.escape = exports.invisibleHTMLEntityNames = exports.normalize = void 0;
4390
- const parser_1 = __webpack_require__(605);
4391
- const context_1 = __webpack_require__(8669);
4392
- const htmlentity_1 = __webpack_require__(470);
4389
+ exports.escape = exports.invisibleGraphHTMLEntityNames = exports.invisibleBlankHTMLEntityNames = exports.normalize = void 0;
4390
+ const dom_1 = __webpack_require__(394);
4393
4391
  const UNICODE_REPLACEMENT_CHARACTER = '\uFFFD';
4394
4392
  function normalize(source) {
4395
4393
  return sanitize(format(source));
@@ -4398,7 +4396,7 @@ exports.normalize = normalize;
4398
4396
  function format(source) {
4399
4397
  return source.replace(/\r\n?|[\u2028\u2029]/g, '\n');
4400
4398
  }
4401
- const invalid = new RegExp([/(?![\t\r\n])[\x00-\x1F\x7F]/g.source, /(?!\u200D)[\u2006\u200B-\u200F\u202A-\u202F\u2060\uFEFF]/g.source
4399
+ const invalid = new RegExp([/(?![\t\r\n])[\x00-\x1F\x7F]/g.source, /(?![\u200C\u200D])[\u2006\u200B-\u200F\u202A-\u202F\u2060\uFEFF]/g.source
4402
4400
  // 後読みが重い
4403
4401
  ///(?<![\u1820\u1821])\u180E/g.source,
4404
4402
  ///[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g.source,
@@ -4408,9 +4406,16 @@ function sanitize(source) {
4408
4406
  }
4409
4407
  // https://dev.w3.org/html5/html-author/charref
4410
4408
  // https://en.wikipedia.org/wiki/Whitespace_character
4411
- exports.invisibleHTMLEntityNames = ['Tab', 'NewLine', 'NonBreakingSpace', 'nbsp', 'shy', 'ensp', 'emsp', 'emsp13', 'emsp14', 'numsp', 'puncsp', 'ThinSpace', 'thinsp', 'VeryThinSpace', 'hairsp', 'ZeroWidthSpace', 'NegativeVeryThinSpace', 'NegativeThinSpace', 'NegativeMediumSpace', 'NegativeThickSpace', 'zwj', 'zwnj', 'lrm', 'rlm', 'MediumSpace', 'NoBreak', 'ApplyFunction', 'af', 'InvisibleTimes', 'it', 'InvisibleComma', 'ic'];
4412
- const unreadableEscapeHTMLEntityNames = exports.invisibleHTMLEntityNames.filter(name => !['Tab', 'NewLine', 'NonBreakingSpace', 'nbsp', 'zwj', 'zwnj'].includes(name));
4413
- const unreadableEscapeCharacters = unreadableEscapeHTMLEntityNames.map(name => (0, htmlentity_1.unsafehtmlentity)((0, parser_1.input)(`&${name};`, new context_1.Context())).head.value);
4409
+ const invisibleHTMLEntityNames = ['Tab', 'NewLine', 'NonBreakingSpace', 'nbsp', 'shy', 'ensp', 'emsp', 'emsp13', 'emsp14', 'numsp', 'puncsp', 'ThinSpace', 'thinsp', 'VeryThinSpace', 'hairsp', 'ZeroWidthSpace', 'NegativeVeryThinSpace', 'NegativeThinSpace', 'NegativeMediumSpace', 'NegativeThickSpace', 'zwj', 'zwnj', 'lrm', 'rlm', 'MediumSpace', 'NoBreak', 'ApplyFunction', 'af', 'InvisibleTimes', 'it', 'InvisibleComma', 'ic'];
4410
+ const parser = (el => entity => {
4411
+ if (entity === '&NewLine;') return entity;
4412
+ el.innerHTML = entity;
4413
+ return el.textContent;
4414
+ })((0, dom_1.html)('span'));
4415
+ exports.invisibleBlankHTMLEntityNames = invisibleHTMLEntityNames.filter(name => parser(`&${name};`).trimStart() === '');
4416
+ exports.invisibleGraphHTMLEntityNames = invisibleHTMLEntityNames.filter(name => parser(`&${name};`).trimStart() !== '');
4417
+ const unreadableEscapeHTMLEntityNames = invisibleHTMLEntityNames.filter(name => !['Tab', 'NewLine', 'NonBreakingSpace', 'nbsp', 'zwj', 'zwnj'].includes(name));
4418
+ const unreadableEscapeCharacters = unreadableEscapeHTMLEntityNames.map(name => parser(`&${name};`));
4414
4419
  const unreadableEscapeCharacter = new RegExp(`[${unreadableEscapeCharacters.join('')}]`, 'g');
4415
4420
  // https://www.pandanoir.info/entry/2018/03/11/193000
4416
4421
  // http://anti.rosx.net/etc/memo/002_space.html
@@ -4421,7 +4426,7 @@ const unreadableSpecialCharacters = (/* unused pure expression or super */ null
4421
4426
  // ZERO WIDTH SPACE
4422
4427
  '\u200B',
4423
4428
  // ZERO WIDTH NON-JOINER
4424
- '\u200C',
4429
+ //'\u200C',
4425
4430
  // ZERO WIDTH JOINER
4426
4431
  //'\u200D',
4427
4432
  // LEFT-TO-RIGHT MARK
@@ -5756,7 +5761,7 @@ const delimiter = new RegExp(`${cite_1.syntax.source}|${quote_1.syntax.source}`,
5756
5761
  exports.reply = (0, combinator_1.block)((0, combinator_1.validate)(cite_1.syntax, (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.union)([cite_1.cite, quote_1.quote, (0, combinator_1.rewrite)((0, combinator_1.some)(source_1.anyline, delimiter), (0, visibility_1.visualize)((0, combinator_1.fmap)((0, combinator_1.some)(inline_1.inline), (ns, {
5757
5762
  source,
5758
5763
  position
5759
- }) => source[position - 1] === '\n' ? ns : ns.push(new parser_1.Node((0, dom_1.html)('br'), 1 /* Flag.invisible */)) && ns)))])), ns => new parser_1.List([new parser_1.Node((0, dom_1.html)('p', (0, dom_1.defrag)((0, util_1.unwrap)((0, visibility_1.trimBlankNodeEnd)(ns)))))]))));
5764
+ }) => source[position - 1] === '\n' ? ns : ns.push(new parser_1.Node((0, dom_1.html)('br'), 1 /* Flag.blank */)) && ns)))])), ns => new parser_1.List([new parser_1.Node((0, dom_1.html)('p', (0, dom_1.defrag)((0, util_1.unwrap)((0, visibility_1.trimBlankNodeEnd)(ns)))))]))));
5760
5765
 
5761
5766
  /***/ },
5762
5767
 
@@ -5808,7 +5813,7 @@ exports.cite = (0, combinator_1.line)((0, combinator_1.fmap)((0, combinator_1.op
5808
5813
  ...(0, util_1.invalid)('cite', 'syntax', 'Invalid syntax')
5809
5814
  }, (0, dom_1.defrag)([`${quotes}>`, typeof node === 'object' ? (0, dom_1.define)(node, {
5810
5815
  'data-depth': `${quotes.length + 1}`
5811
- }, node.innerText.slice(1)) : node.slice(1)]))), new parser_1.Node((0, dom_1.html)('br'), 1 /* Flag.invisible */)]);
5816
+ }, node.innerText.slice(1)) : node.slice(1)]))), new parser_1.Node((0, dom_1.html)('br'), 1 /* Flag.blank */)]);
5812
5817
  }));
5813
5818
 
5814
5819
  /***/ },
@@ -5836,7 +5841,7 @@ exports.quote = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combina
5836
5841
  math_1.math, autolink_1.autolink, source_1.unescsource])))), (ns, {
5837
5842
  source,
5838
5843
  position
5839
- }) => new parser_1.List([new parser_1.Node(source[position - 1] === '\n' ? ns.pop().value : (0, dom_1.html)('br'), 1 /* Flag.invisible */), new parser_1.Node((0, dom_1.html)('span', {
5844
+ }) => new parser_1.List([new parser_1.Node(source[position - 1] === '\n' ? ns.pop().value : (0, dom_1.html)('br'), 1 /* Flag.blank */), new parser_1.Node((0, dom_1.html)('span', {
5840
5845
  class: 'quote'
5841
5846
  }, (0, dom_1.defrag)((0, util_1.unwrap)(ns))))].reverse())), false));
5842
5847
 
@@ -6238,7 +6243,7 @@ const inline_1 = __webpack_require__(7973);
6238
6243
  const visibility_1 = __webpack_require__(6364);
6239
6244
  const util_1 = __webpack_require__(4992);
6240
6245
  const dom_1 = __webpack_require__(394);
6241
- exports.annotation = (0, combinator_1.lazy)(() => (0, combinator_1.constraint)(128 /* State.annotation */, (0, combinator_1.surround)('((', (0, combinator_1.precedence)(1, (0, combinator_1.state)(128 /* State.annotation */, (0, visibility_1.trimBlankStart)((0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]), ')', [[')', 1]])))), '))', false, [2, 1 | 4 /* Backtrack.common */, 3 | 128 /* Backtrack.doublebracket */], ([, ns], context) => context.linebreak === 0 ? new parser_1.List([new parser_1.Node((0, dom_1.html)('sup', {
6246
+ exports.annotation = (0, combinator_1.lazy)(() => (0, combinator_1.constraint)(128 /* State.annotation */, (0, combinator_1.surround)('((', (0, combinator_1.precedence)(1, (0, combinator_1.state)(128 /* State.annotation */, (0, visibility_1.beforeNonblank)((0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]), ')', [[')', 1]])))), '))', false, [2, 1 | 4 /* Backtrack.common */, 3 | 128 /* Backtrack.doublebracket */], ([, ns], context) => context.linebreak === 0 ? new parser_1.List([new parser_1.Node((0, dom_1.html)('sup', {
6242
6247
  class: 'annotation'
6243
6248
  }, [(0, dom_1.html)('span', (0, dom_1.defrag)((0, util_1.unwrap)((0, visibility_1.trimBlankNodeEnd)(ns))))]))]) : undefined, (_, context) => {
6244
6249
  const {
@@ -7186,7 +7191,7 @@ Object.setPrototypeOf(attrspecs, null);
7186
7191
  Object.values(attrspecs).forEach(o => Object.setPrototypeOf(o, null));
7187
7192
  exports.html = (0, combinator_1.lazy)(() => (0, combinator_1.validate)(/<[a-z]+(?=[ >])/yi, (0, combinator_1.union)([(0, combinator_1.surround)(
7188
7193
  // https://html.spec.whatwg.org/multipage/syntax.html#void-elements
7189
- (0, source_1.str)(/<(?:area|base|br|col|embed|hr|img|input|link|meta|source|track|wbr)(?=[ >])/y), (0, combinator_1.precedence)(9, (0, combinator_1.some)((0, combinator_1.union)([exports.attribute]))), (0, combinator_1.open)((0, source_1.str)(/ ?/y), (0, source_1.str)('>'), true), true, [], ([as, bs = new parser_1.List(), cs], context) => new parser_1.List([new parser_1.Node(elem(as.head.value.slice(1), false, [...(0, util_1.unwrap)(as.import(bs).import(cs))], new parser_1.List(), new parser_1.List(), context), as.head.value === '<wbr' ? 1 /* Flag.invisible */ : 0 /* Flag.none */)]), ([as, bs = new parser_1.List()], context) => new parser_1.List([new parser_1.Node(elem(as.head.value.slice(1), false, [...(0, util_1.unwrap)(as.import(bs))], new parser_1.List(), new parser_1.List(), context))])), (0, combinator_1.match)(new RegExp(String.raw`<(${TAGS.join('|')})(?=[ >])`, 'y'), (0, memoize_1.memoize)(([, tag]) => (0, combinator_1.surround)((0, combinator_1.surround)((0, source_1.str)(`<${tag}`), (0, combinator_1.precedence)(9, (0, combinator_1.some)(exports.attribute)), (0, combinator_1.open)((0, source_1.str)(/ ?/y), (0, source_1.str)('>'), true), true, [], ([as, bs = new parser_1.List(), cs]) => as.import(bs).import(cs), ([as, bs = new parser_1.List()]) => as.import(bs)),
7194
+ (0, source_1.str)(/<(?:area|base|br|col|embed|hr|img|input|link|meta|source|track|wbr)(?=[ >])/y), (0, combinator_1.precedence)(9, (0, combinator_1.some)((0, combinator_1.union)([exports.attribute]))), (0, combinator_1.open)((0, source_1.str)(/ ?/y), (0, source_1.str)('>'), true), true, [], ([as, bs = new parser_1.List(), cs], context) => new parser_1.List([new parser_1.Node(elem(as.head.value.slice(1), false, [...(0, util_1.unwrap)(as.import(bs).import(cs))], new parser_1.List(), new parser_1.List(), context), as.head.value === '<wbr' ? 1 /* Flag.blank */ : 0 /* Flag.none */)]), ([as, bs = new parser_1.List()], context) => new parser_1.List([new parser_1.Node(elem(as.head.value.slice(1), false, [...(0, util_1.unwrap)(as.import(bs))], new parser_1.List(), new parser_1.List(), context))])), (0, combinator_1.match)(new RegExp(String.raw`<(${TAGS.join('|')})(?=[ >])`, 'y'), (0, memoize_1.memoize)(([, tag]) => (0, combinator_1.surround)((0, combinator_1.surround)((0, source_1.str)(`<${tag}`), (0, combinator_1.precedence)(9, (0, combinator_1.some)(exports.attribute)), (0, combinator_1.open)((0, source_1.str)(/ ?/y), (0, source_1.str)('>'), true), true, [], ([as, bs = new parser_1.List(), cs]) => as.import(bs).import(cs), ([as, bs = new parser_1.List()]) => as.import(bs)),
7190
7195
  // 不可視のHTML構造が可視構造を変化させるべきでない。
7191
7196
  // 可視のHTMLは優先度変更を検討する。
7192
7197
  // このため`<>`記号は将来的に共通構造を変化させる可能性があり
@@ -7200,7 +7205,7 @@ function elem(tag, content, as, bs, cs, context) {
7200
7205
  if (content) {
7201
7206
  if (cs.length === 0) return ielem('tag', `Missing the closing HTML tag "</${tag}>"`, context);
7202
7207
  if (bs.length === 0) return ielem('content', `Missing the content`, context);
7203
- if (!(0, visibility_1.isLooseNodeStart)(bs)) return ielem('content', `Missing the visible content in the same line`, context);
7208
+ if (!(0, visibility_1.isNonblankFirstLine)(bs)) return ielem('content', `Missing the visible content in the same line`, context);
7204
7209
  }
7205
7210
  const [attrs] = attributes('html', attrspecs[tag], as.slice(1, as.at(-1) === '>' ? -1 : as.length));
7206
7211
  if (/(?<!\S)invalid(?!\S)/.test(attrs['class'] ?? '')) return ielem('attribute', 'Invalid HTML attribute', context);
@@ -7265,7 +7270,7 @@ const combinator_1 = __webpack_require__(3484);
7265
7270
  const source_1 = __webpack_require__(8745);
7266
7271
  const util_1 = __webpack_require__(4992);
7267
7272
  const dom_1 = __webpack_require__(394);
7268
- exports.unsafehtmlentity = (0, combinator_1.surround)((0, source_1.str)('&'), (0, source_1.str)(/[0-9A-Za-z]+/y), (0, source_1.str)(';'), false, [3 | 8 /* Backtrack.unescapable */], ([as, bs, cs]) => new parser_1.List([new parser_1.Node(parser(as.head.value + bs.head.value + cs.head.value), (0, node_1.isinvisibleHTMLEntityName)(bs.head.value) ? 1 /* Flag.invisible */ : 0 /* Flag.none */)]), ([as, bs]) => new parser_1.List([new parser_1.Node(as.head.value + (bs?.head?.value ?? ''))]));
7273
+ exports.unsafehtmlentity = (0, combinator_1.surround)((0, source_1.str)('&'), (0, source_1.str)(/[0-9A-Za-z]+/y), (0, source_1.str)(';'), false, [3 | 8 /* Backtrack.unescapable */], ([as, bs, cs]) => new parser_1.List([new parser_1.Node(parser(as.head.value + bs.head.value + cs.head.value), (0, node_1.isBlankHTMLEntityName)(bs.head.value) ? 1 /* Flag.blank */ : 0 /* Flag.none */)]), ([as, bs]) => new parser_1.List([new parser_1.Node(as.head.value + (bs?.head?.value ?? ''))]));
7269
7274
  exports.htmlentity = (0, combinator_1.fmap)((0, combinator_1.union)([exports.unsafehtmlentity]), ([{
7270
7275
  value,
7271
7276
  flags
@@ -7355,7 +7360,7 @@ const optspec = {
7355
7360
  rel: ['nofollow']
7356
7361
  };
7357
7362
  Object.setPrototypeOf(optspec, null);
7358
- exports.textlink = (0, combinator_1.lazy)(() => (0, combinator_1.bind)((0, combinator_1.subsequence)([(0, combinator_1.constraint)(8 /* State.link */, (0, combinator_1.state)(251 /* State.linkers */, (0, combinator_1.dup)((0, combinator_1.surround)('[', (0, combinator_1.precedence)(1, (0, visibility_1.trimBlankStart)((0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]), ']', [[']', 1]]))), ']', true, [3 | 4 /* Backtrack.common */ | 64 /* Backtrack.link */, 2 | 32 /* Backtrack.ruby */], ([, ns = new parser_1.List()], context) => {
7363
+ exports.textlink = (0, combinator_1.lazy)(() => (0, combinator_1.bind)((0, combinator_1.subsequence)([(0, combinator_1.constraint)(8 /* State.link */, (0, combinator_1.state)(251 /* State.linkers */, (0, combinator_1.dup)((0, combinator_1.surround)('[', (0, combinator_1.precedence)(1, (0, visibility_1.beforeNonblank)((0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]), ']', [[']', 1]]))), ']', true, [3 | 4 /* Backtrack.common */ | 64 /* Backtrack.link */, 2 | 32 /* Backtrack.ruby */], ([, ns = new parser_1.List()], context) => {
7359
7364
  if (context.linebreak !== 0) {
7360
7365
  const head = context.position - context.range;
7361
7366
  return void (0, combinator_1.setBacktrack)(context, 2 | 64 /* Backtrack.link */ | 32 /* Backtrack.ruby */, head);
@@ -7595,15 +7600,20 @@ exports.media = (0, combinator_1.lazy)(() => (0, combinator_1.constraint)(4 /* S
7595
7600
  return ns;
7596
7601
  })), (0, combinator_1.dup)((0, combinator_1.surround)(/{(?![{}])/y, (0, combinator_1.precedence)(9, (0, combinator_1.inits)([link_1.uri, (0, combinator_1.some)(option)])), / ?}/y, false, [], undefined, ([as, bs]) => bs && as.import(bs).push(new parser_1.Node("\u0018" /* Command.Cancel */)) && as))]), nodes => nodes.length === 1 ? new parser_1.List([new parser_1.Node(new parser_1.List([new parser_1.Node('')])), nodes.delete(nodes.head)]) : new parser_1.List([new parser_1.Node(new parser_1.List([new parser_1.Node(nodes.head.value.foldl((acc, {
7597
7602
  value
7598
- }) => acc + value, ''))])), nodes.delete(nodes.last)])), ([{
7603
+ }) => acc + value, ''), nodes.head.value.head?.flags)])), nodes.delete(nodes.last)])), ([{
7599
7604
  value: [{
7600
- value: text
7605
+ value: text,
7606
+ flags
7601
7607
  }]
7602
7608
  }, {
7603
7609
  value: params
7604
7610
  }], context) => {
7605
- if (text && text.trimStart() === '') return;
7606
- text = text.trim();
7611
+ if (flags & 1 /* Flag.blank */) return;
7612
+ if (text) {
7613
+ const tmp = text;
7614
+ text = text.trim();
7615
+ if (text === '' || text[0] !== tmp[0]) return;
7616
+ }
7607
7617
  (0, combinator_1.consume)(100, context);
7608
7618
  if (params.last.value === "\u0018" /* Command.Cancel */) {
7609
7619
  params.pop();
@@ -7693,7 +7703,7 @@ const source_1 = __webpack_require__(8745);
7693
7703
  const visibility_1 = __webpack_require__(6364);
7694
7704
  const util_1 = __webpack_require__(4992);
7695
7705
  const dom_1 = __webpack_require__(394);
7696
- exports.reference = (0, combinator_1.lazy)(() => (0, combinator_1.constraint)(64 /* State.reference */, (0, combinator_1.surround)((0, source_1.str)('[['), (0, combinator_1.precedence)(1, (0, combinator_1.state)(128 /* State.annotation */ | 64 /* State.reference */, (0, combinator_1.subsequence)([abbr, (0, visibility_1.trimBlankStart)((0, combinator_1.some)(inline_1.inline, ']', [[']', 1]]))]))), ']]', false, [2, 1 | 4 /* Backtrack.common */, 3 | 128 /* Backtrack.doublebracket */], ([, ns], context) => {
7706
+ exports.reference = (0, combinator_1.lazy)(() => (0, combinator_1.constraint)(64 /* State.reference */, (0, combinator_1.surround)((0, source_1.str)('[['), (0, combinator_1.precedence)(1, (0, combinator_1.state)(128 /* State.annotation */ | 64 /* State.reference */, (0, combinator_1.subsequence)([abbr, (0, visibility_1.beforeNonblank)((0, combinator_1.some)(inline_1.inline, ']', [[']', 1]]))]))), ']]', false, [2, 1 | 4 /* Backtrack.common */, 3 | 128 /* Backtrack.doublebracket */], ([, ns], context) => {
7697
7707
  const {
7698
7708
  position,
7699
7709
  range,
@@ -7817,7 +7827,7 @@ const util_1 = __webpack_require__(4992);
7817
7827
  const dom_1 = __webpack_require__(394);
7818
7828
  exports.ruby = (0, combinator_1.lazy)(() => (0, combinator_1.bind)((0, combinator_1.inits)([(0, combinator_1.dup)((0, combinator_1.surround)('[', text, ']', false, [1 | 4 /* Backtrack.common */, 3 | 32 /* Backtrack.ruby */], ([, ns]) => {
7819
7829
  ns && ns.last?.value === '' && ns.pop();
7820
- return (0, visibility_1.isTightNodeStart)(ns) ? ns : undefined;
7830
+ return (0, visibility_1.isNonblankNodeStart)(ns) ? ns : undefined;
7821
7831
  })), (0, combinator_1.dup)((0, combinator_1.surround)('(', text, ')', false, [3 | 32 /* Backtrack.ruby */]))]), ([{
7822
7832
  value: texts
7823
7833
  }, {
@@ -7976,12 +7986,9 @@ const bracket = (0, combinator_1.lazy)(() => (0, combinator_1.union)([(0, combin
7976
7986
  Object.defineProperty(exports, "__esModule", ({
7977
7987
  value: true
7978
7988
  }));
7979
- exports.isinvisibleHTMLEntityName = void 0;
7989
+ exports.isBlankHTMLEntityName = void 0;
7980
7990
  const normalize_1 = __webpack_require__(4490);
7981
- function isinvisibleHTMLEntityName(name) {
7982
- return normalize_1.invisibleHTMLEntityNames.includes(name);
7983
- }
7984
- exports.isinvisibleHTMLEntityName = isinvisibleHTMLEntityName;
7991
+ exports.isBlankHTMLEntityName = eval(['name => {', 'switch(name){', normalize_1.invisibleBlankHTMLEntityNames.map(name => `case '${name}':`).join(''), 'return true;', 'default:', 'return false;', '}', '}'].join(''));
7985
7992
 
7986
7993
  /***/ },
7987
7994
 
@@ -8486,7 +8493,7 @@ const escsource = ({
8486
8493
  return new parser_1.List();
8487
8494
  case '\n':
8488
8495
  context.linebreak ||= source.length - position;
8489
- return new parser_1.List([new parser_1.Node((0, dom_1.html)('br'))]);
8496
+ return new parser_1.List([new parser_1.Node((0, dom_1.html)('br'), 1 /* Flag.blank */)]);
8490
8497
  default:
8491
8498
  if (context.sequential) return new parser_1.List([new parser_1.Node(char)]);
8492
8499
  let i = (0, text_1.next)(source, position, state, delimiter);
@@ -8636,17 +8643,16 @@ const text = input => {
8636
8643
  case '\n':
8637
8644
  return new parser_1.List();
8638
8645
  default:
8639
- const flags = source[position + 1].trimStart() ? 0 /* Flag.none */ : 1 /* Flag.invisible */;
8640
8646
  (0, combinator_1.consume)(1, context);
8641
8647
  context.position += 1;
8642
- return new parser_1.List([new parser_1.Node(source.slice(position + 1, context.position), flags)]);
8648
+ return new parser_1.List([new parser_1.Node(source.slice(position + 1, context.position))]);
8643
8649
  }
8644
8650
  case '\r':
8645
8651
  (0, combinator_1.consume)(-1, context);
8646
8652
  return new parser_1.List();
8647
8653
  case '\n':
8648
8654
  context.linebreak ||= source.length - position;
8649
- return new parser_1.List([new parser_1.Node((0, dom_1.html)('br'), 1 /* Flag.invisible */)]);
8655
+ return new parser_1.List([new parser_1.Node((0, dom_1.html)('br'), 1 /* Flag.blank */)]);
8650
8656
  default:
8651
8657
  if (context.sequential) return new parser_1.List([new parser_1.Node(char)]);
8652
8658
  exports.nonWhitespace.lastIndex = position + 1;
@@ -8659,9 +8665,7 @@ const text = input => {
8659
8665
  context.position += i - 1;
8660
8666
  const linestart = position === 0 || source[position - 1] === '\n';
8661
8667
  if (position === context.position || s && !linestart || lineend) return new parser_1.List();
8662
- const str = source.slice(position, context.position);
8663
- const flags = str.length === 1 && str.trimStart() === '' ? 1 /* Flag.invisible */ : 0 /* Flag.none */;
8664
- return new parser_1.List([new parser_1.Node(str, flags)]);
8668
+ return new parser_1.List([new parser_1.Node(source.slice(position, context.position))]);
8665
8669
  }
8666
8670
  };
8667
8671
  exports.text = text;
@@ -8878,7 +8882,7 @@ const unescsource = ({
8878
8882
  return new parser_1.List();
8879
8883
  case '\n':
8880
8884
  context.linebreak ||= source.length - position;
8881
- return new parser_1.List([new parser_1.Node((0, dom_1.html)('br'))]);
8885
+ return new parser_1.List([new parser_1.Node((0, dom_1.html)('br'), 1 /* Flag.blank */)]);
8882
8886
  default:
8883
8887
  if (context.sequential) return new parser_1.List([new parser_1.Node(char)]);
8884
8888
  text_1.nonWhitespace.lastIndex = position + 1;
@@ -9034,15 +9038,15 @@ exports.stringify = stringify;
9034
9038
  Object.defineProperty(exports, "__esModule", ({
9035
9039
  value: true
9036
9040
  }));
9037
- exports.trimBlankNodeEnd = exports.trimBlankEnd = exports.trimBlankStart = exports.trimBlank = exports.isTightNodeStart = exports.isLooseNodeStart = exports.beforeNonblank = exports.blankWith = exports.afterNonblank = exports.visualize = void 0;
9041
+ exports.trimBlankNodeEnd = exports.trimBlankEnd = exports.trimBlank = exports.isNonblankNodeStart = exports.isNonblankFirstLine = exports.beforeNonblank = exports.blankWith = exports.afterNonblank = exports.visualize = void 0;
9038
9042
  const parser_1 = __webpack_require__(605);
9039
9043
  const combinator_1 = __webpack_require__(3484);
9040
9044
  const normalize_1 = __webpack_require__(4490);
9041
9045
  var blank;
9042
9046
  (function (blank) {
9043
- blank.line = new RegExp(/((?:^|\n)[^\S\n]*(?=\S))((?:[^\S\n]|\\(?=$|\s)|&IHN;|<wbr ?>)+(?=$|\n))/g.source.replace('IHN', `(?:${normalize_1.invisibleHTMLEntityNames.join('|')})`), 'g');
9044
- blank.start = new RegExp(/(?:[^\S\n]|\\(?=$|\s)|&IHN;|<wbr ?>)+/y.source.replace('IHN', `(?:${normalize_1.invisibleHTMLEntityNames.join('|')})`), 'y');
9045
- blank.unit = new RegExp(/(?:[^\S\n]|\\(?=$|\s)|&IHN;|<wbr ?>)/y.source.replace('IHN', `(?:${normalize_1.invisibleHTMLEntityNames.join('|')})`), 'y');
9047
+ blank.line = new RegExp(/((?:^|\n)[^\S\n]*(?=\S))((?:[^\S\n]|\\(?=$|\s)|&IBHN;|<wbr ?>)+(?=$|\n))/g.source.replace('IBHN', `(?:${normalize_1.invisibleBlankHTMLEntityNames.join('|')})`), 'g');
9048
+ blank.start = new RegExp(/(?:[^\S\n]|\\(?=$|\s)|&IBHN;|<wbr ?>)+/y.source.replace('IBHN', `(?:${normalize_1.invisibleBlankHTMLEntityNames.join('|')})`), 'y');
9049
+ blank.unit = new RegExp(/(?:[^\S\n]|\\(?=$|\s)|&IBHN;|<wbr ?>)/y.source.replace('IBHN', `(?:${normalize_1.invisibleBlankHTMLEntityNames.join('|')})`), 'y');
9046
9050
  })(blank || (blank = {}));
9047
9051
  function visualize(parser) {
9048
9052
  return (0, combinator_1.convert)(source => source.replace(blank.line, `$1${"\u001B" /* Command.Escape */}$2`), parser);
@@ -9053,17 +9057,17 @@ function blankWith(starts, delimiter) {
9053
9057
  return new RegExp([
9054
9058
  // 空行除去
9055
9059
  // 完全な空行はエスケープ済みなので再帰的バックトラックにはならない。
9056
- String.raw`(?:${starts}(?:\\?\s|&(?:${normalize_1.invisibleHTMLEntityNames.join('|')});|<wbr ?>)*)?`, typeof delimiter === 'string' ? delimiter.replace(/[*+()\[\]]/g, '\\$&') : delimiter.source].join(''), 'y');
9060
+ String.raw`(?:${starts}(?:\\?\s|&(?:${normalize_1.invisibleBlankHTMLEntityNames.join('|')});|<wbr ?>)*)?`, typeof delimiter === 'string' ? delimiter.replace(/[*+()\[\]]/g, '\\$&') : delimiter.source].join(''), 'y');
9057
9061
  }
9058
9062
  exports.blankWith = blankWith;
9059
9063
  function nonblankWith(delimiter) {
9060
- return new RegExp([String.raw`(?<!\s|&(?:${normalize_1.invisibleHTMLEntityNames.join('|')});|<wbr ?>)`, typeof delimiter === 'string' ? delimiter.replace(/[*+()\[\]]/g, '\\$&') : delimiter.source].join(''), 'y');
9064
+ return new RegExp([String.raw`(?<!\s|&(?:${normalize_1.invisibleBlankHTMLEntityNames.join('|')});|<wbr ?>)`, typeof delimiter === 'string' ? delimiter.replace(/[*+()\[\]]/g, '\\$&') : delimiter.source].join(''), 'y');
9061
9065
  }
9062
9066
  function beforeNonblank(parser) {
9063
- return input => isTightStart(input) ? parser(input) : undefined;
9067
+ return input => isNonblankStart(input) ? parser(input) : undefined;
9064
9068
  }
9065
9069
  exports.beforeNonblank = beforeNonblank;
9066
- function isTightStart(input) {
9070
+ function isNonblankStart(input) {
9067
9071
  const {
9068
9072
  context
9069
9073
  } = input;
@@ -9084,38 +9088,35 @@ function isTightStart(input) {
9084
9088
  return !reg.test(source);
9085
9089
  }
9086
9090
  }
9087
- function isLooseNodeStart(nodes) {
9091
+ function isNonblankFirstLine(nodes) {
9088
9092
  if (nodes.length === 0) return true;
9089
9093
  for (const node of nodes) {
9090
- if (isVisible(node)) return true;
9091
- if (typeof node.value === 'object' && node.value.tagName === 'BR') break;
9094
+ if (isNonblank(node)) return true;
9095
+ if (node.flags & 1 /* Flag.blank */ && typeof node.value === 'object' && node.value.tagName === 'BR') break;
9092
9096
  }
9093
9097
  return false;
9094
9098
  }
9095
- exports.isLooseNodeStart = isLooseNodeStart;
9096
- function isTightNodeStart(nodes) {
9099
+ exports.isNonblankFirstLine = isNonblankFirstLine;
9100
+ function isNonblankNodeStart(nodes) {
9097
9101
  if (nodes.length === 0) return true;
9098
- return isVisible(nodes.head, 0);
9099
- }
9100
- exports.isTightNodeStart = isTightNodeStart;
9101
- //export function isTightNodeEnd(nodes: readonly (HTMLElement | string)[]): boolean {
9102
- // if (nodes.length === 0) return true;
9103
- // return isVisible(nodes.at(-1)!, -1);
9104
- //}
9105
- function isVisible({
9102
+ return isNonblank(nodes.head, 0);
9103
+ }
9104
+ exports.isNonblankNodeStart = isNonblankNodeStart;
9105
+ function isNonblank({
9106
9106
  value: node,
9107
9107
  flags
9108
9108
  }, strpos) {
9109
- if (strpos === undefined || typeof node !== 'string') return !(flags & 1 /* Flag.invisible */);
9110
- const char = node && node[strpos && node.length + strpos];
9111
- switch (char) {
9109
+ if (flags & 1 /* Flag.blank */) return false;
9110
+ if (typeof node !== 'string') return true;
9111
+ const str = node && strpos !== undefined ? node[strpos >= 0 ? strpos : node.length + strpos] : node;
9112
+ switch (str) {
9112
9113
  case '':
9113
9114
  case ' ':
9114
9115
  case '\t':
9115
9116
  case '\n':
9116
9117
  return false;
9117
9118
  default:
9118
- return char.trimStart() !== '';
9119
+ return str.trimStart() !== '';
9119
9120
  }
9120
9121
  }
9121
9122
  function trimBlank(parser) {
@@ -9139,37 +9140,21 @@ function trimBlankStart(parser) {
9139
9140
  return context.position === source.length ? new parser_1.List() : parser(input);
9140
9141
  });
9141
9142
  }
9142
- exports.trimBlankStart = trimBlankStart;
9143
9143
  function trimBlankEnd(parser) {
9144
9144
  return (0, combinator_1.fmap)(parser, trimBlankNodeEnd);
9145
9145
  }
9146
9146
  exports.trimBlankEnd = trimBlankEnd;
9147
- //export function trimBlankNode<N extends HTMLElement | string>(nodes: N[]): N[] {
9148
- // return trimBlankNodeStart(trimBlankNodeEnd(nodes));
9149
- //}
9150
- //function trimBlankNodeStart<N extends HTMLElement | string>(nodes: N[]): N[] {
9151
- // for (let node = nodes[0]; nodes.length > 0 && !isVisible(node = nodes[0], 0);) {
9152
- // if (typeof node === 'string') {
9153
- // const pos = node.trimStart().length;
9154
- // if (pos > 0) {
9155
- // nodes[0] = node.slice(-pos) as N;
9156
- // break;
9157
- // }
9158
- // }
9159
- // else if (nodes.length === 1 && node.className === 'indexer') {
9160
- // break;
9161
- // }
9162
- // nodes.shift();
9163
- // }
9164
- // return nodes;
9165
- //}
9166
9147
  function trimBlankNodeEnd(nodes) {
9167
- const skip = typeof nodes.last?.value === 'object' && nodes.last.value.className === 'indexer';
9168
- for (let node = skip ? nodes.last?.prev : nodes.last; node && !isVisible(node, -1);) {
9169
- if (typeof node.value === 'string') {
9170
- const str = node.value.trimEnd();
9171
- if (str.length > 0) {
9172
- node.value = str;
9148
+ const skip = nodes.last && ~nodes.last.flags & 1 /* Flag.blank */ && typeof nodes.last.value === 'object' ? nodes.last.value.className === 'indexer' : false;
9149
+ for (let node = skip ? nodes.last?.prev : nodes.last; node;) {
9150
+ if (~node.flags & 1 /* Flag.blank */) {
9151
+ if (typeof node.value === 'string') {
9152
+ const str = node.value.trimEnd();
9153
+ if (str.length > 0) {
9154
+ node.value = str;
9155
+ break;
9156
+ }
9157
+ } else {
9173
9158
  break;
9174
9159
  }
9175
9160
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "securemark",
3
- "version": "0.295.9",
3
+ "version": "0.296.1",
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",
@@ -1,5 +1,5 @@
1
1
  import { Parser, failsafe } from '../../data/parser';
2
- import { isBlankline } from './line';
2
+ import { isEmptyline } from './line';
3
3
 
4
4
  export function block<P extends Parser>(parser: P, separation?: boolean): P;
5
5
  export function block<N>(parser: Parser<N>, separation = true): Parser<N> {
@@ -10,7 +10,7 @@ export function block<N>(parser: Parser<N>, separation = true): Parser<N> {
10
10
  if (position === source.length) return;
11
11
  const result = parser(input);
12
12
  if (result === undefined) return;
13
- if (separation && !isBlankline(source, context.position)) return;
13
+ if (separation && !isEmptyline(source, context.position)) return;
14
14
  assert(context.position === source.length || source[context.position - 1] === '\n');
15
15
  return context.position === source.length || source[context.position - 1] === '\n'
16
16
  ? result
@@ -14,7 +14,7 @@ export function line<N>(parser: Parser<N>): Parser<N> {
14
14
  context.source = source;
15
15
  context.offset -= position;
16
16
  if (result === undefined) return;
17
- if (context.position < position + line.length && !isBlankline(source, context.position)) return;
17
+ if (context.position < position + line.length && !isEmptyline(source, context.position)) return;
18
18
  context.position = position + line.length;
19
19
  return result;
20
20
  });
@@ -27,10 +27,10 @@ export function firstline(source: string, position: number): string {
27
27
  : source.slice(position, i + 1);
28
28
  }
29
29
 
30
- const blankline = /[^\S\n]*(?:$|\n)/y;
31
- export function isBlankline(source: string, position: number): boolean {
32
- blankline.lastIndex = position;
30
+ const emptyline = /[^\S\n]*(?:$|\n)/y;
31
+ export function isEmptyline(source: string, position: number): boolean {
32
+ emptyline.lastIndex = position;
33
33
  return source.length === position
34
34
  || source[position] === '\n'
35
- || blankline.test(source);
35
+ || emptyline.test(source);
36
36
  }
@@ -1,6 +1,6 @@
1
1
  import { Parser, List, Node, Context, failsafe } from '../../data/parser';
2
2
  import { consume } from '../../../combinator';
3
- import { firstline, isBlankline } from '../constraint/line';
3
+ import { firstline, isEmptyline } from '../constraint/line';
4
4
  import { push } from 'spica/array';
5
5
 
6
6
  export function fence<C extends Context, D extends Parser<unknown, C>[]>(opener: RegExp, limit: number, separation = true): Parser<string, C, D> {
@@ -20,20 +20,20 @@ export function fence<C extends Context, D extends Parser<unknown, C>[]>(opener:
20
20
  context.position += matches[0].length;
21
21
  // Prevent annoying parsing in editing.
22
22
  const secondline = firstline(source, context.position);
23
- if (isBlankline(secondline, 0) && firstline(source, context.position + secondline.length).trimEnd() !== delim) return;
23
+ if (isEmptyline(secondline, 0) && firstline(source, context.position + secondline.length).trimEnd() !== delim) return;
24
24
  let block = '';
25
25
  let closer = '';
26
26
  let overflow = '';
27
27
  for (let count = 1; ; ++count) {
28
28
  if (context.position === source.length) break;
29
29
  const line = firstline(source, context.position);
30
- if ((closer || count > limit + 1) && isBlankline(line, 0)) break;
30
+ if ((closer || count > limit + 1) && isEmptyline(line, 0)) break;
31
31
  if(closer) {
32
32
  overflow += line;
33
33
  }
34
34
  if (!closer && count <= limit + 1 && line.slice(0, delim.length) === delim && line.trimEnd() === delim) {
35
35
  closer = line;
36
- if (isBlankline(source, context.position + line.length)) {
36
+ if (isEmptyline(source, context.position + line.length)) {
37
37
  context.position += line.length;
38
38
  break;
39
39
  }