[{"data":1,"prerenderedAt":524},["ShallowReactive",2],{"msfe-doc:\u002Fextensions\u002Finput-rules":3,"msfe-source:recipes\u002Frules.ts":132,"mdc-5319rn-key":133},{"id":4,"title":5,"body":6,"description":116,"extension":117,"keywords":118,"locale":123,"meta":124,"navigation":125,"order":126,"path":127,"section":128,"seo":129,"stem":130,"__hash__":131},"docs\u002Fextensions\u002Finput-rules.zh-CN.md","输入与粘贴规则",{"type":7,"value":8,"toc":108},"minimark",[9,13,30,39,43,47,61,67,70,86,89,92,95],[10,11,12],"h2",{"id":12},"何时需要规则",[14,15,16,17,21,22,25,26,29],"p",{},"解析插件只解释源码。输入规则会改变用户刚输入的文本，例如将 ",[18,19,20],"code",{},"::ok "," 换成 ",[18,23,24],{},"[[done]] ","；粘贴规则可以将外部系统的 ",[18,27,28],{},"[STATUS:DONE]"," 换成自己的状态语法。转换应是应用明确启用的行为，并能撤销。",[14,31,32,33,38],{},"以下完整模块可与 ",[34,35,37],"a",{"href":36},"\u002Fextensions\u002Fcustom-node","状态节点"," 一起安装；不安装状态节点时，转换后的文本仍是普通源码。",[40,41],"msfe-recipe",{"name":42},"recipes\u002Frules",[10,44,46],{"id":45},"handler-的坐标和结果","handler 的坐标和结果",[14,48,49,52,53,56,57,60],{},[18,50,51],{},"find"," 是正则；",[18,54,55],{},"handler({ match, range, document })"," 取得原生输入已经进入文本后的匹配结果和 UTF-16 范围。返回字符串替换这一段，返回 ",[18,58,59],{},"null"," 保留输入。不要在 handler 内提交命令、发请求或改变 DOM。",[14,62,63,66],{},[18,64,65],{},"document"," 可用于必要的有界上下文判断。例子有意定义为全局字面转换，也会转换代码中的匹配字面值；业务若要求代码区域保留原样，需要增加准确的语法上下文约束并覆盖输入尚未解析完成的情况。不能只靠正则声称完成 Markdown 语义判断。",[10,68,69],{"id":69},"内置工作边界",[71,72,73,77,80,83],"ul",{},[74,75,76],"li",{},"输入规则只检查当前行末尾最多 512 个逻辑单元，且匹配必须结束于输入位置。第一条适用转换生效。",[74,78,79],{},"粘贴规则只扫描本次插入的文本，不扫描原文。超过 65,536 单元的单次插入保留原样。",[74,81,82],{},"重叠粘贴匹配不会重复应用；结果按源码位置排序。",[74,84,85],{},"多选区、只读和原生组合输入不会进入普通规则转换路径。程序化命令也不能当作键盘输入规则触发器。",[14,87,88],{},"这些是当前实现的有界策略；不要依赖超长输入自动改写。处理大型导入应走独立、可预览的导入命令。",[10,90,91],{"id":91},"验证转换没有越界",[14,93,94],{},"测试转换后的精确源码和一次撤销结果，同时覆盖：不匹配、空匹配、两个规则竞争、多个粘贴匹配、原文中存在同样字符串、长剪贴板、中文输入法及只读。返回与原匹配相同的字符串不会增加额外替换。",[14,96,97,98,102,103,107],{},"签名见 ",[34,99,101],{"href":100},"\u002Fapi\u002Fextensions","扩展 API","。只需改变显示时，选择 ",[34,104,106],{"href":105},"\u002Fextensions\u002Fmarkdown-plugins","Markdown 插件","，不要用输入规则重写已有文件。",{"title":109,"searchDepth":110,"depth":110,"links":111},"",2,[112,113,114,115],{"id":12,"depth":110,"text":12},{"id":45,"depth":110,"text":46},{"id":69,"depth":110,"text":69},{"id":91,"depth":110,"text":91},"显式转换新输入，保持组合输入、范围边界和撤销的一致性。","md",[119,120,121,122],"InputRule","PasteRule","IME","clipboard","zh-CN",{},true,5,"\u002Fextensions\u002Finput-rules","扩展开发",{"title":5,"description":116},"extensions\u002Finput-rules.zh-CN","y961kVDCIub_RL7aipOfPjC7-HN7BWAuIl1kQDPYNXA","import { Extension, InputRule, PasteRule } from \"@quirekit\u002Fmsfe-core\";\n\u002F** Explicit opt-in text normalization, separate from syntax-only rendering plugins. *\u002F\nexport const SourceRules = Extension.create({ name: \"exampleRules\",\n  \u002F** @returns A suffix rule triggered by the final space after ::ok. *\u002F\n  addInputRules() { return [new InputRule({ find: \u002F::ok $\u002Fu,\n    \u002F** @returns Exact canonical replacement. *\u002F handler() { return \"[[done]] \"; },\n  })]; },\n  \u002F** @returns A clipboard-only legacy status migration. *\u002F\n  addPasteRules() { return [new PasteRule({ find: \u002F\\[STATUS:DONE\\]\u002Fu,\n    \u002F** @returns Exact canonical status syntax. *\u002F handler() { return \"[[done]]\"; },\n  })]; },\n});\n",{"data":134,"body":135},{},{"type":136,"children":137},"root",[138,518],{"type":139,"tag":140,"props":141,"children":145},"element","pre",{"className":142,"code":143,"language":144,"meta":109,"style":109},"language-ts shiki shiki-themes github-light github-light github-dark","import { Extension, InputRule, PasteRule } from \"@quirekit\u002Fmsfe-core\";\n\u002F** Explicit opt-in text normalization, separate from syntax-only rendering plugins. *\u002F\nexport const SourceRules = Extension.create({ name: \"exampleRules\",\n  \u002F** @returns A suffix rule triggered by the final space after ::ok. *\u002F\n  addInputRules() { return [new InputRule({ find: \u002F::ok $\u002Fu,\n    \u002F** @returns Exact canonical replacement. *\u002F handler() { return \"[[done]] \"; },\n  })]; },\n  \u002F** @returns A clipboard-only legacy status migration. *\u002F\n  addPasteRules() { return [new PasteRule({ find: \u002F\\[STATUS:DONE\\]\u002Fu,\n    \u002F** @returns Exact canonical status syntax. *\u002F handler() { return \"[[done]]\"; },\n  })]; },\n});\n\n","ts",[146],{"type":139,"tag":18,"props":147,"children":148},{"__ignoreMap":109},[149,184,193,244,263,330,371,380,397,463,501,509],{"type":139,"tag":150,"props":151,"children":154},"span",{"class":152,"line":153},"line",1,[155,162,168,173,179],{"type":139,"tag":150,"props":156,"children":158},{"style":157},"--shiki-default:#D73A49;--shiki-light:#D73A49;--shiki-dark:#F97583",[159],{"type":160,"value":161},"text","import",{"type":139,"tag":150,"props":163,"children":165},{"style":164},"--shiki-default:#24292E;--shiki-light:#24292E;--shiki-dark:#E1E4E8",[166],{"type":160,"value":167}," { Extension, InputRule, PasteRule } ",{"type":139,"tag":150,"props":169,"children":170},{"style":157},[171],{"type":160,"value":172},"from",{"type":139,"tag":150,"props":174,"children":176},{"style":175},"--shiki-default:#032F62;--shiki-light:#032F62;--shiki-dark:#9ECBFF",[177],{"type":160,"value":178}," \"@quirekit\u002Fmsfe-core\"",{"type":139,"tag":150,"props":180,"children":181},{"style":164},[182],{"type":160,"value":183},";\n",{"type":139,"tag":150,"props":185,"children":186},{"class":152,"line":110},[187],{"type":139,"tag":150,"props":188,"children":190},{"style":189},"--shiki-default:#6A737D;--shiki-light:#6A737D;--shiki-dark:#6A737D",[191],{"type":160,"value":192},"\u002F** Explicit opt-in text normalization, separate from syntax-only rendering plugins. *\u002F\n",{"type":139,"tag":150,"props":194,"children":196},{"class":152,"line":195},3,[197,202,207,213,218,223,229,234,239],{"type":139,"tag":150,"props":198,"children":199},{"style":157},[200],{"type":160,"value":201},"export",{"type":139,"tag":150,"props":203,"children":204},{"style":157},[205],{"type":160,"value":206}," const",{"type":139,"tag":150,"props":208,"children":210},{"style":209},"--shiki-default:#005CC5;--shiki-light:#005CC5;--shiki-dark:#79B8FF",[211],{"type":160,"value":212}," SourceRules",{"type":139,"tag":150,"props":214,"children":215},{"style":157},[216],{"type":160,"value":217}," =",{"type":139,"tag":150,"props":219,"children":220},{"style":164},[221],{"type":160,"value":222}," Extension.",{"type":139,"tag":150,"props":224,"children":226},{"style":225},"--shiki-default:#6F42C1;--shiki-light:#6F42C1;--shiki-dark:#B392F0",[227],{"type":160,"value":228},"create",{"type":139,"tag":150,"props":230,"children":231},{"style":164},[232],{"type":160,"value":233},"({ name: ",{"type":139,"tag":150,"props":235,"children":236},{"style":175},[237],{"type":160,"value":238},"\"exampleRules\"",{"type":139,"tag":150,"props":240,"children":241},{"style":164},[242],{"type":160,"value":243},",\n",{"type":139,"tag":150,"props":245,"children":247},{"class":152,"line":246},4,[248,253,258],{"type":139,"tag":150,"props":249,"children":250},{"style":189},[251],{"type":160,"value":252},"  \u002F** ",{"type":139,"tag":150,"props":254,"children":255},{"style":157},[256],{"type":160,"value":257},"@returns",{"type":139,"tag":150,"props":259,"children":260},{"style":189},[261],{"type":160,"value":262}," A suffix rule triggered by the final space after ::ok. *\u002F\n",{"type":139,"tag":150,"props":264,"children":265},{"class":152,"line":126},[266,271,276,281,286,291,296,301,306,311,316,321,326],{"type":139,"tag":150,"props":267,"children":268},{"style":225},[269],{"type":160,"value":270},"  addInputRules",{"type":139,"tag":150,"props":272,"children":273},{"style":164},[274],{"type":160,"value":275},"() { ",{"type":139,"tag":150,"props":277,"children":278},{"style":157},[279],{"type":160,"value":280},"return",{"type":139,"tag":150,"props":282,"children":283},{"style":164},[284],{"type":160,"value":285}," [",{"type":139,"tag":150,"props":287,"children":288},{"style":157},[289],{"type":160,"value":290},"new",{"type":139,"tag":150,"props":292,"children":293},{"style":225},[294],{"type":160,"value":295}," InputRule",{"type":139,"tag":150,"props":297,"children":298},{"style":164},[299],{"type":160,"value":300},"({ find:",{"type":139,"tag":150,"props":302,"children":303},{"style":175},[304],{"type":160,"value":305}," \u002F",{"type":139,"tag":150,"props":307,"children":309},{"style":308},"--shiki-default:#032F62;--shiki-light:#032F62;--shiki-dark:#DBEDFF",[310],{"type":160,"value":20},{"type":139,"tag":150,"props":312,"children":313},{"style":157},[314],{"type":160,"value":315},"$",{"type":139,"tag":150,"props":317,"children":318},{"style":175},[319],{"type":160,"value":320},"\u002F",{"type":139,"tag":150,"props":322,"children":323},{"style":157},[324],{"type":160,"value":325},"u",{"type":139,"tag":150,"props":327,"children":328},{"style":164},[329],{"type":160,"value":243},{"type":139,"tag":150,"props":331,"children":333},{"class":152,"line":332},6,[334,339,343,348,353,357,361,366],{"type":139,"tag":150,"props":335,"children":336},{"style":189},[337],{"type":160,"value":338},"    \u002F** ",{"type":139,"tag":150,"props":340,"children":341},{"style":157},[342],{"type":160,"value":257},{"type":139,"tag":150,"props":344,"children":345},{"style":189},[346],{"type":160,"value":347}," Exact canonical replacement. *\u002F",{"type":139,"tag":150,"props":349,"children":350},{"style":225},[351],{"type":160,"value":352}," handler",{"type":139,"tag":150,"props":354,"children":355},{"style":164},[356],{"type":160,"value":275},{"type":139,"tag":150,"props":358,"children":359},{"style":157},[360],{"type":160,"value":280},{"type":139,"tag":150,"props":362,"children":363},{"style":175},[364],{"type":160,"value":365}," \"[[done]] \"",{"type":139,"tag":150,"props":367,"children":368},{"style":164},[369],{"type":160,"value":370},"; },\n",{"type":139,"tag":150,"props":372,"children":374},{"class":152,"line":373},7,[375],{"type":139,"tag":150,"props":376,"children":377},{"style":164},[378],{"type":160,"value":379},"  })]; },\n",{"type":139,"tag":150,"props":381,"children":383},{"class":152,"line":382},8,[384,388,392],{"type":139,"tag":150,"props":385,"children":386},{"style":189},[387],{"type":160,"value":252},{"type":139,"tag":150,"props":389,"children":390},{"style":157},[391],{"type":160,"value":257},{"type":139,"tag":150,"props":393,"children":394},{"style":189},[395],{"type":160,"value":396}," A clipboard-only legacy status migration. *\u002F\n",{"type":139,"tag":150,"props":398,"children":400},{"class":152,"line":399},9,[401,406,410,414,418,422,427,431,435,441,446,451,455,459],{"type":139,"tag":150,"props":402,"children":403},{"style":225},[404],{"type":160,"value":405},"  addPasteRules",{"type":139,"tag":150,"props":407,"children":408},{"style":164},[409],{"type":160,"value":275},{"type":139,"tag":150,"props":411,"children":412},{"style":157},[413],{"type":160,"value":280},{"type":139,"tag":150,"props":415,"children":416},{"style":164},[417],{"type":160,"value":285},{"type":139,"tag":150,"props":419,"children":420},{"style":157},[421],{"type":160,"value":290},{"type":139,"tag":150,"props":423,"children":424},{"style":225},[425],{"type":160,"value":426}," PasteRule",{"type":139,"tag":150,"props":428,"children":429},{"style":164},[430],{"type":160,"value":300},{"type":139,"tag":150,"props":432,"children":433},{"style":175},[434],{"type":160,"value":305},{"type":139,"tag":150,"props":436,"children":438},{"style":437},"--shiki-default:#22863A;--shiki-default-font-weight:bold;--shiki-light:#22863A;--shiki-light-font-weight:bold;--shiki-dark:#85E89D;--shiki-dark-font-weight:bold",[439],{"type":160,"value":440},"\\[",{"type":139,"tag":150,"props":442,"children":443},{"style":308},[444],{"type":160,"value":445},"STATUS:DONE",{"type":139,"tag":150,"props":447,"children":448},{"style":437},[449],{"type":160,"value":450},"\\]",{"type":139,"tag":150,"props":452,"children":453},{"style":175},[454],{"type":160,"value":320},{"type":139,"tag":150,"props":456,"children":457},{"style":157},[458],{"type":160,"value":325},{"type":139,"tag":150,"props":460,"children":461},{"style":164},[462],{"type":160,"value":243},{"type":139,"tag":150,"props":464,"children":466},{"class":152,"line":465},10,[467,471,475,480,484,488,492,497],{"type":139,"tag":150,"props":468,"children":469},{"style":189},[470],{"type":160,"value":338},{"type":139,"tag":150,"props":472,"children":473},{"style":157},[474],{"type":160,"value":257},{"type":139,"tag":150,"props":476,"children":477},{"style":189},[478],{"type":160,"value":479}," Exact canonical status syntax. *\u002F",{"type":139,"tag":150,"props":481,"children":482},{"style":225},[483],{"type":160,"value":352},{"type":139,"tag":150,"props":485,"children":486},{"style":164},[487],{"type":160,"value":275},{"type":139,"tag":150,"props":489,"children":490},{"style":157},[491],{"type":160,"value":280},{"type":139,"tag":150,"props":493,"children":494},{"style":175},[495],{"type":160,"value":496}," \"[[done]]\"",{"type":139,"tag":150,"props":498,"children":499},{"style":164},[500],{"type":160,"value":370},{"type":139,"tag":150,"props":502,"children":504},{"class":152,"line":503},11,[505],{"type":139,"tag":150,"props":506,"children":507},{"style":164},[508],{"type":160,"value":379},{"type":139,"tag":150,"props":510,"children":512},{"class":152,"line":511},12,[513],{"type":139,"tag":150,"props":514,"children":515},{"style":164},[516],{"type":160,"value":517},"});\n",{"type":139,"tag":519,"props":520,"children":521},"style",{},[522],{"type":160,"value":523},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",1793046311420]