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:
parent
f172da378a
commit
2c762b0411
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue