@traq-markdown-engine/sdk 0.1.0
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/LICENSE +22 -0
- package/README.md +193 -0
- package/THIRD_PARTY_NOTICES.md +51 -0
- package/dist/contract.json +18 -0
- package/dist/embedding.d.ts +5 -0
- package/dist/embedding.js +34 -0
- package/dist/generated/artifact.d.ts +2 -0
- package/dist/generated/artifact.js +3 -0
- package/dist/generated/nodes.d.ts +54 -0
- package/dist/generated/nodes.js +17 -0
- package/dist/generated/presets.d.ts +7 -0
- package/dist/generated/presets.js +4 -0
- package/dist/generated/processing.d.ts +48 -0
- package/dist/generated/processing.js +1 -0
- package/dist/index.css +965 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +95 -0
- package/dist/parser.wasm +0 -0
- package/dist/renderer/condensed.d.ts +4 -0
- package/dist/renderer/condensed.js +73 -0
- package/dist/renderer/embeddings.d.ts +23 -0
- package/dist/renderer/embeddings.js +145 -0
- package/dist/renderer/image-domains.d.ts +2 -0
- package/dist/renderer/image-domains.js +11 -0
- package/dist/renderer/index.d.ts +27 -0
- package/dist/renderer/index.js +93 -0
- package/dist/renderer/links.d.ts +8 -0
- package/dist/renderer/links.js +16 -0
- package/package.json +84 -0
- package/styles/animation/_ascension.sass +34 -0
- package/styles/animation/_atsumori.sass +19 -0
- package/styles/animation/_attract.sass +19 -0
- package/styles/animation/_conga.sass +11 -0
- package/styles/animation/_flashy.sass +7 -0
- package/styles/animation/_happa.sass +15 -0
- package/styles/animation/_index.sass +18 -0
- package/styles/animation/_invert.sass +5 -0
- package/styles/animation/_parrot.sass +5 -0
- package/styles/animation/_party.sass +11 -0
- package/styles/animation/_pull.sass +9 -0
- package/styles/animation/_pyon.sass +9 -0
- package/styles/animation/_rainbow.sass +5 -0
- package/styles/animation/_rotate.sass +11 -0
- package/styles/animation/_shake.sass +9 -0
- package/styles/animation/_stretch.sass +47 -0
- package/styles/animation/_turn.sass +11 -0
- package/styles/animation/_wiggle.sass +23 -0
- package/styles/animation/_zoom.sass +9 -0
- package/styles/index.scss +3 -0
- package/styles/markdown.scss +377 -0
- package/styles/stamp.scss +32 -0
- package/styles/stampEffect.scss +102 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 traP
|
|
4
|
+
Copyright (c) 2026 東京工業大学デジタル創作同好会traP
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# sdk: traQ Markdown
|
|
2
|
+
|
|
3
|
+
traQ 向けの Markdown 文法・通知処理の構成と、Rust・WebAssembly・Go・TypeScript 向けの配布を所有します。文法・AST の契約・検証は Rust が所有します。
|
|
4
|
+
|
|
5
|
+
- npm: **`@traq-markdown-engine/sdk`**
|
|
6
|
+
- Go module: **`github.com/uni-kakurenbo/traq-markdown-engine/packages/sdk/go`**
|
|
7
|
+
|
|
8
|
+
文法の実装は [core](../core/README.md)、[commonmark-plugin](../plugins/commonmark/README.md)、[traq-plugin](../plugins/traq/README.md) にあります。このリポジトリで配布するプリセットを選び、Wasm と対応する型を生成します。
|
|
9
|
+
|
|
10
|
+
## 構成と責任
|
|
11
|
+
|
|
12
|
+
| 場所 | 責任 |
|
|
13
|
+
| ----------------------------- | ---------------------------------------------------------------------------- |
|
|
14
|
+
| `crates/grammar` | CommonMark・汎用拡張・traP 拡張を選択し、文法プリセットを構成 |
|
|
15
|
+
| `crates/processing` | AST を受け取る PlainText renderer と extractor、および traQ 向けの方針を構成 |
|
|
16
|
+
| `crates/wasm` | 配布する文法・ノード型・処理 API を Wasm として公開 |
|
|
17
|
+
| `go`・`typescript`・`scripts` | この配布物に対応する bindings と型生成 |
|
|
18
|
+
|
|
19
|
+
共通機構は core、CommonMark と汎用拡張は commonmark、traP 固有の拡張部品は
|
|
20
|
+
traq-plugin にあります。このリポジトリがそれらに依存し、traQ 向けに組み合わせます。
|
|
21
|
+
下位の部品はこの配布物に依存しません。bindings はここで選んだ型とプリセットに対応します。
|
|
22
|
+
|
|
23
|
+
## ビルド
|
|
24
|
+
|
|
25
|
+
環境準備、ビルド、検証は [ルートの CONTRIBUTING](../../CONTRIBUTING.md) に従います。Wasm・JavaScript・型定義は `packages/sdk/dist/` に出力します。Rust から生成する TypeScript / Go のソースと、対応する Rust ビルド ID はソース管理します。バイナリと SDK は同じソース・固定依存から生成した組を配布してください。
|
|
26
|
+
|
|
27
|
+
まだレジストリへ公開していません。TypeScript は4パッケージの `bun pm pack` アーカイブを利用できます。
|
|
28
|
+
|
|
29
|
+
## TypeScript
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { createRuntime, presets } from '@traq-markdown-engine/sdk'
|
|
33
|
+
|
|
34
|
+
const runtime = await createRuntime(wasmBytes)
|
|
35
|
+
try {
|
|
36
|
+
const parser = runtime.createParser(presets.traq.v1)
|
|
37
|
+
const document = parser.parse('**hello** :stamp:')
|
|
38
|
+
const inline = parser.parseInline('**hello**')
|
|
39
|
+
} finally {
|
|
40
|
+
runtime.dispose()
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`wasmBytes` は `Uint8Array` です。Bun では `Bun.file(new URL(import.meta.resolve('@traq-markdown-engine/sdk/parser.wasm'))).bytes()` で読み、ブラウザーでは `new Uint8Array(await response.arrayBuffer())` を渡します。Runtime と Parser は再利用できます。同じ Runtime から異なるプリセットの Parser も作成できます。
|
|
45
|
+
|
|
46
|
+
ノード型は判別可能な union です。文法別の payload 型と任意利用の guard は `@traq-markdown-engine/commonmark-plugin/nodes`・`@traq-markdown-engine/commonmark-plugin/generic/nodes`・`@traq-markdown-engine/traq-plugin/nodes`、配布物全体の一覧は `@traq-markdown-engine/sdk/nodes` から利用できます。
|
|
47
|
+
|
|
48
|
+
## Go
|
|
49
|
+
|
|
50
|
+
```go
|
|
51
|
+
import markdown "github.com/uni-kakurenbo/traq-markdown-engine/packages/sdk/go"
|
|
52
|
+
|
|
53
|
+
runtime, err := markdown.NewRuntime(ctx, wasmBytes)
|
|
54
|
+
if err != nil { return err }
|
|
55
|
+
defer runtime.Close(ctx)
|
|
56
|
+
|
|
57
|
+
parser, err := runtime.NewParser(ctx, markdown.PresetTraQV1)
|
|
58
|
+
if err != nil { return err }
|
|
59
|
+
defer parser.Close(ctx)
|
|
60
|
+
document, err := parser.Parse(ctx, "**hello** :stamp:")
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`Parse` / `ParseInline` は `*markdown.Document` を返します。`Node.Data` の具体的な型も Rust から生成します。Runtime は Wasm のコンパイル結果を共有します。一つの Parser の呼び出しは直列化し、並列実行には同じ Runtime から Parser を複数作ります。`Parser.Close` はその Parser だけ、`Runtime.Close` は配下の全 Parser を解放します。
|
|
64
|
+
|
|
65
|
+
## 文法の変更
|
|
66
|
+
|
|
67
|
+
文法バージョンは、本文がどの構文規則で書かれたかを示す永続的な識別子です。
|
|
68
|
+
パッケージのバージョンとは独立しており、パッケージを更新しても既存の識別子の意味を変えません。
|
|
69
|
+
processing・renderer には独立した文法バージョンを設けず、選択された文法が生成した AST を処理します。
|
|
70
|
+
|
|
71
|
+
文法のレジストリは Rust の `bindings::grammars()` にあります。
|
|
72
|
+
`bindings::parser(version)` が名前から Grammar を選び、Parser を生成します。
|
|
73
|
+
Go / TypeScript には文法構成を複製せず、Wasm 境界では文法バージョンの文字列を渡します。
|
|
74
|
+
`presets.traq.v1` / `PresetTraQV1` はその文字列を表す生成済み定数です。
|
|
75
|
+
Rust の配布層がバージョンを解決し、共通のパーサー生成や処理機構は文法バージョンを知りません。
|
|
76
|
+
|
|
77
|
+
TypeScript の `runtime.createParser(version)`、
|
|
78
|
+
Go の `NewParser(ctx, Preset(version))` に
|
|
79
|
+
DB から読み出したバージョンを指定できます。未知のバージョンはエラーになり、最新文法への暗黙の置き換えはしません。
|
|
80
|
+
同じ Runtime から作成したパーサーを `Map<string, Parser>` に保持して使い分けられます。
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import type { Parser } from '@traq-markdown-engine/sdk'
|
|
84
|
+
|
|
85
|
+
const parsers = new Map<string, Parser>()
|
|
86
|
+
for (const message of messages) {
|
|
87
|
+
let parser = parsers.get(message.grammarVersion)
|
|
88
|
+
if (!parser) {
|
|
89
|
+
parser = runtime.createParser(message.grammarVersion)
|
|
90
|
+
parsers.set(message.grammarVersion, parser)
|
|
91
|
+
}
|
|
92
|
+
const document = parser.parse(message.text)
|
|
93
|
+
const result = view.render(document)
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
DB に保存するのは永続的な文法バージョンです。SDK と Wasm の対応を確認するビルド ID は
|
|
98
|
+
保存用バージョンではなく、パッケージ更新後も同じ文法バージョンで旧文法を選択できます。
|
|
99
|
+
|
|
100
|
+
新しい文法は Rust の文法定義と `crates/grammar/src/presets/exports.rs` の公開カタログに追加します。
|
|
101
|
+
選択レジストリと Go / TypeScript の定数はこのカタログを使うため、言語ごとの分岐や processing / renderer のバージョン追加は不要です。
|
|
102
|
+
既存文法の共有ルールを変更するときは、旧文法の解釈を維持してください。解釈を変えるルールだけを分離し、
|
|
103
|
+
旧実装を旧文法に残します。変更のないルールや AST の処理コードを文法ごとに複製する必要はありません。
|
|
104
|
+
既存の v1 AST fixture は互換性検証に使い、文法を更新する目的で期待値を上書きしません。
|
|
105
|
+
|
|
106
|
+
TypeScript の `presets.commonmark` / `presets.traq.v1`、Go の `PresetCommonMark` / `PresetTraQV1` は Rust が公開するプリセットから生成します。独自の文法は Rust で組み立て、配布層からプリセットとして公開して再ビルドします。ホスト API は文法からのパーサー生成、解析、解放を提供します。
|
|
107
|
+
|
|
108
|
+
Wasm のホスト実装は TypeScript の `index.ts` と Go の `parser.go` です。共通 AST 型と payload guard の検証部品は core、構文の生成型はそれぞれのパッケージが所有します。文法ビルダー、Plugin / Rule のミラー、文法ハンドル、worker pool は持ちません。
|
|
109
|
+
|
|
110
|
+
HTML 描画の共通基盤は core、構文別の描画は commonmark-plugin と traq-plugin が担当します。traQ の描画構成・condensed 表示・CSS はこのリポジトリの `typescript/renderer` が所有します。
|
|
111
|
+
|
|
112
|
+
[API と実装](docs/implementation.md)、[実行例](examples/README.md)、[開発と検証](../../CONTRIBUTING.md) を参照してください。
|
|
113
|
+
|
|
114
|
+
## AST からの描画と抽出
|
|
115
|
+
|
|
116
|
+
Parser が返す Document を renderer と extractor に直接渡します。文法を選択するのは Parser だけです。
|
|
117
|
+
TypeScript の HTML renderer はホスト上で AST を描画し、Extractor と Go の PlainTextRenderer は
|
|
118
|
+
渡された AST を Wasm の Rust 実装に渡します。Markdown 原文の再解析は行いません。
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
const parser = runtime.createParser(presets.traq.v1)
|
|
122
|
+
const extractor = runtime.createExtractor({ origin: 'https://q.example.test' })
|
|
123
|
+
const document = parser.parse('**hello** !!secret!!')
|
|
124
|
+
const { references, embedding, messageText } = extractor.extract(document)
|
|
125
|
+
const html = view.render(document)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
```go
|
|
129
|
+
parser, err := runtime.NewParser(ctx, markdown.PresetTraQV1)
|
|
130
|
+
if err != nil { return err }
|
|
131
|
+
extractor, err := runtime.NewExtractor(ctx, markdown.ExtractorOptions{Origin: origin})
|
|
132
|
+
if err != nil { return err }
|
|
133
|
+
renderer, err := runtime.NewPlainTextRenderer(ctx, markdown.RendererOptions{Origin: origin})
|
|
134
|
+
if err != nil { return err }
|
|
135
|
+
document, err := parser.Parse(ctx, "**hello** !!secret!!")
|
|
136
|
+
if err != nil { return err }
|
|
137
|
+
metadata, err := extractor.Extract(ctx, document)
|
|
138
|
+
if err != nil { return err }
|
|
139
|
+
notification, err := renderer.Render(ctx, document)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
各 instance は同じ Runtime のコンパイル結果を共有し、独立した設定を持ちます。
|
|
143
|
+
Go の呼び出し直列化・キャンセル規則は各 instance に適用され、Runtime の解放で全 instance を閉じます。
|
|
144
|
+
ネイティブ Rust は `traq_markdown_processing::extraction::Extractor` と
|
|
145
|
+
`rendering::PlainTextRenderer` が `&Document` を借用します。
|
|
146
|
+
|
|
147
|
+
PlainTextRenderer は spoiler をマスクし、空白を正規化した一行の通知テキストを返します。
|
|
148
|
+
Extractor は参照・添付 ID・引用 ID・埋め込み編集計画と、Markdown 記法を保つ `messageText` を返します。
|
|
149
|
+
参照は文書順・重複・spoiler 内を保持し、コード内の文字列は抽出しません。
|
|
150
|
+
`origin` が空なら traQ のファイル・メッセージ URL を通常の URL として扱います。
|
|
151
|
+
|
|
152
|
+
## TypeScript / HTML rendering
|
|
153
|
+
|
|
154
|
+
TypeScript の実装は各パッケージの責務に合わせて配置しています。
|
|
155
|
+
|
|
156
|
+
| TypeScript package | 責務 |
|
|
157
|
+
| ----------------------------------------- | ---------------------------------------------------------------------- |
|
|
158
|
+
| `@traq-markdown-engine/core` | 共通 AST 型、HTML handler・Plugin・PresetBuilder、契約検証と生成の基盤 |
|
|
159
|
+
| `@traq-markdown-engine/commonmark-plugin` | CommonMark・汎用拡張の生成ノード型と HTML 描画 |
|
|
160
|
+
| `@traq-markdown-engine/traq-plugin` | traP の生成ノード型・参照・スタンプ等の HTML 描画 |
|
|
161
|
+
| `@traq-markdown-engine/sdk` | Wasm / Go / TypeScript 配布、traQ の描画構成・condensed 表示・CSS |
|
|
162
|
+
|
|
163
|
+
開発手順は [ルートの README](../../README.md) を参照してください。ルートで `bun install`・`bun run build` を実行すると、4パッケージを依存順にビルドします。`bun run check:package` は4パッケージを pack し、独立した consumer で配布内容を検証します。
|
|
164
|
+
|
|
165
|
+
AST の共通形は core の `typescript/ast.ts` に一度だけ定義し、SDK の生成 bindings はそれを構文の union で特殊化します。構文の payload は Rust を正として生成し、commonmark-plugin と traq-plugin の `bun run generate:bindings` でそれぞれの契約 crate から再生成できます。
|
|
166
|
+
|
|
167
|
+
HTML API は `/renderer` サブパスです。traQ は `@traq-markdown-engine/sdk/renderer` の `messageRenderers`、CSS は `@traq-markdown-engine/sdk/index.css` を利用します。
|
|
168
|
+
|
|
169
|
+
### HTML の利用例
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
import { createRuntime, presets } from '@traq-markdown-engine/sdk'
|
|
173
|
+
import '@traq-markdown-engine/sdk/index.css'
|
|
174
|
+
import { messageRenderers } from '@traq-markdown-engine/sdk/renderer'
|
|
175
|
+
|
|
176
|
+
const runtime = await createRuntime(wasmBytes)
|
|
177
|
+
const parser = runtime.createParser(presets.traq.v1)
|
|
178
|
+
const view = messageRenderers({ origin: 'https://q.example.test' })
|
|
179
|
+
const document = parser.parse(source)
|
|
180
|
+
const { renderedText, embeddings } = view.standard.render(document)
|
|
181
|
+
const condensed = view.condensed.render(document)
|
|
182
|
+
runtime.dispose()
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Wasm の起動は利用側が明示的に行います。`/renderer` を import しても Wasm runtime は読み込みません。描画のカスタマイズは `@traq-markdown-engine/core/renderer` の `Plugin`・`PresetBuilder` と、各構文の `/renderer` を利用します。
|
|
186
|
+
|
|
187
|
+
## Corpus comparison
|
|
188
|
+
|
|
189
|
+
Use `bun run corpus:collect`, `bun run corpus:compare`, and `bun run corpus:report` to collect messages and generate offline HTML/MHTML difference reports. See the [corpus comparison tool](../../tools/corpus/README.md) for inputs, options, and output files.
|
|
190
|
+
|
|
191
|
+
Go consumers use `github.com/uni-kakurenbo/traq-markdown-engine/packages/sdk/go` for presets and artifact pairing. Shared AST/transport live in the core Go module; payload factories live in commonmark-plugin and traq-plugin. `Extractor.Extract` returns source-preserving message text, references, embedding edits, attachment IDs and citation IDs from the supplied Document. `PlainTextRenderer.Render` independently renders that Document for notifications.
|
|
192
|
+
|
|
193
|
+
Embedding edits are also shared: Rust derives `output.embedding` from the same AST. Pass that plan and an application identity resolver to `embedReferences` (TypeScript) or `EmbedReferences` (Go). `output.embedding.unembeddedText` restores reference labels for copying, and `mentionsUser` checks the extracted references. See [processing presets](crates/processing/README.md) for the editing rules.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Algorithm sources
|
|
2
|
+
|
|
3
|
+
The delimiter pairing in the core package’s `crates/parser/src/engine/inline/delimiters.rs` and emphasis handling
|
|
4
|
+
in the commonmark-plugin package’s `crates/syntax/src/inlines/emphasis.rs` are adapted from
|
|
5
|
+
markdown-it 14.3.0 (`lib/rules_inline/balance_pairs.mjs`, `emphasis.mjs`).
|
|
6
|
+
The spoiler scanner follows @traptitech/markdown-it-spoiler 1.1.6.
|
|
7
|
+
The inline math scanner follows @traptitech/markdown-it-katex 3.6.0.
|
|
8
|
+
Block parsing, reference handling, and HTML recognition follow markdown-it 14.3.0.
|
|
9
|
+
V1 stamp recognition follows @traptitech/traq-markdown-it.
|
|
10
|
+
URL recognition/normalization and the frozen TLD set follow linkify-it 5 and markdown-it 14.3.0.
|
|
11
|
+
|
|
12
|
+
Copyright (c) 2014 Vitaly Puzrin, Alex Kocharin.
|
|
13
|
+
Copyright (c) 2014-2015 Vitaly Puzrin, Alex Kocharin.
|
|
14
|
+
Copyright (c) 2016 Waylon Flinn.
|
|
15
|
+
Copyright (c) 2018 Takahiro Ethan Ikeuchi @iktakahiro.
|
|
16
|
+
Copyright (c) 2020 traP.
|
|
17
|
+
Copyright (c) 2020 magiclen.org (Ron Li). Entity names from html-escape 0.2.15.
|
|
18
|
+
|
|
19
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
20
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
21
|
+
in the Software without restriction, including without limitation the rights
|
|
22
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
23
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
24
|
+
furnished to do so, subject to the following conditions:
|
|
25
|
+
|
|
26
|
+
The above copyright notice and this permission notice shall be included in all
|
|
27
|
+
copies or substantial portions of the Software.
|
|
28
|
+
|
|
29
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
30
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
31
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
32
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
33
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
34
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
35
|
+
SOFTWARE.
|
|
36
|
+
|
|
37
|
+
## Entity values
|
|
38
|
+
|
|
39
|
+
`src/syntax/commonmark/inlines/entities_table.rs` freezes the 2,125 semicolon-terminated names with values decoded
|
|
40
|
+
by the frontend's `entities` 7.0.1. This also preserves multi-codepoint entities.
|
|
41
|
+
|
|
42
|
+
Copyright (c) Felix Böhm
|
|
43
|
+
All rights reserved.
|
|
44
|
+
|
|
45
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
46
|
+
|
|
47
|
+
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
48
|
+
|
|
49
|
+
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
50
|
+
|
|
51
|
+
THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"buildId": "015d42a01b73e510",
|
|
3
|
+
"limits": {
|
|
4
|
+
"inputBytes": 1048576,
|
|
5
|
+
"memoryBytes": 33554432,
|
|
6
|
+
"outputBytes": 1048576
|
|
7
|
+
},
|
|
8
|
+
"presets": {
|
|
9
|
+
"commonmark": 0,
|
|
10
|
+
"traq": {
|
|
11
|
+
"v1": 1
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"sha256": "3823d4eab050ae3c410c95ce268b6170c75e64918ecd546e04b32c6bca4699b7",
|
|
15
|
+
"bytes": 1530839,
|
|
16
|
+
"gzipBytes": 518515,
|
|
17
|
+
"brotliBytes": 347616
|
|
18
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { EmbeddingPlan, LookupKind, References } from './generated/processing.js';
|
|
2
|
+
/** Resolves Rust's ordered AST-derived candidates and preserves all other source bytes. */
|
|
3
|
+
export declare function embedReferences(source: string, plan: EmbeddingPlan, resolve: (kind: LookupKind, name: string) => string | undefined): string;
|
|
4
|
+
/** Uses parsed references, including those inside spoilers but excluding code/math. */
|
|
5
|
+
export declare function mentionsUser(references: References, userId: string, groupIds: readonly string[]): boolean;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Resolves Rust's ordered AST-derived candidates and preserves all other source bytes. */
|
|
2
|
+
export function embedReferences(source, plan, resolve) {
|
|
3
|
+
const bytes = new TextEncoder().encode(source);
|
|
4
|
+
const decoder = new TextDecoder('utf-8', { fatal: true });
|
|
5
|
+
let position = 0;
|
|
6
|
+
let result = '';
|
|
7
|
+
for (const candidate of plan.candidates) {
|
|
8
|
+
const { start, end, raw, kind, name } = candidate;
|
|
9
|
+
if (start < position) {
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
if (!Number.isSafeInteger(start) ||
|
|
13
|
+
!Number.isSafeInteger(end) ||
|
|
14
|
+
start < 0 ||
|
|
15
|
+
end <= start ||
|
|
16
|
+
end > bytes.length ||
|
|
17
|
+
decoder.decode(bytes.subarray(start, end)) !== raw) {
|
|
18
|
+
throw new Error('Embedding plan does not match source');
|
|
19
|
+
}
|
|
20
|
+
const id = resolve(kind, name);
|
|
21
|
+
if (!id) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
result += decoder.decode(bytes.subarray(position, start));
|
|
25
|
+
result += '!' + JSON.stringify({ type: kind, raw, id });
|
|
26
|
+
position = end;
|
|
27
|
+
}
|
|
28
|
+
return result + decoder.decode(bytes.subarray(position));
|
|
29
|
+
}
|
|
30
|
+
/** Uses parsed references, including those inside spoilers but excluding code/math. */
|
|
31
|
+
export function mentionsUser(references, userId, groupIds) {
|
|
32
|
+
return (references.mentions.includes(userId) ||
|
|
33
|
+
references.groupMentions.some(id => groupIds.includes(id)));
|
|
34
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as generic from '@traq-markdown-engine/commonmark-plugin/generic/nodes';
|
|
2
|
+
import * as commonmark from '@traq-markdown-engine/commonmark-plugin/nodes';
|
|
3
|
+
import * as trap from '@traq-markdown-engine/traq-plugin/nodes';
|
|
4
|
+
import type { Document as AstDocument, Node as AstNode } from '@traq-markdown-engine/core';
|
|
5
|
+
export type NodeKind = commonmark.NodeKind | generic.NodeKind | trap.NodeKind;
|
|
6
|
+
export type Node<AllowUnknown extends boolean = false> = AstNode<NodeKind | (AllowUnknown extends true ? {
|
|
7
|
+
kind: string;
|
|
8
|
+
data: unknown;
|
|
9
|
+
} : never)>;
|
|
10
|
+
export type Document<AllowUnknown extends boolean = false> = AstDocument<NodeKind | (AllowUnknown extends true ? {
|
|
11
|
+
kind: string;
|
|
12
|
+
data: unknown;
|
|
13
|
+
} : never)>;
|
|
14
|
+
export declare const names: Readonly<{
|
|
15
|
+
Mark: 'markdown_generic_contracts::mark::MarkData';
|
|
16
|
+
BlockMath: 'markdown_generic_contracts::math::BlockMathData';
|
|
17
|
+
InlineMath: 'markdown_generic_contracts::math::InlineMathData';
|
|
18
|
+
Strikethrough: 'markdown_generic_contracts::strikethrough::StrikethroughData';
|
|
19
|
+
Cell: 'markdown_generic_contracts::table::CellData';
|
|
20
|
+
Row: 'markdown_generic_contracts::table::RowData';
|
|
21
|
+
Table: 'markdown_generic_contracts::table::TableData';
|
|
22
|
+
Blockquote: 'markdown_commonmark_contracts::nodes::Blockquote';
|
|
23
|
+
CodeBlock: 'markdown_commonmark_contracts::nodes::CodeBlock';
|
|
24
|
+
Emphasis: 'markdown_commonmark_contracts::nodes::Emphasis';
|
|
25
|
+
Hardbreak: 'markdown_commonmark_contracts::nodes::Hardbreak';
|
|
26
|
+
Heading: 'markdown_commonmark_contracts::nodes::Heading';
|
|
27
|
+
HtmlBlock: 'markdown_commonmark_contracts::nodes::HtmlBlock';
|
|
28
|
+
HtmlInline: 'markdown_commonmark_contracts::nodes::HtmlInline';
|
|
29
|
+
Image: 'markdown_commonmark_contracts::nodes::Image';
|
|
30
|
+
InlineCode: 'markdown_commonmark_contracts::nodes::InlineCode';
|
|
31
|
+
Link: 'markdown_commonmark_contracts::nodes::Link';
|
|
32
|
+
List: 'markdown_commonmark_contracts::nodes::List';
|
|
33
|
+
ListItem: 'markdown_commonmark_contracts::nodes::ListItem';
|
|
34
|
+
Paragraph: 'markdown_commonmark_contracts::nodes::Paragraph';
|
|
35
|
+
Softbreak: 'markdown_commonmark_contracts::nodes::Softbreak';
|
|
36
|
+
Strong: 'markdown_commonmark_contracts::nodes::Strong';
|
|
37
|
+
Text: 'markdown_commonmark_contracts::nodes::Text';
|
|
38
|
+
ThematicBreak: 'markdown_commonmark_contracts::nodes::ThematicBreak';
|
|
39
|
+
BlankLine: 'markdown_trap_contracts::compat::BlankLineData';
|
|
40
|
+
Embedding: 'markdown_trap_contracts::embedding::EmbeddingData';
|
|
41
|
+
Reference: 'markdown_trap_contracts::reference::ReferenceData';
|
|
42
|
+
Spoiler: 'markdown_trap_contracts::spoiler::SpoilerData';
|
|
43
|
+
Stamp: 'markdown_trap_contracts::stamp::StampData';
|
|
44
|
+
}>;
|
|
45
|
+
export declare const nodes: ReadonlyMap<string, (data: unknown) => boolean>;
|
|
46
|
+
export declare function isKnownNode(node: Node<true>): node is Node<true> & NodeKind;
|
|
47
|
+
export type ParseError = {
|
|
48
|
+
code: 'invalid_utf8';
|
|
49
|
+
} | {
|
|
50
|
+
code: 'resource_limit';
|
|
51
|
+
resource: string;
|
|
52
|
+
} | {
|
|
53
|
+
code: 'internal_error';
|
|
54
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Generated from Rust contracts. Do not edit.
|
|
2
|
+
import * as generic from '@traq-markdown-engine/commonmark-plugin/generic/nodes';
|
|
3
|
+
import * as commonmark from '@traq-markdown-engine/commonmark-plugin/nodes';
|
|
4
|
+
import * as trap from '@traq-markdown-engine/traq-plugin/nodes';
|
|
5
|
+
export const names = Object.freeze({
|
|
6
|
+
...commonmark.names,
|
|
7
|
+
...generic.names,
|
|
8
|
+
...trap.names
|
|
9
|
+
});
|
|
10
|
+
export const nodes = new Map([
|
|
11
|
+
...commonmark.nodes,
|
|
12
|
+
...generic.nodes,
|
|
13
|
+
...trap.nodes
|
|
14
|
+
]);
|
|
15
|
+
export function isKnownNode(node) {
|
|
16
|
+
return nodes.get(node.kind)?.(node.data) ?? false;
|
|
17
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export type Extraction = {
|
|
2
|
+
messageText: string;
|
|
3
|
+
attachments: Array<string>;
|
|
4
|
+
citations: Array<string>;
|
|
5
|
+
references: References;
|
|
6
|
+
embedding: EmbeddingPlan;
|
|
7
|
+
};
|
|
8
|
+
export type EmbeddingPlan = {
|
|
9
|
+
/**
|
|
10
|
+
* Ordered lookup attempts. A successful attempt consumes its source range.
|
|
11
|
+
*/
|
|
12
|
+
candidates: Array<EmbeddingCandidate>;
|
|
13
|
+
/**
|
|
14
|
+
* Original Markdown with recognized reference nodes restored to their labels.
|
|
15
|
+
*/
|
|
16
|
+
unembeddedText: string;
|
|
17
|
+
};
|
|
18
|
+
export type EmbeddingCandidate = {
|
|
19
|
+
/**
|
|
20
|
+
* UTF-8 byte offsets into the original source, not rendered text.
|
|
21
|
+
*/
|
|
22
|
+
start: number;
|
|
23
|
+
end: number;
|
|
24
|
+
raw: string;
|
|
25
|
+
name: string;
|
|
26
|
+
kind: LookupKind;
|
|
27
|
+
};
|
|
28
|
+
export type LookupKind = 'user' | 'group' | 'channel';
|
|
29
|
+
export type References = {
|
|
30
|
+
mentions: Array<string>;
|
|
31
|
+
groupMentions: Array<string>;
|
|
32
|
+
channelLinks: Array<string>;
|
|
33
|
+
embeddings: Array<EmbeddedInfo>;
|
|
34
|
+
};
|
|
35
|
+
export type EmbeddedInfo = {
|
|
36
|
+
raw: string;
|
|
37
|
+
type: string;
|
|
38
|
+
id: string;
|
|
39
|
+
};
|
|
40
|
+
export type ExtractorOptions = {
|
|
41
|
+
/**
|
|
42
|
+
* Origin used to recognize traQ file/message URLs; empty leaves URLs as text.
|
|
43
|
+
*/
|
|
44
|
+
origin: string;
|
|
45
|
+
};
|
|
46
|
+
export type RendererOptions = {
|
|
47
|
+
origin: string;
|
|
48
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|