refactor: move block scanning logic to shared module

Import `FENCED_BLOCK_RE` and `parseBlockAttrs` from `block-scanner.js`
instead of defining them locally in `declare-parser.ts`.
This commit is contained in:
hypercross 2026-07-13 10:49:40 +08:00
parent f172da378a
commit 2c762b0411
1 changed files with 1 additions and 19 deletions

View File

@ -15,25 +15,7 @@
*/
import { parse } from "csv-parse/browser/esm/sync";
// ---------------------------------------------------------------------------
// Shared block scanning — used by both CLI (block-processor) and client
// (completions.ts) so there's a single source of truth for declare parsing.
// ---------------------------------------------------------------------------
/** Matches fenced code blocks with an info string. */
const FENCED_BLOCK_RE = /^```(\w*)\s+(\S.*?)\s*\n([\s\S]*?)```\s*$/gm;
/** Parse key="value" and key=value pairs from an attribute string. */
function parseBlockAttrs(info: string): Record<string, string> {
const attrs: Record<string, string> = {};
const re = /(\w+)\s*=\s*("[^"]*"|\S+)/g;
let m: RegExpExecArray | null;
while ((m = re.exec(info)) !== null) {
attrs[m[1]] = m[2].replace(/^"|"$/g, "");
}
return attrs;
}
import { FENCED_BLOCK_RE, parseBlockAttrs } from "./block-scanner.js";
/**
* Scan markdown content for ```csv role=declare blocks and return