@dinoxx/dinox-cli 2.19.0 → 2.20.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 +15 -0
- package/README.md +17 -17
- package/dist/chunks/applePodcast-V4FSJOC5.js +169 -0
- package/dist/chunks/bbc-NTMRPYRF.js +570 -0
- package/dist/chunks/bilibili-UA3MBSPH.js +835 -0
- package/dist/chunks/bohaishibei-B7UVXH4Y.js +246 -0
- package/dist/chunks/chunk-224ML7QC.js +21 -0
- package/dist/chunks/chunk-2LW76QIL.js +32 -0
- package/dist/chunks/chunk-2M7RJATW.js +60 -0
- package/dist/chunks/chunk-3EKNTO6G.js +61 -0
- package/dist/chunks/chunk-3VZNZWDG.js +437 -0
- package/dist/chunks/chunk-5JF7J5MP.js +114 -0
- package/dist/chunks/chunk-5KU25TMX.js +26 -0
- package/dist/chunks/chunk-67RXND3H.js +65 -0
- package/dist/chunks/chunk-6AZT4ARG.js +1491 -0
- package/dist/chunks/chunk-6D3QLMRM.js +421 -0
- package/dist/chunks/chunk-6VMHHE5Y.js +235 -0
- package/dist/chunks/chunk-77UP745T.js +143 -0
- package/dist/chunks/chunk-7A5QISPG.js +19 -0
- package/dist/chunks/chunk-7ODU7LXP.js +31 -0
- package/dist/chunks/chunk-A6WF7CZL.js +904 -0
- package/dist/chunks/chunk-ABYPGMDC.js +100 -0
- package/dist/chunks/chunk-AHRCI2RW.js +141 -0
- package/dist/chunks/chunk-BDLS5EEP.js +49 -0
- package/dist/chunks/chunk-BKCNERPB.js +246 -0
- package/dist/chunks/chunk-BZQYECIH.js +54 -0
- package/dist/chunks/chunk-D5SBKLDX.js +71 -0
- package/dist/chunks/chunk-DR6BGSZM.js +865 -0
- package/dist/chunks/chunk-F7BDWXBG.js +57 -0
- package/dist/chunks/chunk-FGQRYB7F.js +34 -0
- package/dist/chunks/chunk-FIQYJ6KZ.js +19 -0
- package/dist/chunks/chunk-FKLZZGEX.js +116 -0
- package/dist/chunks/chunk-FZGEWY5L.js +37 -0
- package/dist/chunks/chunk-GTDX2LIJ.js +265 -0
- package/dist/chunks/chunk-HIJXC3RT.js +194 -0
- package/dist/chunks/chunk-HQJUJYUM.js +36 -0
- package/dist/chunks/chunk-IAEJG5NI.js +50 -0
- package/dist/chunks/chunk-KCHHY6QB.js +65 -0
- package/dist/chunks/chunk-KL75BFYJ.js +71 -0
- package/dist/chunks/chunk-KOAKG2QU.js +45 -0
- package/dist/chunks/chunk-MCFXD2LS.js +66 -0
- package/dist/chunks/chunk-MLOITAK6.js +29 -0
- package/dist/chunks/chunk-N44NRKDJ.js +101 -0
- package/dist/chunks/chunk-N6ALWINB.js +14115 -0
- package/dist/chunks/chunk-NGIIELO4.js +61 -0
- package/dist/chunks/chunk-OG6MBAGC.js +95 -0
- package/dist/chunks/chunk-P4LG4DIO.js +108 -0
- package/dist/chunks/chunk-PJDD4R46.js +77 -0
- package/dist/chunks/chunk-PK5AOVLU.js +107 -0
- package/dist/chunks/chunk-PTFGE4KS.js +66 -0
- package/dist/chunks/chunk-Q6G7VO5G.js +67 -0
- package/dist/chunks/chunk-QFUD3I7W.js +185 -0
- package/dist/chunks/chunk-QNIYFLJT.js +39 -0
- package/dist/chunks/chunk-QZQRG3JY.js +86 -0
- package/dist/chunks/chunk-RKJYKUQD.js +91 -0
- package/dist/chunks/chunk-TAENC45D.js +160 -0
- package/dist/chunks/chunk-TILRKKRN.js +20481 -0
- package/dist/chunks/chunk-TIXOORAP.js +60 -0
- package/dist/chunks/chunk-ULKGDBAJ.js +80 -0
- package/dist/chunks/chunk-URYABAYN.js +72 -0
- package/dist/chunks/chunk-VNB4ZFLN.js +86 -0
- package/dist/chunks/chunk-W7R5JTSA.js +42 -0
- package/dist/chunks/chunk-WC3GSQBC.js +25699 -0
- package/dist/chunks/chunk-WMJXAF3X.js +55 -0
- package/dist/chunks/chunk-X36EIV25.js +93 -0
- package/dist/chunks/chunk-X7IZXCSL.js +60 -0
- package/dist/chunks/chunk-XEPDFQYD.js +215 -0
- package/dist/chunks/chunk-XFVLNCOW.js +171 -0
- package/dist/chunks/chunk-XMMTGPZ6.js +1332 -0
- package/dist/chunks/chunk-XQZUX7OT.js +39 -0
- package/dist/chunks/chunk-XZLFMJOG.js +72 -0
- package/dist/chunks/chunk-ZGF3OEWR.js +84 -0
- package/dist/chunks/chunk-ZHKS4R4P.js +1215 -0
- package/dist/chunks/cookies-6QQHSM26.js +34 -0
- package/dist/chunks/dedaoNote-KJ32ZQLS.js +418 -0
- package/dist/chunks/doubanGroup-HR4K2KMY.js +429 -0
- package/dist/chunks/doubao-MXUHPLUB.js +462 -0
- package/dist/chunks/douyin-UU2FSQPS.js +566 -0
- package/dist/chunks/ensure-MLNCD2SD.js +18 -0
- package/dist/chunks/execute-57M65KKK.js +17 -0
- package/dist/chunks/facebook-SZFOVE7R.js +878 -0
- package/dist/chunks/feishu-ISWRJ7HI.js +877 -0
- package/dist/chunks/ima-D7CX5WR4.js +202 -0
- package/dist/chunks/instagram-HNDPO37H.js +939 -0
- package/dist/chunks/install-IIMVFNAT.js +303 -0
- package/dist/chunks/jike-H7L4LJTN.js +445 -0
- package/dist/chunks/mcp-PZBHAYXQ.js +297 -0
- package/dist/chunks/mcpServer-T4DNYR7R.js +436 -0
- package/dist/chunks/metaso-ZVZW5UBB.js +194 -0
- package/dist/chunks/run-GCMWLTIV.js +1464 -0
- package/dist/chunks/runCli-SBQE2VQJ.js +464 -0
- package/dist/chunks/setup-EEU6GSWX.js +378 -0
- package/dist/chunks/threads-ADW6IANQ.js +657 -0
- package/dist/chunks/twitter-NAGCB3NI.js +1148 -0
- package/dist/chunks/web-QFKZCM4F.js +31 -0
- package/dist/chunks/wechat-OXNNLT4J.js +1551 -0
- package/dist/chunks/weibo-PMVGDNQU.js +641 -0
- package/dist/chunks/workbuddy-NNAXIIIZ.js +426 -0
- package/dist/chunks/xiaoheihe-WFQJRBAD.js +316 -0
- package/dist/chunks/xiaohongshu-5CXBELGW.js +1833 -0
- package/dist/chunks/xiaoyuzhou-6L6IB46Y.js +322 -0
- package/dist/chunks/youtube-52NGBTQC.js +58 -0
- package/dist/chunks/zcool-HDSWK4KD.js +755 -0
- package/dist/chunks/zhihu-EX2VRJYY.js +1024 -0
- package/dist/dinox.js +137 -51
- package/dist/dsh-plugin/lib/client.js +265 -252
- package/dist/dsh-plugin/package.json +1 -1
- package/dist/dsh-plugin/runtime.json +3 -3
- package/dist/editor-ui/mcp-app.html +293 -280
- package/package.json +81 -63
- package/dist/ai/ragxClient.d.ts +0 -15
- package/dist/ai/ragxClient.js +0 -71
- package/dist/auth/devicePair.d.ts +0 -62
- package/dist/auth/devicePair.js +0 -377
- package/dist/auth/userInfo.d.ts +0 -26
- package/dist/auth/userInfo.js +0 -224
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -130
- package/dist/cliTypes.d.ts +0 -7
- package/dist/cliTypes.js +0 -1
- package/dist/commands/auth/index.d.ts +0 -34
- package/dist/commands/auth/index.js +0 -605
- package/dist/commands/batch.d.ts +0 -35
- package/dist/commands/batch.js +0 -202
- package/dist/commands/boxes/index.d.ts +0 -4
- package/dist/commands/boxes/index.js +0 -382
- package/dist/commands/boxes/model.d.ts +0 -37
- package/dist/commands/boxes/model.js +0 -93
- package/dist/commands/boxes/operations.d.ts +0 -86
- package/dist/commands/boxes/operations.js +0 -448
- package/dist/commands/boxes/repo.d.ts +0 -36
- package/dist/commands/boxes/repo.js +0 -320
- package/dist/commands/boxes/store.d.ts +0 -22
- package/dist/commands/boxes/store.js +0 -143
- package/dist/commands/config/index.d.ts +0 -5
- package/dist/commands/config/index.js +0 -105
- package/dist/commands/descriptor/register.d.ts +0 -8
- package/dist/commands/descriptor/register.js +0 -122
- package/dist/commands/descriptor/types.d.ts +0 -37
- package/dist/commands/descriptor/types.js +0 -17
- package/dist/commands/doctor.d.ts +0 -126
- package/dist/commands/doctor.js +0 -558
- package/dist/commands/domain/options.d.ts +0 -10
- package/dist/commands/domain/options.js +0 -75
- package/dist/commands/domain/run.d.ts +0 -24
- package/dist/commands/domain/run.js +0 -137
- package/dist/commands/editor/index.d.ts +0 -4
- package/dist/commands/editor/index.js +0 -155
- package/dist/commands/gateway/index.d.ts +0 -4
- package/dist/commands/gateway/index.js +0 -340
- package/dist/commands/graph/index.d.ts +0 -4
- package/dist/commands/graph/index.js +0 -173
- package/dist/commands/graph/repo.d.ts +0 -40
- package/dist/commands/graph/repo.js +0 -201
- package/dist/commands/info/index.d.ts +0 -4
- package/dist/commands/info/index.js +0 -75
- package/dist/commands/mcp.d.ts +0 -6
- package/dist/commands/mcp.js +0 -47
- package/dist/commands/meta/index.d.ts +0 -4
- package/dist/commands/meta/index.js +0 -60
- package/dist/commands/meta/repo.d.ts +0 -30
- package/dist/commands/meta/repo.js +0 -76
- package/dist/commands/notes/actions.d.ts +0 -12
- package/dist/commands/notes/actions.js +0 -591
- package/dist/commands/notes/bulk.d.ts +0 -35
- package/dist/commands/notes/bulk.js +0 -195
- package/dist/commands/notes/contentEngine.d.ts +0 -95
- package/dist/commands/notes/contentEngine.js +0 -714
- package/dist/commands/notes/contentPatch.d.ts +0 -114
- package/dist/commands/notes/contentPatch.js +0 -450
- package/dist/commands/notes/contentPatchCommand.d.ts +0 -6
- package/dist/commands/notes/contentPatchCommand.js +0 -164
- package/dist/commands/notes/createFromTemplate.d.ts +0 -35
- package/dist/commands/notes/createFromTemplate.js +0 -58
- package/dist/commands/notes/descriptors.d.ts +0 -4
- package/dist/commands/notes/descriptors.js +0 -548
- package/dist/commands/notes/detailContent.d.ts +0 -19
- package/dist/commands/notes/detailContent.js +0 -62
- package/dist/commands/notes/dryRun.d.ts +0 -33
- package/dist/commands/notes/dryRun.js +0 -133
- package/dist/commands/notes/export.d.ts +0 -27
- package/dist/commands/notes/export.js +0 -252
- package/dist/commands/notes/index.d.ts +0 -2
- package/dist/commands/notes/index.js +0 -2
- package/dist/commands/notes/metadataMutation.d.ts +0 -29
- package/dist/commands/notes/metadataMutation.js +0 -138
- package/dist/commands/notes/repo/read.d.ts +0 -8
- package/dist/commands/notes/repo/read.js +0 -302
- package/dist/commands/notes/repo/resolve.d.ts +0 -8
- package/dist/commands/notes/repo/resolve.js +0 -187
- package/dist/commands/notes/repo/search.d.ts +0 -43
- package/dist/commands/notes/repo/search.js +0 -513
- package/dist/commands/notes/repo/semantic.d.ts +0 -14
- package/dist/commands/notes/repo/semantic.js +0 -31
- package/dist/commands/notes/repo/shared.d.ts +0 -192
- package/dist/commands/notes/repo/shared.js +0 -102
- package/dist/commands/notes/repo/write.d.ts +0 -27
- package/dist/commands/notes/repo/write.js +0 -262
- package/dist/commands/notes/repo.d.ts +0 -7
- package/dist/commands/notes/repo.js +0 -7
- package/dist/commands/notes/runtime.d.ts +0 -20
- package/dist/commands/notes/runtime.js +0 -175
- package/dist/commands/notes/searchOutput.d.ts +0 -15
- package/dist/commands/notes/searchOutput.js +0 -54
- package/dist/commands/notes/searchResponse.d.ts +0 -54
- package/dist/commands/notes/searchResponse.js +0 -57
- package/dist/commands/notes/searchSql.d.ts +0 -11
- package/dist/commands/notes/searchSql.js +0 -614
- package/dist/commands/notes/searchTime.d.ts +0 -9
- package/dist/commands/notes/searchTime.js +0 -85
- package/dist/commands/notes/semantic.d.ts +0 -116
- package/dist/commands/notes/semantic.js +0 -332
- package/dist/commands/notes/writeReceipt.d.ts +0 -20
- package/dist/commands/notes/writeReceipt.js +0 -82
- package/dist/commands/prompt/index.d.ts +0 -5
- package/dist/commands/prompt/index.js +0 -132
- package/dist/commands/prompt/repo.d.ts +0 -28
- package/dist/commands/prompt/repo.js +0 -220
- package/dist/commands/properties/index.d.ts +0 -16
- package/dist/commands/properties/index.js +0 -640
- package/dist/commands/properties/repo.d.ts +0 -150
- package/dist/commands/properties/repo.js +0 -272
- package/dist/commands/runtime.d.ts +0 -54
- package/dist/commands/runtime.js +0 -228
- package/dist/commands/savedViews/fields.d.ts +0 -28
- package/dist/commands/savedViews/fields.js +0 -87
- package/dist/commands/savedViews/index.d.ts +0 -7
- package/dist/commands/savedViews/index.js +0 -506
- package/dist/commands/savedViews/model.d.ts +0 -45
- package/dist/commands/savedViews/model.js +0 -90
- package/dist/commands/savedViews/repo.d.ts +0 -125
- package/dist/commands/savedViews/repo.js +0 -393
- package/dist/commands/schema/commandMetadata.d.ts +0 -2
- package/dist/commands/schema/commandMetadata.js +0 -18
- package/dist/commands/schema/globalOptions.d.ts +0 -11
- package/dist/commands/schema/globalOptions.js +0 -11
- package/dist/commands/schema/index.d.ts +0 -5
- package/dist/commands/schema/index.js +0 -130
- package/dist/commands/schema/renderSkills.d.ts +0 -12
- package/dist/commands/schema/renderSkills.js +0 -366
- package/dist/commands/schema/spec.d.ts +0 -5
- package/dist/commands/schema/spec.js +0 -74
- package/dist/commands/schema/types.d.ts +0 -34
- package/dist/commands/schema/types.js +0 -1
- package/dist/commands/skills/index.d.ts +0 -80
- package/dist/commands/skills/index.js +0 -572
- package/dist/commands/storage/index.d.ts +0 -4
- package/dist/commands/storage/index.js +0 -270
- package/dist/commands/storage/repo/configs.d.ts +0 -30
- package/dist/commands/storage/repo/configs.js +0 -259
- package/dist/commands/storage/repo/operations.d.ts +0 -25
- package/dist/commands/storage/repo/operations.js +0 -339
- package/dist/commands/storage/repo/remote.d.ts +0 -32
- package/dist/commands/storage/repo/remote.js +0 -132
- package/dist/commands/storage/repo/resources.d.ts +0 -12
- package/dist/commands/storage/repo/resources.js +0 -134
- package/dist/commands/storage/repo/shared.d.ts +0 -181
- package/dist/commands/storage/repo/shared.js +0 -36
- package/dist/commands/storage/repo/targets.d.ts +0 -12
- package/dist/commands/storage/repo/targets.js +0 -178
- package/dist/commands/storage/repo.d.ts +0 -3
- package/dist/commands/storage/repo.js +0 -4
- package/dist/commands/sync.d.ts +0 -27
- package/dist/commands/sync.js +0 -153
- package/dist/commands/tags/content.d.ts +0 -32
- package/dist/commands/tags/content.js +0 -252
- package/dist/commands/tags/index.d.ts +0 -4
- package/dist/commands/tags/index.js +0 -404
- package/dist/commands/tags/model.d.ts +0 -38
- package/dist/commands/tags/model.js +0 -100
- package/dist/commands/tags/operations.d.ts +0 -105
- package/dist/commands/tags/operations.js +0 -468
- package/dist/commands/tags/repo.d.ts +0 -27
- package/dist/commands/tags/repo.js +0 -236
- package/dist/commands/tags/store.d.ts +0 -28
- package/dist/commands/tags/store.js +0 -166
- package/dist/commands/templates/index.d.ts +0 -4
- package/dist/commands/templates/index.js +0 -290
- package/dist/commands/templates/model.d.ts +0 -28
- package/dist/commands/templates/model.js +0 -195
- package/dist/commands/templates/repo.d.ts +0 -53
- package/dist/commands/templates/repo.js +0 -78
- package/dist/commands/todo/contentModel.d.ts +0 -33
- package/dist/commands/todo/contentModel.js +0 -377
- package/dist/commands/todo/dryRun.d.ts +0 -26
- package/dist/commands/todo/dryRun.js +0 -150
- package/dist/commands/todo/index.d.ts +0 -10
- package/dist/commands/todo/index.js +0 -631
- package/dist/commands/todo/repo.d.ts +0 -257
- package/dist/commands/todo/repo.js +0 -772
- package/dist/commands/todo/taskIdentity.d.ts +0 -2
- package/dist/commands/todo/taskIdentity.js +0 -64
- package/dist/commands/todo/taskModel.d.ts +0 -56
- package/dist/commands/todo/taskModel.js +0 -492
- package/dist/commands/todo/taskPatch.d.ts +0 -119
- package/dist/commands/todo/taskPatch.js +0 -502
- package/dist/commands/todo/taskText.d.ts +0 -26
- package/dist/commands/todo/taskText.js +0 -221
- package/dist/commands/update.d.ts +0 -46
- package/dist/commands/update.js +0 -326
- package/dist/commands/writeConfirmation.d.ts +0 -13
- package/dist/commands/writeConfirmation.js +0 -54
- package/dist/commands/writeDryRun.d.ts +0 -88
- package/dist/commands/writeDryRun.js +0 -162
- package/dist/commands/writeDurability.d.ts +0 -5
- package/dist/commands/writeDurability.js +0 -22
- package/dist/commands/writeReceipt.d.ts +0 -13
- package/dist/commands/writeReceipt.js +0 -12
- package/dist/config/keys.d.ts +0 -9
- package/dist/config/keys.js +0 -14
- package/dist/config/paths.d.ts +0 -6
- package/dist/config/paths.js +0 -55
- package/dist/config/resolve.d.ts +0 -4
- package/dist/config/resolve.js +0 -68
- package/dist/config/serviceEndpoints.d.ts +0 -5
- package/dist/config/serviceEndpoints.js +0 -5
- package/dist/config/store.d.ts +0 -8
- package/dist/config/store.js +0 -149
- package/dist/config/types.d.ts +0 -55
- package/dist/config/types.js +0 -1
- package/dist/constants/links.d.ts +0 -18
- package/dist/constants/links.js +0 -26
- package/dist/contract/snapshot.d.ts +0 -30
- package/dist/contract/snapshot.js +0 -114
- package/dist/daemon/autoInstall.d.ts +0 -32
- package/dist/daemon/autoInstall.js +0 -106
- package/dist/daemon/client.d.ts +0 -29
- package/dist/daemon/client.js +0 -418
- package/dist/daemon/connectivity.d.ts +0 -20
- package/dist/daemon/connectivity.js +0 -42
- package/dist/daemon/ensure.d.ts +0 -1
- package/dist/daemon/ensure.js +0 -120
- package/dist/daemon/env.d.ts +0 -8
- package/dist/daemon/env.js +0 -81
- package/dist/daemon/forward.d.ts +0 -37
- package/dist/daemon/forward.js +0 -155
- package/dist/daemon/fresh.d.ts +0 -4
- package/dist/daemon/fresh.js +0 -10
- package/dist/daemon/index.d.ts +0 -80
- package/dist/daemon/index.js +0 -727
- package/dist/daemon/launch.d.ts +0 -43
- package/dist/daemon/launch.js +0 -124
- package/dist/daemon/lifecycle.d.ts +0 -51
- package/dist/daemon/lifecycle.js +0 -182
- package/dist/daemon/log.d.ts +0 -14
- package/dist/daemon/log.js +0 -57
- package/dist/daemon/pid.d.ts +0 -31
- package/dist/daemon/pid.js +0 -212
- package/dist/daemon/route.d.ts +0 -14
- package/dist/daemon/route.js +0 -43
- package/dist/daemon/server.d.ts +0 -67
- package/dist/daemon/server.js +0 -563
- package/dist/daemon/supervise.d.ts +0 -29
- package/dist/daemon/supervise.js +0 -100
- package/dist/daemon/supervisor.d.ts +0 -91
- package/dist/daemon/supervisor.js +0 -612
- package/dist/daemon/types.d.ts +0 -71
- package/dist/daemon/types.js +0 -2
- package/dist/dinox.d.ts +0 -2
- package/dist/editor/anchor.d.ts +0 -46
- package/dist/editor/anchor.js +0 -129
- package/dist/editor/blockIds.d.ts +0 -21
- package/dist/editor/blockIds.js +0 -51
- package/dist/editor/blocks.d.ts +0 -47
- package/dist/editor/blocks.js +0 -236
- package/dist/editor/compat.d.ts +0 -38
- package/dist/editor/compat.js +0 -410
- package/dist/editor/daemon.d.ts +0 -10
- package/dist/editor/daemon.js +0 -83
- package/dist/editor/document.d.ts +0 -74
- package/dist/editor/document.js +0 -88
- package/dist/editor/i18n.d.ts +0 -23
- package/dist/editor/i18n.js +0 -61
- package/dist/editor/install.d.ts +0 -90
- package/dist/editor/install.js +0 -335
- package/dist/editor/mcp.d.ts +0 -22
- package/dist/editor/mcp.js +0 -319
- package/dist/editor/meta.d.ts +0 -70
- package/dist/editor/meta.js +0 -163
- package/dist/editor/paths.d.ts +0 -2
- package/dist/editor/paths.js +0 -13
- package/dist/editor/persistence.d.ts +0 -4
- package/dist/editor/persistence.js +0 -35
- package/dist/editor/saveGuard.d.ts +0 -9
- package/dist/editor/saveGuard.js +0 -38
- package/dist/editor/schema.d.ts +0 -14
- package/dist/editor/schema.js +0 -38
- package/dist/editor/service.d.ts +0 -382
- package/dist/editor/service.js +0 -1174
- package/dist/editor/todos.d.ts +0 -67
- package/dist/editor/todos.js +0 -293
- package/dist/gateway/adapters/acp.d.ts +0 -75
- package/dist/gateway/adapters/acp.js +0 -431
- package/dist/gateway/adapters/codexImages.d.ts +0 -4
- package/dist/gateway/adapters/codexImages.js +0 -34
- package/dist/gateway/adapters/echo.d.ts +0 -12
- package/dist/gateway/adapters/echo.js +0 -54
- package/dist/gateway/adapters/index.d.ts +0 -13
- package/dist/gateway/adapters/index.js +0 -42
- package/dist/gateway/agentTaskHost.d.ts +0 -135
- package/dist/gateway/agentTaskHost.js +0 -410
- package/dist/gateway/assistantProjection.d.ts +0 -36
- package/dist/gateway/assistantProjection.js +0 -230
- package/dist/gateway/config.d.ts +0 -56
- package/dist/gateway/config.js +0 -312
- package/dist/gateway/conversationContext.d.ts +0 -44
- package/dist/gateway/conversationContext.js +0 -75
- package/dist/gateway/detect.d.ts +0 -63
- package/dist/gateway/detect.js +0 -281
- package/dist/gateway/deviceHost.d.ts +0 -100
- package/dist/gateway/deviceHost.js +0 -735
- package/dist/gateway/fileUpload.d.ts +0 -12
- package/dist/gateway/fileUpload.js +0 -154
- package/dist/gateway/keepAwake.d.ts +0 -24
- package/dist/gateway/keepAwake.js +0 -64
- package/dist/gateway/mcpCommandTools.d.ts +0 -62
- package/dist/gateway/mcpCommandTools.js +0 -220
- package/dist/gateway/mcpEnv.d.ts +0 -11
- package/dist/gateway/mcpEnv.js +0 -11
- package/dist/gateway/mcpGroups.d.ts +0 -3
- package/dist/gateway/mcpGroups.js +0 -4
- package/dist/gateway/mcpServer.d.ts +0 -25
- package/dist/gateway/mcpServer.js +0 -214
- package/dist/gateway/processTree.d.ts +0 -15
- package/dist/gateway/processTree.js +0 -60
- package/dist/gateway/protocol.d.ts +0 -145
- package/dist/gateway/protocol.js +0 -195
- package/dist/gateway/runExecutor.d.ts +0 -104
- package/dist/gateway/runExecutor.js +0 -480
- package/dist/gateway/service.d.ts +0 -35
- package/dist/gateway/service.js +0 -147
- package/dist/gateway/spawnAgent.d.ts +0 -12
- package/dist/gateway/spawnAgent.js +0 -32
- package/dist/gateway/streamPublisher.d.ts +0 -33
- package/dist/gateway/streamPublisher.js +0 -93
- package/dist/gateway/taskJournal.d.ts +0 -14
- package/dist/gateway/taskJournal.js +0 -47
- package/dist/gateway/threadStore.d.ts +0 -230
- package/dist/gateway/threadStore.js +0 -621
- package/dist/gateway/types.d.ts +0 -168
- package/dist/gateway/types.js +0 -12
- package/dist/gateway/workspace.d.ts +0 -5
- package/dist/gateway/workspace.js +0 -30
- package/dist/gateway/workspaceFolders.d.ts +0 -35
- package/dist/gateway/workspaceFolders.js +0 -142
- package/dist/gateway/workspaceListing.d.ts +0 -5
- package/dist/gateway/workspaceListing.js +0 -78
- package/dist/integrations/dsh/host.d.ts +0 -53
- package/dist/integrations/dsh/host.js +0 -245
- package/dist/integrations/dsh/mcpClient.d.ts +0 -66
- package/dist/integrations/dsh/mcpClient.js +0 -192
- package/dist/powersync/connector.d.ts +0 -22
- package/dist/powersync/connector.js +0 -91
- package/dist/powersync/exclusiveRuntime.d.ts +0 -21
- package/dist/powersync/exclusiveRuntime.js +0 -66
- package/dist/powersync/runtime.d.ts +0 -62
- package/dist/powersync/runtime.js +0 -358
- package/dist/powersync/schema/content.d.ts +0 -1
- package/dist/powersync/schema/content.js +0 -1
- package/dist/powersync/schema/electronCanonical.d.ts +0 -1561
- package/dist/powersync/schema/electronCanonical.js +0 -1154
- package/dist/powersync/schema/index.d.ts +0 -844
- package/dist/powersync/schema/index.js +0 -8
- package/dist/powersync/schema/local.d.ts +0 -13
- package/dist/powersync/schema/local.js +0 -24
- package/dist/powersync/schema/note.d.ts +0 -1
- package/dist/powersync/schema/note.js +0 -1
- package/dist/powersync/schema/notesExtras.d.ts +0 -1
- package/dist/powersync/schema/notesExtras.js +0 -1
- package/dist/powersync/schema/projects.d.ts +0 -1
- package/dist/powersync/schema/projects.js +0 -1
- package/dist/powersync/schema/savedViews.d.ts +0 -1
- package/dist/powersync/schema/savedViews.js +0 -1
- package/dist/powersync/schema/storage.d.ts +0 -1
- package/dist/powersync/schema/storage.js +0 -1
- package/dist/powersync/schema/tags.d.ts +0 -1
- package/dist/powersync/schema/tags.js +0 -1
- package/dist/powersync/syncGate.d.ts +0 -45
- package/dist/powersync/syncGate.js +0 -45
- package/dist/powersync/syncPass.d.ts +0 -9
- package/dist/powersync/syncPass.js +0 -33
- package/dist/powersync/tokenIndex.d.ts +0 -32
- package/dist/powersync/tokenIndex.js +0 -382
- package/dist/powersync/uploader.d.ts +0 -22
- package/dist/powersync/uploader.js +0 -231
- package/dist/requests/execute.d.ts +0 -11
- package/dist/requests/execute.js +0 -26
- package/dist/requests/store.d.ts +0 -10
- package/dist/requests/store.js +0 -190
- package/dist/runCli.d.ts +0 -2
- package/dist/runCli.js +0 -64
- package/dist/skills/check.d.ts +0 -7
- package/dist/skills/check.js +0 -747
- package/dist/skills/commandRefs.d.ts +0 -21
- package/dist/skills/commandRefs.js +0 -124
- package/dist/skills/generate.d.ts +0 -13
- package/dist/skills/generate.js +0 -80
- package/dist/skills/registry.d.ts +0 -13
- package/dist/skills/registry.js +0 -65
- package/dist/skills/retired.d.ts +0 -60
- package/dist/skills/retired.js +0 -58
- package/dist/utils/abort.d.ts +0 -6
- package/dist/utils/abort.js +0 -19
- package/dist/utils/argValue.d.ts +0 -1
- package/dist/utils/argValue.js +0 -18
- package/dist/utils/asyncRelease.d.ts +0 -2
- package/dist/utils/asyncRelease.js +0 -25
- package/dist/utils/authToken.d.ts +0 -4
- package/dist/utils/authToken.js +0 -28
- package/dist/utils/bidlinkCanonicalization.d.ts +0 -2
- package/dist/utils/bidlinkCanonicalization.js +0 -164
- package/dist/utils/consoleEncoding.d.ts +0 -5
- package/dist/utils/consoleEncoding.js +0 -27
- package/dist/utils/cursor.d.ts +0 -9
- package/dist/utils/cursor.js +0 -61
- package/dist/utils/deadline.d.ts +0 -8
- package/dist/utils/deadline.js +0 -31
- package/dist/utils/defaultFormat.d.ts +0 -8
- package/dist/utils/defaultFormat.js +0 -38
- package/dist/utils/dryRun.d.ts +0 -32
- package/dist/utils/dryRun.js +0 -88
- package/dist/utils/errorCodes.d.ts +0 -595
- package/dist/utils/errorCodes.js +0 -163
- package/dist/utils/errors.d.ts +0 -54
- package/dist/utils/errors.js +0 -277
- package/dist/utils/id.d.ts +0 -1
- package/dist/utils/id.js +0 -4
- package/dist/utils/nodeRuntime.d.ts +0 -4
- package/dist/utils/nodeRuntime.js +0 -12
- package/dist/utils/output.d.ts +0 -26
- package/dist/utils/output.js +0 -262
- package/dist/utils/processExit.d.ts +0 -1
- package/dist/utils/processExit.js +0 -33
- package/dist/utils/progress.d.ts +0 -25
- package/dist/utils/progress.js +0 -59
- package/dist/utils/redact.d.ts +0 -1
- package/dist/utils/redact.js +0 -10
- package/dist/utils/requestContext.d.ts +0 -32
- package/dist/utils/requestContext.js +0 -13
- package/dist/utils/select.d.ts +0 -20
- package/dist/utils/select.js +0 -92
- package/dist/utils/sqliteLease.d.ts +0 -8
- package/dist/utils/sqliteLease.js +0 -59
- package/dist/utils/syncTimeout.d.ts +0 -7
- package/dist/utils/syncTimeout.js +0 -20
- package/dist/utils/terminalSanitization.d.ts +0 -2
- package/dist/utils/terminalSanitization.js +0 -37
- package/dist/utils/text.d.ts +0 -1
- package/dist/utils/text.js +0 -35
- package/dist/utils/time.d.ts +0 -1
- package/dist/utils/time.js +0 -3
- package/dist/utils/tiptapMarkdown.d.ts +0 -9
- package/dist/utils/tiptapMarkdown.js +0 -381
- package/dist/utils/tiptapMarkdownSchema.d.ts +0 -37
- package/dist/utils/tiptapMarkdownSchema.js +0 -608
- package/dist/utils/tiptapMarkdownSchemaUtils.d.ts +0 -74
- package/dist/utils/tiptapMarkdownSchemaUtils.js +0 -394
- package/dist/utils/tiptapMarkdownSyntax.d.ts +0 -9
- package/dist/utils/tiptapMarkdownSyntax.js +0 -249
- package/dist/utils/tokenize.d.ts +0 -1
- package/dist/utils/tokenize.js +0 -67
- package/dist/utils/updateNotice.d.ts +0 -8
- package/dist/utils/updateNotice.js +0 -112
- package/dist/utils/usageError.d.ts +0 -37
- package/dist/utils/usageError.js +0 -127
- package/dist/utils/version.d.ts +0 -1
- package/dist/utils/version.js +0 -21
- package/dist/vendor/electron/domain/note-templates.d.ts +0 -3
- package/dist/vendor/electron/domain/note-templates.js +0 -232
- package/dist/vendor/electron/domain/properties.d.ts +0 -10
- package/dist/vendor/electron/domain/properties.js +0 -1549
- package/dist/vendor/electron/domain/saved-view-analytics.d.ts +0 -45
- package/dist/vendor/electron/domain/saved-view-analytics.js +0 -365
- package/dist/vendor/electron/domain/saved-view-relative-date.d.ts +0 -21
- package/dist/vendor/electron/domain/saved-view-relative-date.js +0 -153
- package/dist/vendor/electron/domain/saved-views.d.ts +0 -61
- package/dist/vendor/electron/domain/saved-views.js +0 -1120
- package/dist/vendor/electron/rpc.d.ts +0 -22
- package/dist/vendor/electron/rpc.js +0 -27
- package/dist/vendor/electron/shared/ai-errors.d.ts +0 -11
- package/dist/vendor/electron/shared/ai-errors.js +0 -107
- package/dist/vendor/electron/shared/external-types.d.ts +0 -20
- package/dist/vendor/electron/shared/external-types.js +0 -1
- package/dist/vendor/electron/shared/index.d.ts +0 -9
- package/dist/vendor/electron/shared/index.js +0 -7
- package/dist/vendor/electron/shared/note-properties.d.ts +0 -328
- package/dist/vendor/electron/shared/note-properties.js +0 -1027
- package/dist/vendor/electron/shared/note-templates.d.ts +0 -82
- package/dist/vendor/electron/shared/note-templates.js +0 -84
- package/dist/vendor/electron/shared/powersync-read-models.d.ts +0 -1716
- package/dist/vendor/electron/shared/powersync-read-models.js +0 -1
- package/dist/vendor/electron/shared/remote-device-agent.d.ts +0 -375
- package/dist/vendor/electron/shared/remote-device-agent.js +0 -191
- package/dist/vendor/electron/shared/saved-views.d.ts +0 -394
- package/dist/vendor/electron/shared/saved-views.js +0 -981
- package/dist/vendor/electron/shared/task-priority.d.ts +0 -42
- package/dist/vendor/electron/shared/task-priority.js +0 -186
- package/dist/vendor/electron/sql-utils.d.ts +0 -5
- package/dist/vendor/electron/sql-utils.js +0 -32
|
@@ -0,0 +1,1332 @@
|
|
|
1
|
+
import { createRequire as __dinoxCreateRequire } from 'node:module';
|
|
2
|
+
const require = __dinoxCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
unwrapRedirectLinksInLine
|
|
5
|
+
} from "./chunk-URYABAYN.js";
|
|
6
|
+
|
|
7
|
+
// ../../packages/clip-engine/src/clipBoilerplate.ts
|
|
8
|
+
var MAX_TAIL_SCAN = 25;
|
|
9
|
+
var MAX_SHORT_UNKNOWN = 2;
|
|
10
|
+
var MAX_REMOVED_RATIO = 0.35;
|
|
11
|
+
var MAX_REMOVED_CHARS = 3e3;
|
|
12
|
+
var CTA_MAX = 120;
|
|
13
|
+
var NOTICE_MAX = 400;
|
|
14
|
+
var FOLLOW_RES = [
|
|
15
|
+
/(点击|点一下|点|戳|长按)\s*(一下)?\s*(上方|下方|下面|上面|文末|底部|标题下方?)?\s*(的)?\s*(蓝字|蓝色字体?|小?卡片|名片|公众号名片|头像|公众号|[“"「【][^”"」】]{1,16}[”"」】])\s*[,,、]?\s*(一键)?\s*(关注|设为?星标|加星标|置顶)/,
|
|
16
|
+
/(欢迎|记得|请|别忘了?|可以|随手|顺手|求|帮忙|麻烦)\s*(点个?|加个?|给个?)?\s*关注\s*(我|我们|一下|本号|公众号|[「“【]|$|[~~!!。,,]|[^\s,。!?]{1,16}(公众号|吧|哦|呀|~|~|!|!))/,
|
|
17
|
+
/^(欢迎|记得)?关注\s*[「“【]?[^,。!?\s]{1,20}[」”】]?\s*[!!~~,,。]?$/,
|
|
18
|
+
/关注(我|我们|本号|公众号)[^。!?]{0,30}(第一时间|获取|不错过|每天|每周|持续|分享|干货|更新|带你|了解更多|看更多)/,
|
|
19
|
+
/持续关注\s*[【「“]/,
|
|
20
|
+
/(设为|设置为?|加为?|标为?|添加)\s*(星标|⭐)|星标\s*⭐|置顶\s*[((]?\s*标星|加星标|标星公众号|(?<!点)击星标/,
|
|
21
|
+
/(加|点|给)?个?关注[,,、]?\s*(不迷路|不走丢)/,
|
|
22
|
+
/^[^。!?]{0,12}点击\s*关注[^。!?]{0,6}$/,
|
|
23
|
+
/星标关注|^推荐关注/,
|
|
24
|
+
/^(点击|戳)\s*[「“"]?阅读原文[」”"]?[^。!?]{0,12}$/
|
|
25
|
+
];
|
|
26
|
+
var ENGAGE_RES = [
|
|
27
|
+
/一键三连|三连击?(吧|哦|走起|支持)?|点赞.{0,4}在看|在看.{0,4}(点赞|转发|分享)|点个?赞.{0,8}(转发|分享|收藏|在看)/,
|
|
28
|
+
/(关注|点赞|在看|转发|分享)[、和及与·\s]{1,3}.{0,12}(就是|是对).{0,10}(最大|支持|动力)/,
|
|
29
|
+
/(你的|您的)(支持|鼓励|关注)[^。]{0,6}(是|就是)[^。]{0,8}(最大|更新|更文|持续|坚持|前进|创作)[^。]{0,4}(动力|支持)/,
|
|
30
|
+
/(若|如果)?喜欢[^。]{0,6}点个?赞/,
|
|
31
|
+
/^(点赞|在看|转发|分享|收藏|关注)([\s、·||/]+(点赞|在看|转发|分享|收藏|关注))+$/,
|
|
32
|
+
/喜欢就(点|点击|给)|点点?\s*[「“"]?\s*(赞|在看)\s*[」”"]?.{0,12}(支持|让更多|鸡腿|鼓励|收到)|(点|点击)\s*[「“"]?在看[」”"]?\s*[,,]?\s*让/,
|
|
33
|
+
/(转发|分享)(给|到).{0,12}(朋友|需要的人|身边的?人|家人|朋友圈)/,
|
|
34
|
+
/加鸡腿/,
|
|
35
|
+
/^(点点?|点个|戳个?|给个|随手点个?)\s*[「“"]?\s*(赞|在看|喜欢|小心心)\s*[」”"]?\s*(?:[!!~~👍❤]|\u{FE0F})*$/u
|
|
36
|
+
];
|
|
37
|
+
var LEAD_IN_RE = /^(如果|若|要是)?(你|您)?(觉得|认为)?(今天|这篇|本文|文章|内容|这期|本期)?(文章|内容)?.{0,10}(有用|有收获|不错|有帮助|有启发|喜欢)[,,。!!~~…]*$/;
|
|
38
|
+
var QR_RES = [
|
|
39
|
+
/(长按|扫描|扫码|扫一扫|识别).{0,10}(二维码|关注|加入|添加|进群|入群|领取|咨询|报名|加我)/,
|
|
40
|
+
/(二维码|下方码|下图码).{0,8}(关注|加入|进群|添加|领取)/
|
|
41
|
+
];
|
|
42
|
+
var GROUP_RES = [
|
|
43
|
+
/(加入|进|入)\s*(我们的?|粉丝|读者|交流|技术|学习|社|微信|官方|[^\s,。]{1,10})?\s*(群|社群)(?!体)/
|
|
44
|
+
];
|
|
45
|
+
var GROUP_ACTION_RE = /(添加|加(?!入)|联系|扫|备注|拉你|回复|输入|小助手|小编|助理|微信|v信|V信|\bV\b|\bv\b)/;
|
|
46
|
+
var GROUP_INVITE_RE = /^欢迎加入.{0,24}(群|社群|社区)[!!。~~]?$/;
|
|
47
|
+
var CONTACT_RE = /(加|添加|联系)\s*(我的?|小编|作者|助理|小助手)?\s*(微信|V|v|wx|vx|VX)\s*[::]?\s*[((]?[A-Za-z][A-Za-z0-9_-]{4,}/;
|
|
48
|
+
var COPYRIGHT_RES = [
|
|
49
|
+
/转载请|如需转载|转载需|转载开白|开白请|授权转载|未经[^。]{0,12}(授权|许可|允许)[^。]{0,16}(转载|使用|复制|摘编|禁止)|禁止转载|谢绝转载|严禁转载/,
|
|
50
|
+
/版权(归|所有|声明|说明)|著作权归|侵删|如有侵权|若有侵权|侵权请?联系|涉及版权问题|版权问题请/,
|
|
51
|
+
/(不代表|仅代表)[^。]{0,10}(本号|本平台|本公众号|本站|平台|[^\s。]{1,8})立场/,
|
|
52
|
+
/投稿或寻求报道|商务合作[,,::]?\s*请?(联系|添加)/
|
|
53
|
+
];
|
|
54
|
+
var REWARD_RE = /(赞赏|打赏)/;
|
|
55
|
+
var REWARD_CTA_RE = /(喜欢|觉得|支持|鼓励|请|欢迎|随意|一杯|作者|码)/;
|
|
56
|
+
var RELATED_HEADER_RE = /^(往期|推荐阅读|相关阅读|延伸阅读|精选回顾|历史文章|热门文章|猜你喜欢|往期精选|往期回顾|往期推荐|往期切片|往期文章|近期热文|热文推荐|精彩回顾|更多阅读|阅读推荐)[^,。!?]{0,8}[::|丨]?$/;
|
|
57
|
+
var AD_MARKER_RE = /^[—\-–\s·]*(广告|推广|AD)[—\-–\s·]*$/i;
|
|
58
|
+
var AD_LEAD_RE = /(▼|👇|点下图|点击下图|戳下图|点击图片|点图)/;
|
|
59
|
+
var DECORATION_RE = /^([-—–_~·•\s]*(END|THE\s*END|©\s*THE\s*END|完|全文完|-完-)[-—–_~·•\s]*|(?:[↓▼👇⬇☝👆\s]|\u{FE0F}|[\u{1F3FB}-\u{1F3FF}])+|[*\-_ ]{3,}|(?:[♥◎★☆❤💗👍\s]|\u{FE0F}|[\u{1F3FB}-\u{1F3FF}])+|赞|在看|收藏|分享|点赞|转发|喜欢|华丽丽的分割线|分割线)$/iu;
|
|
60
|
+
var CREDIT_RE = /^(来源|文章来源|资料来源|内容来源|图片(来源)?|题图|配图|封面|作者|文|编辑|责编|责任编辑|校对|审核|审校|排版|美编|制作|主播|编辑排版|监制|出品|策划|撰文|摄影|翻译|编译|整理|参考(资料|链接|文献)?|原文|项目地址|开源地址|仓库地址|GitHub)\s*[||:://]/i;
|
|
61
|
+
var PROVENANCE_RE = /(转载自|来源于|来自|出自|原载于|原文载于|首发于|发布于|原创\/授权)/;
|
|
62
|
+
var MIXED_CONTENT_RE = /(\d{4}\s*年|写于|全文完)/;
|
|
63
|
+
var HASHTAG_LINE_RE = /^(#[^#\s]+#?\s*)+$/;
|
|
64
|
+
var QR_IMAGE_HINT_RE = /(二维码|qrcode|qr_code|qr-code|名片|赞赏码|收款码|关注|扫码)/i;
|
|
65
|
+
var HEAD_PARAGRAPHS = 3;
|
|
66
|
+
var HEAD_MAX = 80;
|
|
67
|
+
var ARTICLE_NAV_RE = /^(上一篇|下一篇|上一页|下一页|上一章|下一章|上一节|下一节|返回顶部|回到顶部|返回首页|previous(?:\s+(?:post|article|page))?|next(?:\s+(?:post|article|page))?|prev|«\s*prev|next\s*»)(\s*[::]|\s*$)/i;
|
|
68
|
+
var ARTICLE_NAV_MAX = 200;
|
|
69
|
+
function isArticleNav(text) {
|
|
70
|
+
if (!ARTICLE_NAV_RE.test(text) || text.length > ARTICLE_NAV_MAX) return false;
|
|
71
|
+
return (text.match(/[。!?]/g) ?? []).length < 2;
|
|
72
|
+
}
|
|
73
|
+
function stripClipBoilerplate(markdown, profile = "generic") {
|
|
74
|
+
const paragraphs = splitParagraphs(markdown);
|
|
75
|
+
if (paragraphs.length < 3) return { markdown, removed: [] };
|
|
76
|
+
const totalChars = paragraphs.reduce((sum, p) => sum + plainText(p.raw).length, 0);
|
|
77
|
+
const remove = /* @__PURE__ */ new Map();
|
|
78
|
+
collectTail(paragraphs, remove);
|
|
79
|
+
collectHead(paragraphs, remove);
|
|
80
|
+
if (profile === "wechat") collectAds(paragraphs, remove);
|
|
81
|
+
collectMidNav(paragraphs, remove);
|
|
82
|
+
if (!remove.size) return { markdown, removed: [] };
|
|
83
|
+
const removedChars = [...remove.keys()].reduce((sum, index) => sum + plainText(paragraphs[index].raw).length, 0);
|
|
84
|
+
const keptParagraphs = paragraphs.filter((_, index) => !remove.has(index));
|
|
85
|
+
const keptText = keptParagraphs.reduce((sum, p) => sum + plainText(p.raw).length, 0);
|
|
86
|
+
if (removedChars > MAX_REMOVED_CHARS || totalChars > 0 && removedChars / totalChars > MAX_REMOVED_RATIO || keptText < 80 || !keptParagraphs.some((p) => !isImageOnly(p.raw)))
|
|
87
|
+
return { markdown, removed: [] };
|
|
88
|
+
let output = "";
|
|
89
|
+
let cursor = 0;
|
|
90
|
+
const ordered = [...remove.keys()].sort((a, b) => a - b);
|
|
91
|
+
for (const index of ordered) {
|
|
92
|
+
const paragraph = paragraphs[index];
|
|
93
|
+
output += markdown.slice(cursor, paragraph.start);
|
|
94
|
+
cursor = paragraph.end;
|
|
95
|
+
}
|
|
96
|
+
output += markdown.slice(cursor);
|
|
97
|
+
return {
|
|
98
|
+
markdown: output.replace(/\n{3,}/g, "\n\n").trim(),
|
|
99
|
+
removed: ordered.map((index) => remove.get(index))
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function collectTail(paragraphs, remove) {
|
|
103
|
+
const zone = [];
|
|
104
|
+
let shortUnknown = 0;
|
|
105
|
+
for (let index = paragraphs.length - 1; index >= Math.max(1, paragraphs.length - MAX_TAIL_SCAN); index -= 1) {
|
|
106
|
+
let verdict = classify(paragraphs[index], "tail");
|
|
107
|
+
if (verdict.type === "content" && isShortSignature(paragraphs[index].raw) && shortUnknown < MAX_SHORT_UNKNOWN) {
|
|
108
|
+
shortUnknown += 1;
|
|
109
|
+
verdict = { type: "keep" };
|
|
110
|
+
}
|
|
111
|
+
if (verdict.type === "content") break;
|
|
112
|
+
zone.unshift({ index, verdict });
|
|
113
|
+
}
|
|
114
|
+
const firstStrip = zone.findIndex((entry) => entry.verdict.type === "strip");
|
|
115
|
+
if (firstStrip < 0) return;
|
|
116
|
+
for (const entry of zone.slice(0, firstStrip))
|
|
117
|
+
if (entry.verdict.type === "follower" && entry.verdict.kind === "image" && boilerplateImageHint(paragraphs[entry.index].raw))
|
|
118
|
+
remove.set(entry.index, { kind: "qrcode", position: "tail", text: paragraphs[entry.index].raw });
|
|
119
|
+
let lastStrip = null;
|
|
120
|
+
for (const entry of zone.slice(firstStrip)) {
|
|
121
|
+
if (entry.verdict.type === "strip") lastStrip = entry.verdict.kind;
|
|
122
|
+
if (entry.verdict.type !== "strip" && entry.verdict.type !== "follower") continue;
|
|
123
|
+
if (entry.verdict.type === "follower" && entry.verdict.kind === "link-list" && lastStrip !== "related" && !isBareUrlLinkList(paragraphs[entry.index].raw))
|
|
124
|
+
continue;
|
|
125
|
+
remove.set(entry.index, { kind: entry.verdict.kind, position: "tail", text: paragraphs[entry.index].raw });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function collectHead(paragraphs, remove) {
|
|
129
|
+
for (let index = 0; index < Math.min(HEAD_PARAGRAPHS, paragraphs.length - 1); index += 1) {
|
|
130
|
+
const paragraph = paragraphs[index];
|
|
131
|
+
if (paragraph.fenced) return;
|
|
132
|
+
const text = plainText(paragraph.raw);
|
|
133
|
+
if (!text) continue;
|
|
134
|
+
if (isArticleNav(text)) {
|
|
135
|
+
remove.set(index, { kind: "related", position: "head", text: paragraph.raw });
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (text.length > HEAD_MAX) continue;
|
|
139
|
+
const kind = matchFollowOrEngage(text);
|
|
140
|
+
if (kind) remove.set(index, { kind, position: "head", text: paragraph.raw });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function collectAds(paragraphs, remove) {
|
|
144
|
+
paragraphs.forEach((paragraph, index) => {
|
|
145
|
+
if (paragraph.fenced || !AD_MARKER_RE.test(plainText(paragraph.raw))) return;
|
|
146
|
+
remove.set(index, { kind: "ad", position: "ad", text: paragraph.raw });
|
|
147
|
+
const lead = [];
|
|
148
|
+
for (let back = index - 1; back >= Math.max(0, index - 3); back -= 1) {
|
|
149
|
+
const text = plainText(paragraphs[back].raw);
|
|
150
|
+
if (paragraphs[back].fenced || text.length > 40) break;
|
|
151
|
+
lead.unshift(back);
|
|
152
|
+
if (AD_LEAD_RE.test(text)) {
|
|
153
|
+
for (const leadIndex of lead) remove.set(leadIndex, { kind: "ad", position: "ad", text: paragraphs[leadIndex].raw });
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function collectMidNav(paragraphs, remove) {
|
|
160
|
+
paragraphs.forEach((paragraph, index) => {
|
|
161
|
+
if (remove.has(index) || paragraph.fenced) return;
|
|
162
|
+
const text = plainText(paragraph.raw);
|
|
163
|
+
if (text && isArticleNav(text)) remove.set(index, { kind: "related", position: "mid", text: paragraph.raw });
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
function classify(paragraph, position) {
|
|
167
|
+
void position;
|
|
168
|
+
if (paragraph.fenced) return isFencedSignOff(paragraph.raw) ? { type: "strip", kind: "engage" } : { type: "content" };
|
|
169
|
+
if (isImageOnly(paragraph.raw)) return { type: "follower", kind: "image" };
|
|
170
|
+
const text = plainText(paragraph.raw);
|
|
171
|
+
if (text && isArticleNav(text)) return { type: "strip", kind: "related" };
|
|
172
|
+
if (isLinkList(paragraph.raw)) return { type: "follower", kind: "link-list" };
|
|
173
|
+
if (!text) return { type: "follower", kind: "decoration" };
|
|
174
|
+
if (DECORATION_RE.test(text)) return { type: "follower", kind: "decoration" };
|
|
175
|
+
if (AD_MARKER_RE.test(text)) return { type: "strip", kind: "ad" };
|
|
176
|
+
if (text.length <= 40 && RELATED_HEADER_RE.test(text)) return { type: "strip", kind: "related" };
|
|
177
|
+
if (text.length <= 80 && (CREDIT_RE.test(text) || HASHTAG_LINE_RE.test(text))) return { type: "keep" };
|
|
178
|
+
if (PROVENANCE_RE.test(text)) return { type: "keep" };
|
|
179
|
+
if (/^\d+\s*[、..]/.test(text) || MIXED_CONTENT_RE.test(text)) return { type: "content" };
|
|
180
|
+
if (text.length <= NOTICE_MAX && COPYRIGHT_RES.some((re) => re.test(text))) return { type: "strip", kind: "copyright" };
|
|
181
|
+
if (text.length <= CTA_MAX) {
|
|
182
|
+
const kind = matchFollowOrEngage(text);
|
|
183
|
+
if (kind) return { type: "strip", kind };
|
|
184
|
+
if (QR_RES.some((re) => re.test(text))) return { type: "strip", kind: "qrcode" };
|
|
185
|
+
if (GROUP_INVITE_RE.test(text) || GROUP_RES.some((re) => re.test(text)) && GROUP_ACTION_RE.test(text))
|
|
186
|
+
return { type: "strip", kind: "group" };
|
|
187
|
+
if (CONTACT_RE.test(text)) return { type: "strip", kind: "group" };
|
|
188
|
+
if (text.length <= 80 && REWARD_RE.test(text) && REWARD_CTA_RE.test(text)) return { type: "strip", kind: "reward" };
|
|
189
|
+
if (text.length <= 30 && LEAD_IN_RE.test(text)) return { type: "strip", kind: "engage" };
|
|
190
|
+
}
|
|
191
|
+
return { type: "content" };
|
|
192
|
+
}
|
|
193
|
+
function matchFollowOrEngage(text) {
|
|
194
|
+
if (FOLLOW_RES.some((re) => re.test(text))) return "follow";
|
|
195
|
+
if (ENGAGE_RES.some((re) => re.test(text))) return "engage";
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
function splitParagraphs(markdown) {
|
|
199
|
+
const paragraphs = [];
|
|
200
|
+
const lines = markdown.split("\n");
|
|
201
|
+
let offset = 0;
|
|
202
|
+
let current = null;
|
|
203
|
+
let fence = null;
|
|
204
|
+
const flush = (end) => {
|
|
205
|
+
if (current && current.lines.some((line) => line.trim()))
|
|
206
|
+
paragraphs.push({ end, fenced: current.fenced, raw: current.lines.join("\n"), start: current.start });
|
|
207
|
+
current = null;
|
|
208
|
+
};
|
|
209
|
+
for (const line of lines) {
|
|
210
|
+
const lineEnd = offset + line.length + 1;
|
|
211
|
+
const marker = line.match(/^\s{0,3}(`{3,}|~{3,})/)?.[1];
|
|
212
|
+
if (fence) {
|
|
213
|
+
current.lines.push(line);
|
|
214
|
+
if (marker && marker[0] === fence[0] && marker.length >= fence.length && !line.trim().slice(marker.length).trim()) {
|
|
215
|
+
fence = null;
|
|
216
|
+
}
|
|
217
|
+
offset = lineEnd;
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
if (marker) {
|
|
221
|
+
if (!current) current = { fenced: true, lines: [], start: offset };
|
|
222
|
+
current.fenced = true;
|
|
223
|
+
current.lines.push(line);
|
|
224
|
+
fence = marker;
|
|
225
|
+
offset = lineEnd;
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
if (!line.trim()) {
|
|
229
|
+
flush(offset);
|
|
230
|
+
} else {
|
|
231
|
+
if (!current) current = { fenced: false, lines: [], start: offset };
|
|
232
|
+
current.lines.push(line);
|
|
233
|
+
}
|
|
234
|
+
offset = lineEnd;
|
|
235
|
+
}
|
|
236
|
+
flush(Math.min(offset, markdown.length));
|
|
237
|
+
return paragraphs;
|
|
238
|
+
}
|
|
239
|
+
var IMAGE_RE = /!\[((?:\\.|[^\]\\])*)\]\(([^)\s]+)(?:\s+"([^"]*)")?\)/g;
|
|
240
|
+
function isImageOnly(raw) {
|
|
241
|
+
if (!raw.includes("![")) return false;
|
|
242
|
+
const rest = raw.replace(/<!--[\s\S]*?-->/g, "").replace(/\[(!\[(?:\\.|[^\]\\])*\]\([^)]*\))\]\([^)]*\)/g, "$1").replace(IMAGE_RE, "").replace(/[*_\s]/g, "");
|
|
243
|
+
return rest.length === 0;
|
|
244
|
+
}
|
|
245
|
+
function isLinkList(raw) {
|
|
246
|
+
const lines = raw.split("\n").filter((line) => line.trim());
|
|
247
|
+
return lines.length > 0 && lines.every((line) => {
|
|
248
|
+
const stripped = line.replace(/^\s*(?:[-*+]|\d+[.)])\s+/, "").replace(/[*_]/g, "").trim();
|
|
249
|
+
const withoutLinks = stripped.replace(/\[(?:\\.|[^\]\\])*\]\([^)]*\)/g, "").trim();
|
|
250
|
+
return stripped !== withoutLinks && withoutLinks.length <= 8;
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
function isShortSignature(raw) {
|
|
254
|
+
const text = plainText(raw);
|
|
255
|
+
return text.length > 0 && text.length <= 24 && !/[。!?!?,,;;::]/.test(text);
|
|
256
|
+
}
|
|
257
|
+
function plainText(raw) {
|
|
258
|
+
return raw.replace(/<!--[\s\S]*?-->/g, "").replace(IMAGE_RE, "").replace(/\[((?:\\.|[^\]\\])*)\]\([^)]*\)/g, "$1").replace(/^\s{0,3}(#{1,6}|>)\s*/gm, "").replace(/\\([\\`*_{}[\]()#+\-.!|<>])/g, "$1").replace(/[*_`]/g, "").replace(/\s+/g, " ").trim();
|
|
259
|
+
}
|
|
260
|
+
function boilerplateImageHint(raw) {
|
|
261
|
+
for (const match of raw.matchAll(IMAGE_RE)) if (QR_IMAGE_HINT_RE.test(`${match[1]} ${match[2]} ${match[3] ?? ""}`)) return true;
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
function isFencedSignOff(raw) {
|
|
265
|
+
const lines = raw.split("\n");
|
|
266
|
+
if (!/^\s{0,3}(`{3,}|~{3,})\s*$/.test(lines[0] ?? "")) return false;
|
|
267
|
+
const body = lines.slice(1).filter((line) => !/^\s{0,3}(`{3,}|~{3,})\s*$/.test(line)).map((line) => line.replace(/[\s❖◆◇■□●○✦✧❀✿]+/g, ""));
|
|
268
|
+
const filled = body.filter(Boolean);
|
|
269
|
+
return filled.length > 0 && filled.length <= 6 && filled.every((text) => text.length <= 30 && (DECORATION_RE.test(text) || /^(全文完|完)$/.test(text) || matchFollowOrEngage(text) !== null));
|
|
270
|
+
}
|
|
271
|
+
function isBareUrlLinkList(raw) {
|
|
272
|
+
const links = [...raw.matchAll(/\[((?:\\.|[^\]\\])*)\]\(([^)\s]+)\)/g)];
|
|
273
|
+
return links.length > 0 && links.every((link) => /^https?:/.test(link[1].replace(/\\/g, "")));
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// ../../packages/clip-engine/src/clipFormulaImage.ts
|
|
277
|
+
var FORMULA_ALT_RE = /^(?=.*(?:[A-Za-z\u0391-\u03c9]|\d))[A-Za-z0-9\u0391-\u03c9\s\\^_{}()[\]/+\-*=<>|.,'%′–—]{1,60}$/u;
|
|
278
|
+
var FORMULA_OPERATOR_RE = /[\\^_{}/+=<>|%–—]|\s-\s/;
|
|
279
|
+
var FILE_NAME_ALT_RE = /\.(?:png|jpe?g|gif|webp|svg|bmp)$/i;
|
|
280
|
+
function isInlineFormulaImageAlt(alt, { singleLetter = true } = {}) {
|
|
281
|
+
const value = alt.trim();
|
|
282
|
+
if (!FORMULA_ALT_RE.test(value) || FILE_NAME_ALT_RE.test(value)) return false;
|
|
283
|
+
return singleLetter && value.length === 1 || FORMULA_OPERATOR_RE.test(value);
|
|
284
|
+
}
|
|
285
|
+
function markdownImageAlt(image) {
|
|
286
|
+
const match = /^!\[((?:\\.|[^\]\\])*)\]/.exec(image.trim());
|
|
287
|
+
return (match?.[1] ?? "").replace(/\\(.)/g, "$1");
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// ../../packages/clip-engine/src/clipMarkdownNormalize.ts
|
|
291
|
+
var FULLWIDTH_CLOSING = "\uFF0C\u3002\uFF1A\uFF1B\uFF01\uFF1F\u3001\uFF09\u300B\u300D\u300F\u3011";
|
|
292
|
+
var FULLWIDTH_OPENING = "\uFF0C\u3002\uFF1A\uFF1B\uFF01\uFF1F\u3001\uFF08\u300A\u300C\u300E\u3010";
|
|
293
|
+
var MARKUP_CLOSE_BEFORE_PUNCT = new RegExp(String.raw`([*_\x60)\]]) +([${FULLWIDTH_CLOSING}])`, "gu");
|
|
294
|
+
var PUNCT_BEFORE_MARKUP_OPEN = new RegExp(String.raw`([${FULLWIDTH_OPENING}]) +([*_\x60\[!])`, "gu");
|
|
295
|
+
var PUNCT_RE = /[\p{P}\p{S}]/u;
|
|
296
|
+
var SPACE_RE = /\s/u;
|
|
297
|
+
var IMAGE_UNIT_RE = String.raw`!\[(?:\\.|[^\]\\])*\]\([^)\s]+(?:\s+"[^"]*")?\)(?:\s*<!--[\s\S]*?-->)?`;
|
|
298
|
+
var ALLOWED_INLINE_HTML = /* @__PURE__ */ new Set(["video", "audio", "source", "br", "iframe", "img", "sup", "sub", "u", "kbd", "details", "summary", "mark"]);
|
|
299
|
+
var LINKED_IMAGE_UNIT_RE = String.raw`(?:\[${IMAGE_UNIT_RE}\]\([^)\s]+(?:\s+"[^"]*")?\)|${IMAGE_UNIT_RE})`;
|
|
300
|
+
var STANDALONE_IMAGE_LINE_RE = new RegExp(String.raw`^${LINKED_IMAGE_UNIT_RE}(?:[ \t]+${LINKED_IMAGE_UNIT_RE})*[ \t]*$`);
|
|
301
|
+
function isTextLine(line) {
|
|
302
|
+
if (!line?.trim() || /^\s/.test(line)) return false;
|
|
303
|
+
if (/^(?:>|\||#{1,6}\s|`{3,}|~{3,})/.test(line)) return false;
|
|
304
|
+
return !STANDALONE_IMAGE_LINE_RE.test(line);
|
|
305
|
+
}
|
|
306
|
+
function isParagraphAfterImage(line) {
|
|
307
|
+
if (!line?.trim()) return false;
|
|
308
|
+
if (STANDALONE_IMAGE_LINE_RE.test(line)) return false;
|
|
309
|
+
const trimmed = line.trimStart();
|
|
310
|
+
if (/^(?:>|\||#{1,6}\s|`{3,}|~{3,}|[-*+] |\d+\. )/.test(trimmed)) return false;
|
|
311
|
+
return true;
|
|
312
|
+
}
|
|
313
|
+
function deindentSoftParagraph(line) {
|
|
314
|
+
if (/^\s*([-*+] |\d+\. )/.test(line)) return line;
|
|
315
|
+
if (/^\s+/.test(line) && isParagraphAfterImage(line)) return line.trimStart();
|
|
316
|
+
return line;
|
|
317
|
+
}
|
|
318
|
+
var THEMATIC_BREAK_RE = /^\s{0,3}(?:(?:\*[ \t]*){3,}|(?:-[ \t]*){3,}|(?:_[ \t]*){3,})$/;
|
|
319
|
+
function lastNonBlank(lines) {
|
|
320
|
+
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
321
|
+
if (!lines[index]?.trim()) continue;
|
|
322
|
+
return index === 0 || !lines[index - 1]?.trim() ? lines[index] : "";
|
|
323
|
+
}
|
|
324
|
+
return "";
|
|
325
|
+
}
|
|
326
|
+
var HEADING_IMAGE_RE = new RegExp(LINKED_IMAGE_UNIT_RE, "g");
|
|
327
|
+
var DISCLAIMER_HEADING_RE = /^(?:(?:来源|转自|转载自?|文章来源)[::].*(?:侵删|侵权|仅供)|本文.*(?:仅供|仅作为).*(?:交流|参考|学习))/u;
|
|
328
|
+
function splitHeadingImages(lines) {
|
|
329
|
+
const out = [];
|
|
330
|
+
let fence = null;
|
|
331
|
+
for (const line of lines) {
|
|
332
|
+
const marker = line.match(/^\s{0,3}(`{3,}|~{3,})/)?.[1];
|
|
333
|
+
if (fence) {
|
|
334
|
+
if (marker && marker[0] === fence[0] && marker.length >= fence.length) fence = null;
|
|
335
|
+
out.push(line);
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
if (marker) {
|
|
339
|
+
fence = marker;
|
|
340
|
+
out.push(line);
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
const heading = line.match(/^(\s{0,3}#{1,6})[ \t]+(.*)$/);
|
|
344
|
+
if (!heading) {
|
|
345
|
+
out.push(line);
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
const codeSpans = [];
|
|
349
|
+
const masked = heading[2].replace(/(`+)[\s\S]*?\1/g, (span) => `\uE000${codeSpans.push(span) - 1}\uE000`);
|
|
350
|
+
const images = masked.match(HEADING_IMAGE_RE);
|
|
351
|
+
const text = masked.replace(HEADING_IMAGE_RE, " ").replace(/\uE000(\d+)\uE000/g, (_, index) => codeSpans[Number(index)]).replace(/[ \t]+#+[ \t]*$/, "").replace(/(^|\s)(\*{1,3}|_{1,3})\s+/g, "$1$2").replace(/\s+(\*{1,3}|_{1,3})(?=\s|$)/g, "$1").replace(/(^|\s)(\*{1,3}|_{1,3})\s*\2(?=\s|$)/g, "$1").replace(/[ \t]{2,}/g, " ").trim();
|
|
352
|
+
const disclaimer = DISCLAIMER_HEADING_RE.test(text.replace(/\*+/g, ""));
|
|
353
|
+
if (!images && !disclaimer) {
|
|
354
|
+
out.push(line);
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
if (out.length && out[out.length - 1].trim()) out.push("");
|
|
358
|
+
if (text) {
|
|
359
|
+
out.push(disclaimer ? text : `${heading[1]} ${text}`);
|
|
360
|
+
if (images) out.push("");
|
|
361
|
+
}
|
|
362
|
+
if (images) out.push(...images.map((image) => image.trim()));
|
|
363
|
+
}
|
|
364
|
+
return out;
|
|
365
|
+
}
|
|
366
|
+
var LIST_ITEM_RE = /^(\s*)([-*+]|\d{1,3}[.)])([ \t]+)(\S.*)$/;
|
|
367
|
+
var LIST_CONTINUATION_PUNCT_RE = new RegExp(`^[${FULLWIDTH_CLOSING}:;,]`, "u");
|
|
368
|
+
function joinListPunctuationContinuations(lines) {
|
|
369
|
+
const out = [];
|
|
370
|
+
let fence = null;
|
|
371
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
372
|
+
const line = lines[index];
|
|
373
|
+
const marker = line.match(/^\s{0,3}(`{3,}|~{3,})/)?.[1];
|
|
374
|
+
if (fence) {
|
|
375
|
+
if (marker && marker[0] === fence[0] && marker.length >= fence.length) fence = null;
|
|
376
|
+
out.push(line);
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
if (marker) {
|
|
380
|
+
fence = marker;
|
|
381
|
+
out.push(line);
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
const item = line.match(LIST_ITEM_RE);
|
|
385
|
+
if (!item || /-->\s*$|^\s*!\[/.test(item[4])) {
|
|
386
|
+
out.push(line);
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
const contentIndent = item[1].length + item[2].length + item[3].length;
|
|
390
|
+
let next = index + 1;
|
|
391
|
+
while (next < lines.length && next - index <= 3 && !lines[next].trim()) next += 1;
|
|
392
|
+
const continuation = lines[next];
|
|
393
|
+
const indent = continuation?.match(/^[ \t]*/)?.[0].length ?? 0;
|
|
394
|
+
if (next > index + 1 && continuation !== void 0 && indent >= contentIndent && indent < contentIndent + 4 && LIST_CONTINUATION_PUNCT_RE.test(continuation.trim())) {
|
|
395
|
+
out.push(`${line.trimEnd()}${continuation.trim()}`);
|
|
396
|
+
index = next;
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
out.push(line);
|
|
400
|
+
}
|
|
401
|
+
return out;
|
|
402
|
+
}
|
|
403
|
+
var DOUBLE_HTML_ENTITY_RE = /&(nbsp|amp|lt|gt|quot|apos|#(?:\d+|x[0-9a-f]+));/gi;
|
|
404
|
+
var NAMED_HTML_ENTITIES = {
|
|
405
|
+
amp: "&",
|
|
406
|
+
apos: "'",
|
|
407
|
+
gt: ">",
|
|
408
|
+
lt: "<",
|
|
409
|
+
nbsp: "\xA0",
|
|
410
|
+
quot: '"'
|
|
411
|
+
};
|
|
412
|
+
function decodeResidualDoubleHtmlEntities(text) {
|
|
413
|
+
if (!DOUBLE_HTML_ENTITY_RE.test(text)) return text;
|
|
414
|
+
DOUBLE_HTML_ENTITY_RE.lastIndex = 0;
|
|
415
|
+
let previous = "";
|
|
416
|
+
let current = text;
|
|
417
|
+
while (previous !== current) {
|
|
418
|
+
previous = current;
|
|
419
|
+
current = current.replace(DOUBLE_HTML_ENTITY_RE, (match, name) => {
|
|
420
|
+
const key = name.toLowerCase();
|
|
421
|
+
if (key in NAMED_HTML_ENTITIES) return NAMED_HTML_ENTITIES[key];
|
|
422
|
+
if (key.startsWith("#x")) return String.fromCodePoint(Number.parseInt(key.slice(2), 16));
|
|
423
|
+
if (key.startsWith("#")) return String.fromCodePoint(Number.parseInt(key.slice(1), 10));
|
|
424
|
+
return match;
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
return current;
|
|
428
|
+
}
|
|
429
|
+
function normalizeClipMarkdownBody(markdown) {
|
|
430
|
+
const lines = fixCjkLabelLayout(splitHeadingImages(dropStrandedParagraphClosers(closeOrphanStandaloneBold(closeBoldBrokenByBlockImages(splitOrCloseParagraphSpanningItalic(splitParagraphSpanningBold(unwrapSpanningLinkListBold(joinListPunctuationContinuations(joinStrandedEmphasis(unwrapDiscourseLightboxMarkdown(markdown).split("\n")))))))))));
|
|
431
|
+
const out = [];
|
|
432
|
+
let fence = null;
|
|
433
|
+
let dropBlank = false;
|
|
434
|
+
for (let line of lines) {
|
|
435
|
+
if (dropBlank) {
|
|
436
|
+
dropBlank = false;
|
|
437
|
+
if (!line.trim()) continue;
|
|
438
|
+
}
|
|
439
|
+
const marker = line.match(/^\s{0,3}(`{3,}|~{3,})/)?.[1];
|
|
440
|
+
line = decodeResidualDoubleHtmlEntities(line);
|
|
441
|
+
if (fence) {
|
|
442
|
+
if (marker && marker[0] === fence[0] && marker.length >= fence.length && !line.trim().slice(marker.length).trim()) fence = null;
|
|
443
|
+
out.push(line);
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
if (marker) {
|
|
447
|
+
fence = marker;
|
|
448
|
+
out.push(line);
|
|
449
|
+
continue;
|
|
450
|
+
}
|
|
451
|
+
if (/^\s{0,3}#{1,6}\s*$/.test(line)) {
|
|
452
|
+
dropBlank = out.length === 0 || !out[out.length - 1]?.trim();
|
|
453
|
+
continue;
|
|
454
|
+
}
|
|
455
|
+
if (/^\s*\*\*\s*$/.test(line)) {
|
|
456
|
+
dropBlank = out.length === 0 || !out[out.length - 1]?.trim();
|
|
457
|
+
continue;
|
|
458
|
+
}
|
|
459
|
+
if (/^\s*\\\*\s*$/.test(line)) {
|
|
460
|
+
dropBlank = out.length === 0 || !out[out.length - 1]?.trim();
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
if (/^\s*>\s*!\[/.test(line) && /^\s*>\s*(?!!\[)\S/.test(out[out.length - 1] ?? "")) {
|
|
464
|
+
out.push(line.match(/^\s*>/)[0]);
|
|
465
|
+
}
|
|
466
|
+
if (STANDALONE_IMAGE_LINE_RE.test(line) && isTextLine(out[out.length - 1])) out.push("");
|
|
467
|
+
if (!line.trim()) {
|
|
468
|
+
out.push("");
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
if (STANDALONE_IMAGE_LINE_RE.test(out[out.length - 1] ?? "") && isParagraphAfterImage(line)) {
|
|
472
|
+
out.push("");
|
|
473
|
+
line = deindentSoftParagraph(line);
|
|
474
|
+
}
|
|
475
|
+
if (THEMATIC_BREAK_RE.test(line) && THEMATIC_BREAK_RE.test(lastNonBlank(out))) {
|
|
476
|
+
while (out.length && !out[out.length - 1]?.trim()) out.pop();
|
|
477
|
+
dropBlank = false;
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
out.push(normalizeLine(line));
|
|
481
|
+
}
|
|
482
|
+
return out.join("\n").replace(/\n{4,}/g, "\n\n\n");
|
|
483
|
+
}
|
|
484
|
+
function dropEmptyAndPunctuationBold(line) {
|
|
485
|
+
const runs = [...line.matchAll(/\*+/g)];
|
|
486
|
+
if (runs.some((run) => run[0].length === 3 || run[0].length > 4)) return line;
|
|
487
|
+
let text = line;
|
|
488
|
+
if (/[^*\s]\*{4}\s*$/.test(text) && runs.filter((run) => run[0].length === 4).length === 1) {
|
|
489
|
+
text = text.replace(/\*{4}\s*$/, "");
|
|
490
|
+
if (countRuns(text, 2) % 2 === 1) return line;
|
|
491
|
+
}
|
|
492
|
+
if (/\*{4}/.test(text)) return text;
|
|
493
|
+
const pairs = [...text.matchAll(/\*\*/g)].map((run) => run.index);
|
|
494
|
+
if (pairs.length % 2 !== 0) return text;
|
|
495
|
+
for (let index = pairs.length - 2; index >= 0; index -= 2) {
|
|
496
|
+
const open = pairs[index];
|
|
497
|
+
const close = pairs[index + 1];
|
|
498
|
+
const inner = text.slice(open + 2, close);
|
|
499
|
+
if (!inner || !/^[\s\p{P}\p{S}]+$/u.test(inner)) continue;
|
|
500
|
+
if (isLeftFlanking(text.slice(open - 1, open), inner.slice(0, 1)) && isRightFlanking(inner.slice(-1), text.slice(close + 2, close + 3))) {
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
text = text.slice(0, open) + inner + text.slice(close + 2);
|
|
504
|
+
}
|
|
505
|
+
return text;
|
|
506
|
+
}
|
|
507
|
+
function countRuns(line, size) {
|
|
508
|
+
return (line.match(/\*+/g) ?? []).filter((run) => run.length === size).length;
|
|
509
|
+
}
|
|
510
|
+
function collapseEmptyBoldPrefix(line) {
|
|
511
|
+
if (/^\*{4}\s*$/.test(line)) return line.replace("****", "**");
|
|
512
|
+
const match = line.match(/^\*{4}([^*\s][^*]*?)(\*{4})?(\s*)$/);
|
|
513
|
+
if (!match) return line;
|
|
514
|
+
return `**${match[1]}${match[2] ? "**" : ""}${match[3]}`;
|
|
515
|
+
}
|
|
516
|
+
function joinStrandedEmphasis(lines) {
|
|
517
|
+
const out = [];
|
|
518
|
+
let fence = null;
|
|
519
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
520
|
+
const line = collapseEmptyBoldPrefix(lines[index]);
|
|
521
|
+
const marker = line.match(/^\s{0,3}(`{3,}|~{3,})/)?.[1];
|
|
522
|
+
if (fence) {
|
|
523
|
+
if (marker && marker[0] === fence[0] && marker.length >= fence.length) fence = null;
|
|
524
|
+
out.push(line);
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
if (marker) {
|
|
528
|
+
fence = marker;
|
|
529
|
+
out.push(line);
|
|
530
|
+
continue;
|
|
531
|
+
}
|
|
532
|
+
const run = line.match(/^(\*{2,3})\s*$/)?.[1];
|
|
533
|
+
if (run) {
|
|
534
|
+
const prev = out[out.length - 1];
|
|
535
|
+
if (prev !== void 0 && strandedOpenerLine(prev, run)) {
|
|
536
|
+
out[out.length - 1] = prev.replace(/\s+$/, "") + run;
|
|
537
|
+
continue;
|
|
538
|
+
}
|
|
539
|
+
const next = lines[index + 1];
|
|
540
|
+
if (next !== void 0 && strandedCloserLine(next, run)) {
|
|
541
|
+
out.push(run + next.replace(/^\s+/, ""));
|
|
542
|
+
index += 1;
|
|
543
|
+
continue;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
out.push(line);
|
|
547
|
+
}
|
|
548
|
+
return out;
|
|
549
|
+
}
|
|
550
|
+
function strandedOpenerLine(line, run) {
|
|
551
|
+
if (!line.startsWith(run) || line.length <= run.length || line[run.length] === "*") return false;
|
|
552
|
+
return !line.slice(run.length).includes("*");
|
|
553
|
+
}
|
|
554
|
+
function strandedCloserLine(line, run) {
|
|
555
|
+
if (!line.endsWith(run) || line.length <= run.length || line[line.length - run.length - 1] === "*") return false;
|
|
556
|
+
const body = line.slice(0, -run.length);
|
|
557
|
+
return !!body.trim() && !body.includes("*");
|
|
558
|
+
}
|
|
559
|
+
var LINK_ITEM_RE = String.raw`(?:[·•●▪][ \t]*)?\[[^\]]*\]\([^)\s]+(?:\s+"[^"]*")?\)`;
|
|
560
|
+
var LINK_ONLY_LINE_RE = new RegExp(String.raw`^\s*${LINK_ITEM_RE}\s*$`);
|
|
561
|
+
var BOLD_OPEN_LINK_RE = new RegExp(String.raw`^\s*\*\*(${LINK_ITEM_RE})\s*$`);
|
|
562
|
+
var BOLD_CLOSE_LINK_RE = new RegExp(String.raw`^\s*(${LINK_ITEM_RE})\*\*\s*$`);
|
|
563
|
+
function unwrapSpanningLinkListBold(lines) {
|
|
564
|
+
const out = [];
|
|
565
|
+
let fence = null;
|
|
566
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
567
|
+
const line = lines[index];
|
|
568
|
+
const marker = line.match(/^\s{0,3}(`{3,}|~{3,})/)?.[1];
|
|
569
|
+
if (fence) {
|
|
570
|
+
if (marker && marker[0] === fence[0] && marker.length >= fence.length) fence = null;
|
|
571
|
+
out.push(line);
|
|
572
|
+
continue;
|
|
573
|
+
}
|
|
574
|
+
if (marker) {
|
|
575
|
+
fence = marker;
|
|
576
|
+
out.push(line);
|
|
577
|
+
continue;
|
|
578
|
+
}
|
|
579
|
+
const open = BOLD_OPEN_LINK_RE.exec(line);
|
|
580
|
+
if (open) {
|
|
581
|
+
let end = -1;
|
|
582
|
+
for (let look = index + 1; look < lines.length; look += 1) {
|
|
583
|
+
const candidate = lines[look];
|
|
584
|
+
if (!candidate.trim()) continue;
|
|
585
|
+
if (BOLD_CLOSE_LINK_RE.test(candidate)) {
|
|
586
|
+
end = look;
|
|
587
|
+
break;
|
|
588
|
+
}
|
|
589
|
+
if (!LINK_ONLY_LINE_RE.test(candidate)) break;
|
|
590
|
+
}
|
|
591
|
+
if (end >= 0) {
|
|
592
|
+
out.push(open[1]);
|
|
593
|
+
for (let look = index + 1; look < end; look += 1) out.push(lines[look]);
|
|
594
|
+
out.push(BOLD_CLOSE_LINK_RE.exec(lines[end])[1]);
|
|
595
|
+
index = end;
|
|
596
|
+
continue;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
out.push(line);
|
|
600
|
+
}
|
|
601
|
+
return out;
|
|
602
|
+
}
|
|
603
|
+
var SPAN_TEXT_RE = /^(?![ \t]*(?:[#>|`~<]|[-+][ \t]|\d+[.)][ \t]|!\[|\[!\[))[ \t]*[^\s*][^*]*$/;
|
|
604
|
+
var SPAN_OPEN_RE = /^([ \t]*)\*\*(?![\s*])([^*]*?)\s*$/;
|
|
605
|
+
var SPAN_CLOSE_RE = /^([ \t]*)((?:[^*\s][^*]*?)?[^*\s])\*\*\s*$|^[ \t]*\*\*[ \t]*$/;
|
|
606
|
+
var SPAN_PASS_RE = /^[ \t]*> 🎬 视频/;
|
|
607
|
+
var SPAN_MAX_LINES = 12;
|
|
608
|
+
function splitParagraphSpanningBold(lines) {
|
|
609
|
+
const out = [];
|
|
610
|
+
let fence = null;
|
|
611
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
612
|
+
const line = lines[index];
|
|
613
|
+
const marker = line.match(/^\s{0,3}(`{3,}|~{3,})/)?.[1];
|
|
614
|
+
if (fence) {
|
|
615
|
+
if (marker && marker[0] === fence[0] && marker.length >= fence.length) fence = null;
|
|
616
|
+
out.push(line);
|
|
617
|
+
continue;
|
|
618
|
+
}
|
|
619
|
+
if (marker) {
|
|
620
|
+
fence = marker;
|
|
621
|
+
out.push(line);
|
|
622
|
+
continue;
|
|
623
|
+
}
|
|
624
|
+
const open = SPAN_OPEN_RE.exec(line);
|
|
625
|
+
const end = open && SPAN_TEXT_RE.test(open[2]) ? findSpanningBoldEnd(lines, index) : -1;
|
|
626
|
+
if (end < 0) {
|
|
627
|
+
out.push(line);
|
|
628
|
+
continue;
|
|
629
|
+
}
|
|
630
|
+
out.push(`${open[1]}**${open[2].trimEnd()}**`);
|
|
631
|
+
const openAt = out.length - 1;
|
|
632
|
+
for (let look = index + 1; look < end; look += 1) {
|
|
633
|
+
const inner = lines[look];
|
|
634
|
+
out.push(inner.trim() && SPAN_TEXT_RE.test(inner) ? `${/^[ \t]*/.exec(inner)[0]}**${inner.trim()}**` : inner);
|
|
635
|
+
}
|
|
636
|
+
const endLine = lines[end];
|
|
637
|
+
const mid = spanningMidClose(endLine);
|
|
638
|
+
if (mid) {
|
|
639
|
+
const before = mid[2];
|
|
640
|
+
const after = mid[3] ?? "";
|
|
641
|
+
if (/^[\s\p{P}\p{S}]+$/u.test(before)) {
|
|
642
|
+
out[openAt] = out[openAt].replace(/\*\*\s*$/, `${before.trim()}**`);
|
|
643
|
+
out.push(`${mid[1]}${after}`.replace(/\s+$/, ""));
|
|
644
|
+
} else {
|
|
645
|
+
out.push(`${mid[1]}**${before}**${after}`);
|
|
646
|
+
}
|
|
647
|
+
if (!out[out.length - 1].trim()) out.pop();
|
|
648
|
+
} else {
|
|
649
|
+
const close = SPAN_CLOSE_RE.exec(endLine);
|
|
650
|
+
if (close[2] && STANDALONE_IMAGE_LINE_RE.test(close[2].trim())) out.push(`${close[1]}${close[2]}`);
|
|
651
|
+
else if (close[2] && /^[\s\p{P}\p{S}]+$/u.test(close[2])) {
|
|
652
|
+
out[openAt] = out[openAt].replace(/\*\*\s*$/, `${close[2]}**`);
|
|
653
|
+
while (out.length && !out[out.length - 1].trim()) out.pop();
|
|
654
|
+
} else if (close[2]) out.push(`${close[1]}**${close[2]}**`);
|
|
655
|
+
else while (out.length && !out[out.length - 1].trim()) out.pop();
|
|
656
|
+
}
|
|
657
|
+
index = end;
|
|
658
|
+
}
|
|
659
|
+
return out;
|
|
660
|
+
}
|
|
661
|
+
function findSpanningBoldEnd(lines, start) {
|
|
662
|
+
let blank = false;
|
|
663
|
+
let count = 0;
|
|
664
|
+
let sawImage = false;
|
|
665
|
+
for (let look = start + 1; look < lines.length && count < SPAN_MAX_LINES; look += 1) {
|
|
666
|
+
const candidate = lines[look];
|
|
667
|
+
if (!candidate.trim()) {
|
|
668
|
+
blank = true;
|
|
669
|
+
continue;
|
|
670
|
+
}
|
|
671
|
+
count += 1;
|
|
672
|
+
const close = SPAN_CLOSE_RE.exec(candidate);
|
|
673
|
+
if (close && (!close[2] || SPAN_TEXT_RE.test(close[2]))) return blank ? look : -1;
|
|
674
|
+
if (close?.[2] && blank && STANDALONE_IMAGE_LINE_RE.test(close[2].trim())) return look;
|
|
675
|
+
if (blank && !sawImage && spanningMidClose(candidate)) return look;
|
|
676
|
+
if (STANDALONE_IMAGE_LINE_RE.test(candidate.trim())) {
|
|
677
|
+
sawImage = true;
|
|
678
|
+
continue;
|
|
679
|
+
}
|
|
680
|
+
if (SPAN_TEXT_RE.test(candidate) || SPAN_PASS_RE.test(candidate)) continue;
|
|
681
|
+
return -1;
|
|
682
|
+
}
|
|
683
|
+
return -1;
|
|
684
|
+
}
|
|
685
|
+
function spanningMidClose(line) {
|
|
686
|
+
if ((line.match(/\*\*/g) ?? []).length !== 1) return null;
|
|
687
|
+
const match = /^([ \t]*)([^*]*?[^\s*])\*\*(.+)$/.exec(line);
|
|
688
|
+
if (!match?.[2] || !SPAN_TEXT_RE.test(match[2])) return null;
|
|
689
|
+
return match;
|
|
690
|
+
}
|
|
691
|
+
var ITALIC_SECTION_MARK_RE = /^([ \t]*)\*([ \t]*\\?- \d+ -[ \t]*)$/;
|
|
692
|
+
var ITALIC_SPAN_FIND_MAX = 40;
|
|
693
|
+
function unglueTrailingBoldItalicOpen(line) {
|
|
694
|
+
const match = /^([ \t]*)(\*\*(?!\*)(?:[^*]|\*(?!\*))+?\*\*)\*[ \t]*$/.exec(line);
|
|
695
|
+
if (!match) return line;
|
|
696
|
+
const bold = match[2] ?? "";
|
|
697
|
+
const runs = bold.match(/\*+/g) ?? [];
|
|
698
|
+
if (runs.some((run) => run.length !== 2) || runs.length % 2 === 1) return line;
|
|
699
|
+
return `${match[1]}${bold}`;
|
|
700
|
+
}
|
|
701
|
+
function italicSpanOpen(line) {
|
|
702
|
+
if (/^[ \t]*\*[ \t]+/.test(line)) return null;
|
|
703
|
+
const match = /^([ \t]*)\*(?!\*)(.*)$/.exec(line);
|
|
704
|
+
if (!match?.[2]?.trim() || match[2].includes("*")) return null;
|
|
705
|
+
return match;
|
|
706
|
+
}
|
|
707
|
+
function italicSpanClose(line) {
|
|
708
|
+
if ((line.match(/(?<!\\)\*/g) ?? []).length !== 1) return null;
|
|
709
|
+
const match = /^([ \t]*)(.*[^\s*])\*[ \t]*$/.exec(line);
|
|
710
|
+
if (!match?.[2] || match[2].includes("*")) return null;
|
|
711
|
+
return match;
|
|
712
|
+
}
|
|
713
|
+
function isItalicSpanImageLine(line) {
|
|
714
|
+
return STANDALONE_IMAGE_LINE_RE.test(line.trim());
|
|
715
|
+
}
|
|
716
|
+
function findSpanningItalicEnd(lines, start, maxNonBlank) {
|
|
717
|
+
let blank = false;
|
|
718
|
+
let count = 0;
|
|
719
|
+
for (let look = start + 1; look < lines.length; look += 1) {
|
|
720
|
+
const candidate = lines[look];
|
|
721
|
+
if (!candidate.trim()) {
|
|
722
|
+
blank = true;
|
|
723
|
+
continue;
|
|
724
|
+
}
|
|
725
|
+
count += 1;
|
|
726
|
+
if (count > maxNonBlank) return -1;
|
|
727
|
+
if (italicSpanClose(candidate) && blank) return look;
|
|
728
|
+
if (isItalicSpanImageLine(candidate)) continue;
|
|
729
|
+
if (italicSpanOpen(candidate) || candidate.includes("*") || /^(?!\s*$)\s{0,3}(#{1,6}\s|[>|`~]|[-+][ \t]|\d+[.)][ \t])/.test(candidate)) {
|
|
730
|
+
return -1;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
return -1;
|
|
734
|
+
}
|
|
735
|
+
function splitOrCloseParagraphSpanningItalic(lines) {
|
|
736
|
+
const src = lines.map((line) => unglueTrailingBoldItalicOpen(line));
|
|
737
|
+
const out = [];
|
|
738
|
+
let fence = null;
|
|
739
|
+
for (let index = 0; index < src.length; index += 1) {
|
|
740
|
+
const line = src[index];
|
|
741
|
+
const marker = line.match(/^\s{0,3}(`{3,}|~{3,})/)?.[1];
|
|
742
|
+
if (fence) {
|
|
743
|
+
if (marker && marker[0] === fence[0] && marker.length >= fence.length) fence = null;
|
|
744
|
+
out.push(line);
|
|
745
|
+
continue;
|
|
746
|
+
}
|
|
747
|
+
if (marker) {
|
|
748
|
+
fence = marker;
|
|
749
|
+
out.push(line);
|
|
750
|
+
continue;
|
|
751
|
+
}
|
|
752
|
+
const open = italicSpanOpen(line);
|
|
753
|
+
const end = open ? findSpanningItalicEnd(src, index, ITALIC_SPAN_FIND_MAX) : -1;
|
|
754
|
+
if (open && end >= 0) {
|
|
755
|
+
const nonBlank = src.slice(index, end + 1).filter((entry) => entry.trim()).length;
|
|
756
|
+
out.push(`${open[1]}*${open[2].trimEnd()}*`);
|
|
757
|
+
if (nonBlank <= SPAN_MAX_LINES + 1) {
|
|
758
|
+
for (let look = index + 1; look < end; look += 1) {
|
|
759
|
+
const inner = src[look];
|
|
760
|
+
out.push(inner.trim() && !isItalicSpanImageLine(inner) && !italicSpanOpen(inner) ? `${/^[ \t]*/.exec(inner)[0]}*${inner.trim()}*` : inner);
|
|
761
|
+
}
|
|
762
|
+
const close = italicSpanClose(src[end]);
|
|
763
|
+
if (close?.[2]?.trim()) out.push(`${close[1]}*${close[2]}*`);
|
|
764
|
+
} else {
|
|
765
|
+
for (let look = index + 1; look < end; look += 1) out.push(src[look]);
|
|
766
|
+
const close = italicSpanClose(src[end]);
|
|
767
|
+
out.push(close ? `${close[1]}${close[2]}` : src[end]);
|
|
768
|
+
}
|
|
769
|
+
index = end;
|
|
770
|
+
continue;
|
|
771
|
+
}
|
|
772
|
+
if (open && ITALIC_SECTION_MARK_RE.test(line)) {
|
|
773
|
+
out.push(`${open[1]}*${open[2].trimEnd()}*`);
|
|
774
|
+
continue;
|
|
775
|
+
}
|
|
776
|
+
out.push(line);
|
|
777
|
+
}
|
|
778
|
+
return out;
|
|
779
|
+
}
|
|
780
|
+
var BOLD_BROKEN_BY_IMAGE_OPEN_RE = /^([ \t]*)\*\*(?![\s*])([^*]+?)\s*$/;
|
|
781
|
+
var BOLD_BROKEN_BY_IMAGE_CLOSE_RE = /^([ \t]*)([^*]*?[^*\s])\*\*(.*)$/;
|
|
782
|
+
var CREDIT_ORPHAN_CLOSE_RE = /^(?:来源|文章来源|资料来源|内容来源|图片(?:来源)?|题图|配图|封面|作者|文|编辑|责编|责任编辑|校对|审核|审校|排版|美编|制作|主播|编辑排版|监制|出品|策划|撰文|撰稿|校稿|摄影|翻译|编译|整理|参考(?:资料|链接|文献)?|原文)\s*[||:://][^\n*]+\*\*\s*$/i;
|
|
783
|
+
function dropStrandedParagraphClosers(lines) {
|
|
784
|
+
const out = [...lines];
|
|
785
|
+
let fence = null;
|
|
786
|
+
for (let index = 0; index < out.length; index += 1) {
|
|
787
|
+
const line = out[index];
|
|
788
|
+
const marker = line.match(/^\s{0,3}(`{3,}|~{3,})/)?.[1];
|
|
789
|
+
if (fence) {
|
|
790
|
+
if (marker && marker[0] === fence[0] && marker.length >= fence.length) fence = null;
|
|
791
|
+
continue;
|
|
792
|
+
}
|
|
793
|
+
if (marker) {
|
|
794
|
+
fence = marker;
|
|
795
|
+
continue;
|
|
796
|
+
}
|
|
797
|
+
if ((line.match(/\*\*/g) ?? []).length !== 1) continue;
|
|
798
|
+
if (CREDIT_ORPHAN_CLOSE_RE.test(line)) {
|
|
799
|
+
out[index] = line.replace(/\*\*(\s*)$/, "$1");
|
|
800
|
+
continue;
|
|
801
|
+
}
|
|
802
|
+
if (!/^[^\n*]*[::]\*\*\s*$/.test(line)) continue;
|
|
803
|
+
if (out[index - 1]?.trim()) continue;
|
|
804
|
+
out[index] = line.replace(/\*\*\s*$/, "");
|
|
805
|
+
}
|
|
806
|
+
return out;
|
|
807
|
+
}
|
|
808
|
+
function closeBoldBrokenByBlockImages(lines) {
|
|
809
|
+
const out = [...lines];
|
|
810
|
+
let fence = null;
|
|
811
|
+
for (let index = 0; index < out.length; index += 1) {
|
|
812
|
+
const line = out[index];
|
|
813
|
+
const marker = line.match(/^\s{0,3}(`{3,}|~{3,})/)?.[1];
|
|
814
|
+
if (fence) {
|
|
815
|
+
if (marker && marker[0] === fence[0] && marker.length >= fence.length) fence = null;
|
|
816
|
+
continue;
|
|
817
|
+
}
|
|
818
|
+
if (marker) {
|
|
819
|
+
fence = marker;
|
|
820
|
+
continue;
|
|
821
|
+
}
|
|
822
|
+
const open = BOLD_BROKEN_BY_IMAGE_OPEN_RE.exec(line);
|
|
823
|
+
if (!open || !SPAN_TEXT_RE.test(open[2])) continue;
|
|
824
|
+
let blank = false;
|
|
825
|
+
let images = 0;
|
|
826
|
+
let end = -1;
|
|
827
|
+
for (let look = index + 1; look < out.length && look - index <= SPAN_MAX_LINES + 4; look += 1) {
|
|
828
|
+
const candidate = out[look];
|
|
829
|
+
if (!candidate.trim()) {
|
|
830
|
+
blank = true;
|
|
831
|
+
continue;
|
|
832
|
+
}
|
|
833
|
+
if (STANDALONE_IMAGE_LINE_RE.test(candidate.trim())) {
|
|
834
|
+
if (!blank) break;
|
|
835
|
+
images += 1;
|
|
836
|
+
continue;
|
|
837
|
+
}
|
|
838
|
+
if (!blank || images === 0) break;
|
|
839
|
+
const close2 = BOLD_BROKEN_BY_IMAGE_CLOSE_RE.exec(candidate);
|
|
840
|
+
if (!close2 || (candidate.match(/\*\*/g) ?? []).length !== 1) break;
|
|
841
|
+
end = look;
|
|
842
|
+
break;
|
|
843
|
+
}
|
|
844
|
+
if (end < 0) continue;
|
|
845
|
+
const close = BOLD_BROKEN_BY_IMAGE_CLOSE_RE.exec(out[end]);
|
|
846
|
+
const before = close[2];
|
|
847
|
+
const after = close[3] ?? "";
|
|
848
|
+
if (/^[\s\p{P}\p{S}]+$/u.test(before)) {
|
|
849
|
+
out[index] = `${open[1]}**${open[2].trimEnd()}${before.trim()}**`;
|
|
850
|
+
out[end] = `${close[1]}${after}`.replace(/\s+$/, "");
|
|
851
|
+
} else {
|
|
852
|
+
out[index] = `${open[1]}**${open[2].trimEnd()}**`;
|
|
853
|
+
out[end] = `${close[1]}${before}${after}`.replace(/\s+$/, "");
|
|
854
|
+
}
|
|
855
|
+
if (!out[end].trim()) out[end] = "";
|
|
856
|
+
}
|
|
857
|
+
return out;
|
|
858
|
+
}
|
|
859
|
+
var ORPHAN_STANDALONE_BOLD_RE = /^([ \t]*)\*\*(?![\s*])([^*]+?)\s*$/;
|
|
860
|
+
var ORPHAN_STANDALONE_BOLD_MAX = 40;
|
|
861
|
+
function closeOrphanStandaloneBold(lines) {
|
|
862
|
+
const out = [...lines];
|
|
863
|
+
let fence = null;
|
|
864
|
+
for (let index = 0; index < out.length; index += 1) {
|
|
865
|
+
const line = out[index];
|
|
866
|
+
const marker = line.match(/^\s{0,3}(`{3,}|~{3,})/)?.[1];
|
|
867
|
+
if (fence) {
|
|
868
|
+
if (marker && marker[0] === fence[0] && marker.length >= fence.length) fence = null;
|
|
869
|
+
continue;
|
|
870
|
+
}
|
|
871
|
+
if (marker) {
|
|
872
|
+
fence = marker;
|
|
873
|
+
continue;
|
|
874
|
+
}
|
|
875
|
+
const open = ORPHAN_STANDALONE_BOLD_RE.exec(line);
|
|
876
|
+
if (!open || [...open[2]].length > ORPHAN_STANDALONE_BOLD_MAX || !SPAN_TEXT_RE.test(open[2])) continue;
|
|
877
|
+
if (out[index - 1]?.trim() || out[index + 1]?.trim()) continue;
|
|
878
|
+
const closer = out.findIndex((later, at) => at > index && (later.match(/\*\*/g) ?? []).length % 2 === 1);
|
|
879
|
+
if (closer < 0) continue;
|
|
880
|
+
const close = /^(.*[^*\s])\*\*\s*$/.exec(out[closer]);
|
|
881
|
+
if (!close || closer - index <= SPAN_MAX_LINES * 2) continue;
|
|
882
|
+
out[closer] = close[1];
|
|
883
|
+
out[index] = `${open[1]}**${open[2]}**`;
|
|
884
|
+
}
|
|
885
|
+
return out;
|
|
886
|
+
}
|
|
887
|
+
var BOLD_STRADDLE_LINK_RE = /\[(\*\*|__)([^\]*\n]+)\]\(([^)\s]+)((?:\s+"[^"]*")?)\)\1/g;
|
|
888
|
+
var BOLD_CLOSE_INSIDE_HREF_RE = /\[(\*\*|__)([^\]*\n]+)\]\(([^)\s]*?)\1((?:\s+"[^"]*")?)\)/g;
|
|
889
|
+
function fixBoldStraddlingLinks(line) {
|
|
890
|
+
if (!line.includes("[**") && !line.includes("[__")) return line;
|
|
891
|
+
return line.replace(BOLD_CLOSE_INSIDE_HREF_RE, "[$1$2$1]($3)$4").replace(BOLD_STRADDLE_LINK_RE, "[$1$2$1]($3)$4");
|
|
892
|
+
}
|
|
893
|
+
function unwrapEscapedCitationMarkers(line) {
|
|
894
|
+
return line.replace(/\\\*\*\[(\d+(?:\s*[-–—,,]\s*\d+)*)\\?\](?:\*\*)?/g, "[$1]").replace(/\\\[(\d+(?:\s*[-–—,,]\s*\d+)*)\\\]/g, "[$1]");
|
|
895
|
+
}
|
|
896
|
+
var ORPHAN_CREDIT_BOLD_RE = /^\*\*((?:来源|文章来源|资料来源|内容来源|图片(?:来源)?|题图|配图|封面|作者|文|编辑|责编|责任编辑|校对|审核|审校|排版|美编|制作|主播|编辑排版|监制|出品|策划|撰文|摄影|翻译|编译|整理|参考(?:资料|链接|文献)?|原文)\s*[||:://].+)$/i;
|
|
897
|
+
function closeOrphanCreditBold(line) {
|
|
898
|
+
const trimmedEnd = line.replace(/\s+$/, "");
|
|
899
|
+
const trailing = line.slice(trimmedEnd.length);
|
|
900
|
+
const match = ORPHAN_CREDIT_BOLD_RE.exec(trimmedEnd);
|
|
901
|
+
if (!match) return line;
|
|
902
|
+
const body = match[1];
|
|
903
|
+
if (body.includes("*")) return line;
|
|
904
|
+
return `**${body}**${trailing}`;
|
|
905
|
+
}
|
|
906
|
+
function terminateBareUrlsBeforeCjkOrEmphasis(text) {
|
|
907
|
+
return text.replace(
|
|
908
|
+
/(?<!<)(https?:\/\/[A-Za-z0-9][-A-Za-z0-9._~:/?#@!$&'()+,;=%[\]]*[A-Za-z0-9_~/#&=%])(?=[\u3000-\u303f\uff00-\uffef*])/g,
|
|
909
|
+
"<$1>"
|
|
910
|
+
);
|
|
911
|
+
}
|
|
912
|
+
function normalizeLine(input) {
|
|
913
|
+
if (!input.trim()) return input;
|
|
914
|
+
const line = dropEmptyAndPunctuationBold(detachBoldFromImages(unwrapEscapedCitationMarkers(closeOrphanCreditBold(input))));
|
|
915
|
+
const isTableRow = /^\s*\|/.test(line);
|
|
916
|
+
const withoutEmptyLinks = /\[[ \t\u00a0]*\]\(/.test(line) ? line.replace(
|
|
917
|
+
/(?<![!\]\\])\[[ \t\u00a0]*\]\(([^)\s]+)(?:\s+"([^"]*)")?\)/g,
|
|
918
|
+
(_match, url, title) => title?.trim() ? `[${title.trim()}](${url})` : ""
|
|
919
|
+
) : line;
|
|
920
|
+
let result = mapOutsideCode(
|
|
921
|
+
unwrapRedirectLinksInLine(withoutEmptyLinks),
|
|
922
|
+
(text) => text.replace(/(?<=[\p{L}\p{N}])\\_(?=[\p{L}\p{N}])/gu, "_").replace(
|
|
923
|
+
/(?<=(?:^|[^\\])(?:\\\\)*)<(\/?)([A-Za-z][\w-]*)(?=[\s/>])([^<>]*)>/g,
|
|
924
|
+
(match, _slash, name) => ALLOWED_INLINE_HTML.has(name.toLowerCase()) ? match : `\\${match}`
|
|
925
|
+
)
|
|
926
|
+
);
|
|
927
|
+
result = mapOutsideCode(result, terminateBareUrlsBeforeCjkOrEmphasis);
|
|
928
|
+
result = result.replace(/^(\s{0,3}#{1,6}\s+|\s*(?:>\s*)*(?:\*\*|\*|__)\s*)(\d+)\\\./, "$1$2.");
|
|
929
|
+
result = result.replace(
|
|
930
|
+
new RegExp("^(\\s*(?:>\\s*)*(?:[\u2022\xB7\u25AA\u25E6\u25CF\u25CB\u25A0\u25A1\u25BA\u25B6\u27A4\u2605\u2606\u2B50\u2192]|\\p{Extended_Pictographic})(?:\\p{Emoji_Modifier}|\\uFE0F|\\u20E3)*\\s*(?:\\*\\*|\\*|__)?\\s*)(\\d+)\\\\\\.", "u"),
|
|
931
|
+
"$1$2."
|
|
932
|
+
);
|
|
933
|
+
result = mapOutsideCode(result, (text) => text.replace(/(\S\s+(?:\*\*|__))(\d+)\\\.(?=\s)/g, "$1$2."));
|
|
934
|
+
result = mapOutsideCode(result, (text) => text.replace(/(?<=[^\s\d*_>\\])(\d+)\\\./gu, "$1."));
|
|
935
|
+
if (!isTableRow)
|
|
936
|
+
result = result.replace(
|
|
937
|
+
/^(\s*(?:>\s*)*(?:(?:[-*+]|\d+[.)])\s+)?(?:#{1,6}\s+)?)([\s\S]*)$/,
|
|
938
|
+
(_m, prefix, rest) => prefix + mapOutsideCode(rest, (text) => text.replace(/(?<=\S\s+)(\d+)\\\./g, "$1."))
|
|
939
|
+
);
|
|
940
|
+
if (isTableRow) result = mapOutsideCode(result, (text) => text.replace(/((?:^|[^\\])\|[ \t]*(?:\*\*|__)?[ \t]*)(\d+)\\\./g, "$1$2."));
|
|
941
|
+
result = result.replace(
|
|
942
|
+
/^(\s*(?:>\s*)*(?:(?:[-*+]|\d+[.)])\s+)?(?:\\\*\s+)?)([\s\S]*)$/,
|
|
943
|
+
(_m, prefix, rest) => prefix + mapOutsideCode(rest, (text) => text.replace(/(?<=\s|^)\\\*(?=\s|$)/g, (match, offset) => offset === 0 && !prefix ? match : "*"))
|
|
944
|
+
);
|
|
945
|
+
result = fixEmphasisFlanking(result);
|
|
946
|
+
result = fixBoldStraddlingLinks(result);
|
|
947
|
+
result = result.replace(MARKUP_CLOSE_BEFORE_PUNCT, "$1$2").replace(PUNCT_BEFORE_MARKUP_OPEN, "$1$2");
|
|
948
|
+
if (!isTableRow) result = closeBoldBeforeEdgeImagesOnce(result);
|
|
949
|
+
if (!isTableRow) result = splitListItemTrailingClipImages(result);
|
|
950
|
+
const beforeQuoteSplit = result;
|
|
951
|
+
if (!isTableRow) result = splitBlockquoteTrailingClipImages(result);
|
|
952
|
+
if (!isTableRow && result === beforeQuoteSplit && !/^\s*(?:[-*+]|\d+[.)]|>|#{1,6})\s/.test(result)) result = separateImages(result);
|
|
953
|
+
return result.trim() ? result : "";
|
|
954
|
+
}
|
|
955
|
+
var IMAGE_SPLIT_RE = new RegExp(`(${IMAGE_UNIT_RE})`, "g");
|
|
956
|
+
function detachBoldFromImages(line) {
|
|
957
|
+
if (!canCloseBoldBeforeEdgeImages(line)) return line;
|
|
958
|
+
const edge = closeBoldBeforeEdgeImages(line);
|
|
959
|
+
if (edge !== line) return edge;
|
|
960
|
+
const parts = line.split(IMAGE_SPLIT_RE);
|
|
961
|
+
if (parts.length < 3) return line;
|
|
962
|
+
const last = parts.length - 1;
|
|
963
|
+
let touched = false;
|
|
964
|
+
let hasText = false;
|
|
965
|
+
const out = [...parts];
|
|
966
|
+
for (let index = 0; index <= last; index += 2) {
|
|
967
|
+
let text = parts[index] ?? "";
|
|
968
|
+
const lead = index > 0 ? /^\*+/.exec(text)?.[0] ?? "" : "";
|
|
969
|
+
const trail = index < last ? /\*+$/.exec(text.slice(lead.length))?.[0] ?? "" : "";
|
|
970
|
+
if (lead.length % 2 === 1 || trail.length % 2 === 1) return line;
|
|
971
|
+
if (lead || trail) touched = true;
|
|
972
|
+
text = text.slice(lead.length, text.length - trail.length);
|
|
973
|
+
if (/^[\s*]*$/.test(text)) {
|
|
974
|
+
out[index] = text.replace(/\*/g, "");
|
|
975
|
+
continue;
|
|
976
|
+
}
|
|
977
|
+
const runs = text.match(/\*+/g) ?? [];
|
|
978
|
+
if (runs.some((run) => run.length !== 2 && run.length !== 4)) return line;
|
|
979
|
+
const open = runs.reduce((sum, run) => sum + run.length / 2, 0) % 2 === 1;
|
|
980
|
+
const leadOpens = lead.length / 2 % 2 === 1;
|
|
981
|
+
const trailCloses = trail.length / 2 % 2 === 1;
|
|
982
|
+
if (open) {
|
|
983
|
+
if (trail && (!lead || trailCloses && !leadOpens)) text = text.replace(/(\s*)$/, "**$1");
|
|
984
|
+
else if (lead && (!trail || leadOpens && !trailCloses)) text = text.replace(/^(\s*)/, "$1**");
|
|
985
|
+
else return line;
|
|
986
|
+
} else if (leadOpens && trailCloses) {
|
|
987
|
+
text = text.replace(/^(\s*)([\s\S]*?)(\s*)$/, "$1**$2**$3");
|
|
988
|
+
}
|
|
989
|
+
if (text.trim()) hasText = true;
|
|
990
|
+
out[index] = text;
|
|
991
|
+
}
|
|
992
|
+
return touched && hasText ? out.join("") : line;
|
|
993
|
+
}
|
|
994
|
+
var HSPACE = String.raw`[^\S\r\n]`;
|
|
995
|
+
var EMPTY_BOLD = String.raw`(?:\*{4}${HSPACE}*)*`;
|
|
996
|
+
var BOLD_TEXT_THEN_IMAGES_RE = new RegExp(
|
|
997
|
+
String.raw`^(\s*)${EMPTY_BOLD}\*\*([^*]*?[^\s*[(][^*]*?)${HSPACE}*((?:${IMAGE_UNIT_RE}${HSPACE}*)+)\*\*${HSPACE}*${EMPTY_BOLD}$`
|
|
998
|
+
);
|
|
999
|
+
var BOLD_IMAGES_THEN_TEXT_RE = new RegExp(
|
|
1000
|
+
// The text may not start with "<!--": that is the image's own resource
|
|
1001
|
+
// comment ("** <!-- … -->**"), not text after the image.
|
|
1002
|
+
String.raw`^(\s*)${EMPTY_BOLD}\*\*${HSPACE}*((?:${IMAGE_UNIT_RE}${HSPACE}*)+?)${HSPACE}*((?!<!--)[^*\s\])][^*]*?)\*\*${HSPACE}*${EMPTY_BOLD}$`
|
|
1003
|
+
);
|
|
1004
|
+
function canCloseBoldBeforeEdgeImages(line) {
|
|
1005
|
+
return line.includes("![") && line.includes("**") && !line.includes("`") && !line.includes("\\*");
|
|
1006
|
+
}
|
|
1007
|
+
function closeBoldBeforeEdgeImagesOnce(line) {
|
|
1008
|
+
return canCloseBoldBeforeEdgeImages(line) ? closeBoldBeforeEdgeImages(line) : line;
|
|
1009
|
+
}
|
|
1010
|
+
function closeBoldBeforeEdgeImages(line) {
|
|
1011
|
+
const isBlockImages = (images) => (images.match(new RegExp(IMAGE_UNIT_RE, "g")) ?? []).every((image) => !isInlineFormulaImageAlt(markdownImageAlt(image), EDGE_FORMULA));
|
|
1012
|
+
const textFirst = BOLD_TEXT_THEN_IMAGES_RE.exec(line);
|
|
1013
|
+
if (textFirst && isBlockImages(textFirst[3] ?? "")) {
|
|
1014
|
+
return `${textFirst[1]}**${(textFirst[2] ?? "").trimEnd()}** ${(textFirst[3] ?? "").trim()}`;
|
|
1015
|
+
}
|
|
1016
|
+
const imagesFirst = BOLD_IMAGES_THEN_TEXT_RE.exec(line);
|
|
1017
|
+
if (imagesFirst && isBlockImages(imagesFirst[2] ?? "")) {
|
|
1018
|
+
return `${imagesFirst[1]}${(imagesFirst[2] ?? "").trim()} **${(imagesFirst[3] ?? "").trimEnd()}**`;
|
|
1019
|
+
}
|
|
1020
|
+
return line;
|
|
1021
|
+
}
|
|
1022
|
+
function mapOutsideCode(line, fn) {
|
|
1023
|
+
return line.split(/(`+[^`]*?`+|\]\([^)]*\)|<!--[\s\S]*?-->)/).map((part, index) => index % 2 === 1 ? part : fn(part)).join("");
|
|
1024
|
+
}
|
|
1025
|
+
var LEADING_IMAGE_RE = new RegExp(`^(${IMAGE_UNIT_RE})[ \\t]*(?=\\S)(?!<!--)`);
|
|
1026
|
+
var TRAILING_IMAGE_RE = new RegExp(`(\\S)[ \\t]*((?:${IMAGE_UNIT_RE}[ \\t]*)+)$`);
|
|
1027
|
+
var MID_CLIP_IMAGE_RE = new RegExp(
|
|
1028
|
+
String.raw`([^\s[*_]|[^\s*]\*\*)(!\[(?:\\.|[^\]\\])*\]\([^)\s]+(?:\s+"[^"]*")?\)[ \t]*<!-- \{"kind":"image"[^>]*?-->)[ \t]*(?=[^\s!\]*_])`,
|
|
1029
|
+
"g"
|
|
1030
|
+
);
|
|
1031
|
+
var EDGE_FORMULA = { singleLetter: false };
|
|
1032
|
+
function findMidClipImage(text) {
|
|
1033
|
+
MID_CLIP_IMAGE_RE.lastIndex = 0;
|
|
1034
|
+
let match;
|
|
1035
|
+
while (match = MID_CLIP_IMAGE_RE.exec(text)) {
|
|
1036
|
+
if (!isInlineFormulaImageAlt(markdownImageAlt(match[2] ?? ""))) return match;
|
|
1037
|
+
MID_CLIP_IMAGE_RE.lastIndex = match.index + 1;
|
|
1038
|
+
}
|
|
1039
|
+
return null;
|
|
1040
|
+
}
|
|
1041
|
+
var LIST_TRAILING_CLIP_IMAGE_RE = new RegExp(
|
|
1042
|
+
String.raw`^(\s*(?:[-*+]|\d{1,9}[.)])[ \t]+)(.*?\S)[ \t]*((?:!\[(?:\\.|[^\]\\])*\]\([^)\s]+(?:\s+"[^"]*")?\)[ \t]*<!-- \{"kind":"image"[^>]*?-->[ \t]*)+)$`
|
|
1043
|
+
);
|
|
1044
|
+
function splitListItemTrailingClipImages(line) {
|
|
1045
|
+
const match = LIST_TRAILING_CLIP_IMAGE_RE.exec(line);
|
|
1046
|
+
if (!match) return line;
|
|
1047
|
+
const [, prefix = "", text = "", images = ""] = match;
|
|
1048
|
+
if (!text.replace(new RegExp(IMAGE_UNIT_RE, "g"), "").trim()) return line;
|
|
1049
|
+
if (countRuns(text, 2) % 2 === 1 || countRuns(text, 3) % 2 === 1) return line;
|
|
1050
|
+
const units = images.match(new RegExp(IMAGE_UNIT_RE, "g")) ?? [];
|
|
1051
|
+
if (!units.length || units.every((image) => isInlineFormulaImageAlt(markdownImageAlt(image), EDGE_FORMULA))) return line;
|
|
1052
|
+
const continuation = prefix.replace(/[^\t]/g, " ");
|
|
1053
|
+
return `${prefix}${text}
|
|
1054
|
+
|
|
1055
|
+
${continuation}${images.trim()}`;
|
|
1056
|
+
}
|
|
1057
|
+
var QUOTE_TRAILING_CLIP_IMAGE_RE = new RegExp(
|
|
1058
|
+
String.raw`^(\s*(?:>[ \t]*)+)(.*?\S)[ \t]*((?:!\[(?:\\.|[^\]\\])*\]\([^)\s]+(?:\s+"[^"]*")?\)[ \t]*<!-- \{"kind":"image"[^>]*?-->[ \t]*)+)$`
|
|
1059
|
+
);
|
|
1060
|
+
function splitBlockquoteTrailingClipImages(line) {
|
|
1061
|
+
const match = QUOTE_TRAILING_CLIP_IMAGE_RE.exec(line);
|
|
1062
|
+
if (!match) return line;
|
|
1063
|
+
const [, prefix = "", text = "", images = ""] = match;
|
|
1064
|
+
if (!text.replace(new RegExp(IMAGE_UNIT_RE, "g"), "").trim()) return line;
|
|
1065
|
+
if (countRuns(text, 2) % 2 === 1 || countRuns(text, 3) % 2 === 1) return line;
|
|
1066
|
+
const units = images.match(new RegExp(IMAGE_UNIT_RE, "g")) ?? [];
|
|
1067
|
+
if (!units.length || units.every((image) => isInlineFormulaImageAlt(markdownImageAlt(image), EDGE_FORMULA))) return line;
|
|
1068
|
+
const bare = prefix.replace(/[ \t]+$/, "");
|
|
1069
|
+
const spaced = /[ \t]$/.test(prefix) ? prefix : `${prefix} `;
|
|
1070
|
+
return `${prefix}${text}
|
|
1071
|
+
${bare}
|
|
1072
|
+
${spaced}${images.trim()}`;
|
|
1073
|
+
}
|
|
1074
|
+
function separateImages(line, depth = 0) {
|
|
1075
|
+
const indent = /^\s*/.exec(line)?.[0] ?? "";
|
|
1076
|
+
let rest = line.slice(indent.length);
|
|
1077
|
+
const leading = [];
|
|
1078
|
+
let match;
|
|
1079
|
+
while (match = LEADING_IMAGE_RE.exec(rest)) {
|
|
1080
|
+
if (isInlineFormulaImageAlt(markdownImageAlt(match[1] ?? ""), EDGE_FORMULA)) break;
|
|
1081
|
+
leading.push(match[1] ?? "");
|
|
1082
|
+
rest = rest.slice(match[0].length);
|
|
1083
|
+
}
|
|
1084
|
+
if (leading.length && !rest.replace(new RegExp(IMAGE_UNIT_RE, "g"), "").trim()) return line;
|
|
1085
|
+
const mid = findMidClipImage(rest);
|
|
1086
|
+
if (mid && depth < 4) {
|
|
1087
|
+
const before = rest.slice(0, mid.index + mid[1].length);
|
|
1088
|
+
const after = rest.slice(mid.index + mid[0].length);
|
|
1089
|
+
const pieces = [...leading.length ? [leading.join(" ")] : [], before.trim(), mid[2].trim(), after.trim()];
|
|
1090
|
+
return pieces.map((part) => separateImages(indent + part, depth + 1)).join("\n\n");
|
|
1091
|
+
}
|
|
1092
|
+
let tail = "";
|
|
1093
|
+
const trailing = TRAILING_IMAGE_RE.exec(rest);
|
|
1094
|
+
const trailingImages = trailing ? (trailing[2] ?? "").match(new RegExp(IMAGE_UNIT_RE, "g")) ?? [] : [];
|
|
1095
|
+
if (trailing && !trailingImages.every((image) => isInlineFormulaImageAlt(markdownImageAlt(image), EDGE_FORMULA))) {
|
|
1096
|
+
tail = (trailing[2] ?? "").trim();
|
|
1097
|
+
rest = rest.slice(0, trailing.index + 1);
|
|
1098
|
+
}
|
|
1099
|
+
if (!leading.length && !tail) return line;
|
|
1100
|
+
const parts = [leading.join(" "), rest.trim(), tail].filter(Boolean).map((part) => indent + part);
|
|
1101
|
+
const result = parts.join("\n\n");
|
|
1102
|
+
const split = depth < 4 ? result.split("\n\n").map((part) => separateImages(part, depth + 1)).join("\n\n") : result;
|
|
1103
|
+
if (depth > 0) return split;
|
|
1104
|
+
return split.split("\n\n").filter((part) => !/^\s*\*{1,4}\s*$/.test(part)).join("\n\n");
|
|
1105
|
+
}
|
|
1106
|
+
var BRACKET_PAIRS = { "\uFF09": "\uFF08", "\u300B": "\u300A", "\u300D": "\u300C", "\u300F": "\u300E", "\u3011": "\u3010", "\u201D": "\u201C", "\u2019": "\u2018", ")": "(" };
|
|
1107
|
+
function fixEmphasisFlanking(line) {
|
|
1108
|
+
let text = line;
|
|
1109
|
+
text = text.replace(/(?<=\S)\*\*\*\*(?=\S)/g, "");
|
|
1110
|
+
text = mergeBoldNestedInBoldItalic(text);
|
|
1111
|
+
text = splitGluedBoldItalic(text);
|
|
1112
|
+
text = splitEmptyBoldBetweenItalics(text);
|
|
1113
|
+
text = joinAdjacentItalics(text);
|
|
1114
|
+
for (const size of [2, 1]) text = fixRunsOfSize(text, size);
|
|
1115
|
+
return text;
|
|
1116
|
+
}
|
|
1117
|
+
var BOLD_IN_BOLD_ITALIC_RE = /(?<![^\s\p{P}]|\*)\*\*\*(?=[^\s*])((?:[^*\n]*?[^\s*\\]\*{1,2}(?!\*))+[^*\n]*?[^\s*\\])\*\*\*(?![*\p{L}\p{N}])/gu;
|
|
1118
|
+
function mergeBoldNestedInBoldItalic(line) {
|
|
1119
|
+
if (!line.includes("***")) return line;
|
|
1120
|
+
const masked = maskProtected(line);
|
|
1121
|
+
let out = "";
|
|
1122
|
+
let cursor = 0;
|
|
1123
|
+
for (const match of masked.matchAll(BOLD_IN_BOLD_ITALIC_RE)) {
|
|
1124
|
+
const start = match.index;
|
|
1125
|
+
if (line.slice(start, start + match[0].length) !== match[0]) continue;
|
|
1126
|
+
const inner = match[1] ?? "";
|
|
1127
|
+
const runs = new Set(inner.match(/\*+/g)?.map((run) => run.length));
|
|
1128
|
+
if (runs.size !== 1) continue;
|
|
1129
|
+
out += `${line.slice(cursor, start)}***${inner.replace(/\*+/g, "")}***`;
|
|
1130
|
+
cursor = start + match[0].length;
|
|
1131
|
+
}
|
|
1132
|
+
return cursor ? out + line.slice(cursor) : line;
|
|
1133
|
+
}
|
|
1134
|
+
var GLUED_BOLD_ITALIC_RE = new RegExp("(?<![^\\s\\p{P}])\\*\\*(?=[^\\s*])([^*\\n]*?[^\\s*\\p{P}])(\\p{P}+)\\*\\*\\*(?=[\\p{L}\\p{N}])([^*\\n]*?[^\\s*\\\\])\\*(?![*\\p{L}\\p{N}])", "gu");
|
|
1135
|
+
function splitGluedBoldItalic(line) {
|
|
1136
|
+
if (!line.includes("***")) return line;
|
|
1137
|
+
const masked = maskProtected(line);
|
|
1138
|
+
let out = "";
|
|
1139
|
+
let cursor = 0;
|
|
1140
|
+
for (const match of masked.matchAll(GLUED_BOLD_ITALIC_RE)) {
|
|
1141
|
+
const start = match.index;
|
|
1142
|
+
if (line.slice(start, start + match[0].length) !== match[0]) continue;
|
|
1143
|
+
const [, bold = "", punct = "", italic = ""] = match;
|
|
1144
|
+
out += `${line.slice(cursor, start)}**${bold}**${punct}*${italic}*`;
|
|
1145
|
+
cursor = start + match[0].length;
|
|
1146
|
+
}
|
|
1147
|
+
return cursor ? out + line.slice(cursor) : line;
|
|
1148
|
+
}
|
|
1149
|
+
var EMPTY_BOLD_BETWEEN_ITALICS_RE = /(?<![*\\])\*(?=[^\s*])([^*]+?[^\s*\\])\*{3}(\s+)\*(?=[^\s*])([^*]+?[^\s*\\])\*(?![*])/g;
|
|
1150
|
+
function splitEmptyBoldBetweenItalics(line) {
|
|
1151
|
+
if (!line.includes("***")) return line;
|
|
1152
|
+
const masked = maskProtected(line);
|
|
1153
|
+
let out = "";
|
|
1154
|
+
let cursor = 0;
|
|
1155
|
+
for (const match of masked.matchAll(EMPTY_BOLD_BETWEEN_ITALICS_RE)) {
|
|
1156
|
+
const start = match.index;
|
|
1157
|
+
if (line.slice(start, start + match[0].length) !== match[0]) continue;
|
|
1158
|
+
const [, left = "", gap = " ", right = ""] = match;
|
|
1159
|
+
out += `${line.slice(cursor, start)}*${left}*${gap}*${right}*`;
|
|
1160
|
+
cursor = start + match[0].length;
|
|
1161
|
+
}
|
|
1162
|
+
return cursor ? out + line.slice(cursor) : line;
|
|
1163
|
+
}
|
|
1164
|
+
var ADJACENT_ITALICS_RE = /(?<![*\\A-Za-z0-9])\*(?=[^\s*])([^*]*?[^\s*\\])\*\*(?=[^\s*])([^*]*?[^\s*\\])\*(?![*A-Za-z0-9])/g;
|
|
1165
|
+
function joinAdjacentItalics(line) {
|
|
1166
|
+
let text = line;
|
|
1167
|
+
for (let pass = 0; pass < 5; pass += 1) {
|
|
1168
|
+
const masked = maskProtected(text);
|
|
1169
|
+
let changed = false;
|
|
1170
|
+
let out = "";
|
|
1171
|
+
let cursor = 0;
|
|
1172
|
+
for (const match of masked.matchAll(ADJACENT_ITALICS_RE)) {
|
|
1173
|
+
const start = match.index;
|
|
1174
|
+
const original = text.slice(start, start + match[0].length);
|
|
1175
|
+
if (original !== match[0]) continue;
|
|
1176
|
+
const [, left = "", right = ""] = match;
|
|
1177
|
+
const gap = /[A-Za-z0-9,.;:!?)]$/.test(left) && /^[A-Za-z0-9(]/.test(right) ? " " : "";
|
|
1178
|
+
out += `${text.slice(cursor, start)}*${left}${gap}${right}*`;
|
|
1179
|
+
cursor = start + match[0].length;
|
|
1180
|
+
changed = true;
|
|
1181
|
+
}
|
|
1182
|
+
if (!changed) break;
|
|
1183
|
+
text = out + text.slice(cursor);
|
|
1184
|
+
}
|
|
1185
|
+
return text;
|
|
1186
|
+
}
|
|
1187
|
+
function fixRunsOfSize(line, size) {
|
|
1188
|
+
const masked = maskProtected(line);
|
|
1189
|
+
const runs = [];
|
|
1190
|
+
const re = /\*+/g;
|
|
1191
|
+
let match;
|
|
1192
|
+
while (match = re.exec(masked)) {
|
|
1193
|
+
if (match[0].length !== size) {
|
|
1194
|
+
if (match[0].length >= 3) return line;
|
|
1195
|
+
continue;
|
|
1196
|
+
}
|
|
1197
|
+
if (match.index > 0 && masked[match.index - 1] === "\\") continue;
|
|
1198
|
+
runs.push({ length: size, start: match.index });
|
|
1199
|
+
}
|
|
1200
|
+
if (runs.length < 2 || runs.length % 2 !== 0) return line;
|
|
1201
|
+
let result = "";
|
|
1202
|
+
let cursor = 0;
|
|
1203
|
+
for (let index = 0; index < runs.length; index += 2) {
|
|
1204
|
+
const open = runs[index];
|
|
1205
|
+
const close = runs[index + 1];
|
|
1206
|
+
const inner = line.slice(open.start + size, close.start);
|
|
1207
|
+
const before = line.slice(cursor, open.start);
|
|
1208
|
+
const delimiter = "*".repeat(size);
|
|
1209
|
+
const fixed = rebalance(before, inner, line.slice(close.start + size, runs[index + 2]?.start ?? line.length), delimiter);
|
|
1210
|
+
result += fixed.before + fixed.span;
|
|
1211
|
+
cursor = close.start + size;
|
|
1212
|
+
}
|
|
1213
|
+
return result + line.slice(cursor);
|
|
1214
|
+
}
|
|
1215
|
+
function rebalance(before, inner, after, delimiter) {
|
|
1216
|
+
const prev = before.slice(-1);
|
|
1217
|
+
const next = after.slice(0, 1);
|
|
1218
|
+
let lead = "";
|
|
1219
|
+
let body = inner;
|
|
1220
|
+
let trail = "";
|
|
1221
|
+
const openerOk = () => isLeftFlanking(lead ? lead.slice(-1) : prev, body.slice(0, 1));
|
|
1222
|
+
const closerOk = () => isRightFlanking(body.slice(-1), trail ? trail.slice(0, 1) : next);
|
|
1223
|
+
while (body && !openerOk() && (SPACE_RE.test(body[0]) || PUNCT_RE.test(body[0]))) {
|
|
1224
|
+
const size = leadingEscapeLength(body);
|
|
1225
|
+
lead += body.slice(0, size);
|
|
1226
|
+
body = body.slice(size);
|
|
1227
|
+
}
|
|
1228
|
+
while (body && !closerOk() && (SPACE_RE.test(body.slice(-1)) || PUNCT_RE.test(body.slice(-1)))) {
|
|
1229
|
+
const size = trailingEscapeLength(body);
|
|
1230
|
+
trail = body.slice(-size) + trail;
|
|
1231
|
+
body = body.slice(0, -size);
|
|
1232
|
+
}
|
|
1233
|
+
const opener = BRACKET_PAIRS[trail[0] ?? ""];
|
|
1234
|
+
if (opener && body.startsWith(opener) && body.length > 1) {
|
|
1235
|
+
lead += opener;
|
|
1236
|
+
body = body.slice(1);
|
|
1237
|
+
}
|
|
1238
|
+
const closer = closingBracketFor(lead);
|
|
1239
|
+
if (!trail && closer && body.endsWith(closer) && body.length > closer.length && trailingEscapeLength(body) === closer.length) {
|
|
1240
|
+
trail = closer;
|
|
1241
|
+
body = body.slice(0, -closer.length);
|
|
1242
|
+
}
|
|
1243
|
+
if (body === inner) return { before, span: `${delimiter}${inner}${delimiter}` };
|
|
1244
|
+
if (!body.trim() || !openerOk() || !closerOk()) return { before, span: `${delimiter}${inner}${delimiter}` };
|
|
1245
|
+
return { before, span: `${lead}${delimiter}${body}${delimiter}${trail}` };
|
|
1246
|
+
}
|
|
1247
|
+
var ESCAPABLE_RE = /[!-/:-@[-`{-~]/;
|
|
1248
|
+
var CLOSING_BRACKETS = {
|
|
1249
|
+
...Object.fromEntries(Object.entries(BRACKET_PAIRS).map(([close, open]) => [open, close])),
|
|
1250
|
+
"[": "]"
|
|
1251
|
+
};
|
|
1252
|
+
function closingBracketFor(lead) {
|
|
1253
|
+
const close = CLOSING_BRACKETS[lead.slice(-1)];
|
|
1254
|
+
if (!close) return null;
|
|
1255
|
+
const escaped = lead.length >= 2 && lead.slice(-2, -1) === "\\" && trailingEscapeLength(lead) === 2;
|
|
1256
|
+
return escaped ? `\\${close}` : close;
|
|
1257
|
+
}
|
|
1258
|
+
function leadingEscapeLength(body) {
|
|
1259
|
+
return body[0] === "\\" && ESCAPABLE_RE.test(body[1] ?? "") ? 2 : 1;
|
|
1260
|
+
}
|
|
1261
|
+
function trailingEscapeLength(body) {
|
|
1262
|
+
if (!ESCAPABLE_RE.test(body.slice(-1))) return 1;
|
|
1263
|
+
let slashes = 0;
|
|
1264
|
+
for (let index = body.length - 2; index >= 0 && body[index] === "\\"; index -= 1) slashes += 1;
|
|
1265
|
+
return slashes % 2 === 1 ? 2 : 1;
|
|
1266
|
+
}
|
|
1267
|
+
function isLeftFlanking(prev, next) {
|
|
1268
|
+
if (!next || SPACE_RE.test(next)) return false;
|
|
1269
|
+
if (!PUNCT_RE.test(next)) return true;
|
|
1270
|
+
return !prev || SPACE_RE.test(prev) || PUNCT_RE.test(prev);
|
|
1271
|
+
}
|
|
1272
|
+
function isRightFlanking(prev, next) {
|
|
1273
|
+
if (!prev || SPACE_RE.test(prev)) return false;
|
|
1274
|
+
if (!PUNCT_RE.test(prev)) return true;
|
|
1275
|
+
return !next || SPACE_RE.test(next) || PUNCT_RE.test(next);
|
|
1276
|
+
}
|
|
1277
|
+
function maskProtected(line) {
|
|
1278
|
+
return line.replace(/`+[^`]*?`+|\]\([^)]*\)|<!--[\s\S]*?-->/g, (part) => " ".repeat(part.length)).replace(/^(\s*)[-*+](?=\s)/, (part) => " ".repeat(part.length));
|
|
1279
|
+
}
|
|
1280
|
+
var CJK_CHAR = "\\u3400-\\u9fff";
|
|
1281
|
+
var SPACE_BEFORE_CLOSING_RE = new RegExp(`([${CJK_CHAR}\u300B\u300D\u300F\u201D\uFF09\u3011])[ \\t\\u3000]+(?=[\uFF1A\uFF1B\uFF0C\u3002\u3001\u300B\u300D\u300F\uFF09\u3011\uFF01\uFF1F])`, "g");
|
|
1282
|
+
var SPACED_LABEL_RE = new RegExp(`^[${CJK_CHAR}](?:[ \\t\\u3000]+[${CJK_CHAR}])+[ \\t]*[\uFF1A:]$`);
|
|
1283
|
+
var LABEL_LINE_RE = /^(?:[“"「][^”"」]{1,8}[”"」])?(?:基本案情|案情|案情简介|法院裁判|裁判要旨|裁判理由|裁判结果|相关法条|争议焦点|编者后记|编者按|关键词|典型意义)[::]$/;
|
|
1284
|
+
var LEGAL_LEAD_RE = /^(裁判要旨|基本案情|裁判理由|裁判结果|相关法条|争议焦点|关键词)([::])(?=\S)/;
|
|
1285
|
+
function fixCjkLabelLayout(lines) {
|
|
1286
|
+
const out = [...lines];
|
|
1287
|
+
let fence = null;
|
|
1288
|
+
const orderedStarts = [];
|
|
1289
|
+
for (let index = 0; index < out.length; index += 1) {
|
|
1290
|
+
const line = out[index];
|
|
1291
|
+
const marker = line.match(/^\s{0,3}(`{3,}|~{3,})/)?.[1];
|
|
1292
|
+
if (fence) {
|
|
1293
|
+
if (marker && marker[0] === fence[0] && marker.length >= fence.length) fence = null;
|
|
1294
|
+
continue;
|
|
1295
|
+
}
|
|
1296
|
+
if (marker) {
|
|
1297
|
+
fence = marker;
|
|
1298
|
+
continue;
|
|
1299
|
+
}
|
|
1300
|
+
if (/^\s{4,}|^\s*(?:[>|]|<!--)/.test(line)) continue;
|
|
1301
|
+
let text = line.replace(SPACE_BEFORE_CLOSING_RE, "$1");
|
|
1302
|
+
const prevBlank = !out[index - 1]?.trim();
|
|
1303
|
+
const nextBlank = !out[index + 1]?.trim();
|
|
1304
|
+
let label = false;
|
|
1305
|
+
if (prevBlank && nextBlank && SPACED_LABEL_RE.test(text.trim())) {
|
|
1306
|
+
text = text.replace(/[ \t\u3000]+/g, "").trim();
|
|
1307
|
+
label = true;
|
|
1308
|
+
}
|
|
1309
|
+
if (prevBlank && nextBlank && (label || LABEL_LINE_RE.test(text.trim()))) text = `**${text.trim()}**`;
|
|
1310
|
+
else if (prevBlank) text = text.replace(LEGAL_LEAD_RE, "**$1$2**");
|
|
1311
|
+
const ordered = prevBlank ? text.match(/^(\d{1,3})(\\?)\.\s/) : null;
|
|
1312
|
+
if (ordered) orderedStarts.push({ escaped: ordered[2] === "\\", index, n: Number(ordered[1]) });
|
|
1313
|
+
out[index] = text;
|
|
1314
|
+
}
|
|
1315
|
+
for (let k = 0; k + 1 < orderedStarts.length; k += 1) {
|
|
1316
|
+
const current = orderedStarts[k];
|
|
1317
|
+
const next = orderedStarts[k + 1];
|
|
1318
|
+
if (current.escaped && next.n === current.n + 1 && !next.escaped)
|
|
1319
|
+
out[current.index] = out[current.index].replace(/^(\d{1,3})\\\./, "$1.");
|
|
1320
|
+
}
|
|
1321
|
+
return out;
|
|
1322
|
+
}
|
|
1323
|
+
var DISCOURSE_LIGHTBOX_MD_RE = /^\[[ \t]*\n\s*\n(!\[[^\]\n]*\]\([^)\n]+\)(?:[ \t]*<!--[^\n]*?-->)?)[ \t]*\n\s*\n(?:[^\n]*?\d+\s*[×x]\s*\d+(?:\s+[\d.]+\s*[KMG]?B)?[ \t]*\n\s*\n)?\]\((?:https?:)?\/\/[^)\s]+(?:\s+"[^"\n]*")?\)[ \t]*$/gm;
|
|
1324
|
+
function unwrapDiscourseLightboxMarkdown(markdown) {
|
|
1325
|
+
if (!markdown.includes("](")) return markdown;
|
|
1326
|
+
return markdown.replace(DISCOURSE_LIGHTBOX_MD_RE, "$1");
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
export {
|
|
1330
|
+
stripClipBoilerplate,
|
|
1331
|
+
normalizeClipMarkdownBody
|
|
1332
|
+
};
|