{"id":27992080,"url":"https://github.com/stablecanvas/sd-webui-a1111-prompt-parser","last_synced_at":"2026-05-03T05:41:46.762Z","repository":{"id":213513268,"uuid":"734232363","full_name":"StableCanvas/sd-webui-a1111-prompt-parser","owner":"StableCanvas","description":"sd a1111 prompt parser for javascript.","archived":false,"fork":false,"pushed_at":"2025-12-14T10:20:17.000Z","size":106,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-16T14:43:57.236Z","etag":null,"topics":["a1111-stable-diffusion-webui","a1111-webui","parser","prompt","sd","sdxl","stable-diffusion","stable-diffusion-webui","stablediffusion"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/StableCanvas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-12-21T07:24:07.000Z","updated_at":"2025-12-14T10:20:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"99795801-ba95-4d0d-8b66-f2deb22f88ae","html_url":"https://github.com/StableCanvas/sd-webui-a1111-prompt-parser","commit_stats":null,"previous_names":["stablecanvas/sd-webui-a1111-prompt-parser"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/StableCanvas/sd-webui-a1111-prompt-parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StableCanvas%2Fsd-webui-a1111-prompt-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StableCanvas%2Fsd-webui-a1111-prompt-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StableCanvas%2Fsd-webui-a1111-prompt-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StableCanvas%2Fsd-webui-a1111-prompt-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StableCanvas","download_url":"https://codeload.github.com/StableCanvas/sd-webui-a1111-prompt-parser/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StableCanvas%2Fsd-webui-a1111-prompt-parser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32559716,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T03:21:47.309Z","status":"ssl_error","status_checked_at":"2026-05-03T03:21:43.884Z","response_time":103,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["a1111-stable-diffusion-webui","a1111-webui","parser","prompt","sd","sdxl","stable-diffusion","stable-diffusion-webui","stablediffusion"],"created_at":"2025-05-08T17:57:03.145Z","updated_at":"2026-05-03T05:41:46.757Z","avatar_url":"https://github.com/StableCanvas.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sd-webui-a1111-prompt-parser\n\n## Introduction\n\nsd-webui-a1111-prompt-parser is a Stable Diffusion webUI (A1111) prompt parser for JavaScript. It parses Stable Diffusion model prompts into structured data for easy analysis and manipulation by developers.\n\n## Features\n\n- Parses A1111 format prompts, supporting the following syntax:\n  - Plain text\n  - Emphasis (parentheses)\n  - Weight (brackets)\n  - Lora models\n  - Hypernetwork models\n  - Negative prompts (square brackets)\n  - Step Control (scheduling)\n- Converts parsed results into JavaScript objects for easy manipulation and use\n- Supports regenerating A1111 format prompts from JavaScript objects\n\n## Installation\n\n```\npnpm add @stable-canvas/sd-webui-a1111-prompt-parser\n```\n\n## Usage\n\n```typescript\nimport { PromptParser } from \"@stable-canvas/sd-webui-a1111-prompt-parser\";\n\nconst parser = new PromptParser();\n\nconst prompt = `masterpiece, 1girl, blonde hair, \u003clora:Zelda_v1:0.5\u003e, (chromatic aberration:0.7), sharp focus, hyper detailed, (fog:0.7), \u003chypernet:sxz-bloom:0.5\u003e, [real photo], [highlight:dark:0.9], (((good anatomy)))`;\n\nconst output = parser.parse(prompt);\n\nconsole.log(output);\n```\n\nOutput:\n\n```json\n[\n  { \"type\": \"plain\", \"value\": \"masterpiece\" },\n  { \"type\": \"plain\", \"value\": \"1girl\" },\n  { \"type\": \"plain\", \"value\": \"blonde hair\" },\n  { \"type\": \"extra_networks\", \"value\": \"lora\", \"args\": [\"Zelda_v1\", \"0.5\"] },\n  {\n    \"type\": \"weighted\",\n    \"value\": 0.7,\n    \"args\": [{ \"type\": \"plain\", \"value\": \"chromatic aberration\" }]\n  },\n  { \"type\": \"plain\", \"value\": \"sharp focus\" },\n  { \"type\": \"plain\", \"value\": \"hyper detailed\" },\n  {\n    \"type\": \"weighted\",\n    \"value\": 0.7,\n    \"args\": [{ \"type\": \"plain\", \"value\": \"fog\" }]\n  },\n  {\n    \"type\": \"extra_networks\",\n    \"value\": \"hypernet\",\n    \"args\": [\"sxz-bloom\", \"0.5\"]\n  },\n  {\n    \"type\": \"negative\",\n    \"value\": 1,\n    \"args\": [{ \"type\": \"plain\", \"value\": \"real photo\" }]\n  },\n  {\n    \"type\": \"scheduled_full\",\n    \"value\": 0.9,\n    \"args\": [\n      [{ \"type\": \"plain\", \"value\": \"highlight\" }],\n      [{ \"type\": \"plain\", \"value\": \"dark\" }]\n    ]\n  },\n  {\n    \"type\": \"positive\",\n    \"value\": 3,\n    \"args\": [{ \"type\": \"plain\", \"value\": \"good anatomy\" }]\n  }\n]\n```\n\n### Usage Case: de-SD-styled (remove stable-diffusion styled prompt)\n\nThis function is used to clear all SD-WebUI style prompts, which is necessary when training new models based on DiT.\n\n\u003e Theoretically, it should iterate through the tokens (this is a high level AST structure), but generally, no one writes prompt control syntax beyond two levels.\n\n```typescript\nimport {\n  PromptParser,\n  generation_str,\n} from \"@stable-canvas/sd-webui-a1111-prompt-parser\";\n\nconst parser = new PromptParser();\n\nfunction cleanPrompt(prompt: string): string {\n  const tokens = parser\n    .parse(prompt)\n    .filter((x) =\u003e x.type !== \"extra_networks\")\n    .flatMap((x) =\u003e {\n      switch (x.type) {\n        case \"weighted\":\n        case \"negative\":\n        case \"positive\":\n        case \"scheduled_full\":\n          return x.args;\n        default:\n          return x;\n      }\n    });\n\n  return generation_str(tokens).trim();\n}\n```\n\n## API\n\n### `PromptParser` Class\n\n#### Constructor\n\n```typescript\nnew PromptParser(options?: SDPromptParser.ILarkOptions);\n```\n\n- `options`: Optional parameters for configuring the Lark parser. For detailed parameter descriptions, refer to the [Lark documentation](https://lark-parser.readthedocs.io/en/latest/classes/ Lark.html#lark.Lark).\n\n#### `parse` Method\n\n```typescript\nparse(text: string, options?: ParseOptions): SDPromptParser.PromptNode[];\n```\n\n- `text`: The prompt string to be parsed.\n- `options`: Optional parameters for configuring parsing behavior.\n  - `force`: When set to `true`, parsing is forced even if there are syntax errors in the prompt. The parsing results may be incomplete. The default is `false`.\n- Returns: An array of parsed prompt nodes, node type definitions refer to `SDPromptParser.PromptNode`.\n\n### `compilation` Function\n\n```typescript\ncompilation(node: SDPromptParser.IPromptASTNode): SDPromptParser.PromptNode[];\n```\n\n- `node`: The root node of the abstract syntax tree (AST) generated by the Lark parser.\n- Returns: An array of parsed prompt nodes, node type definitions refer to `SDPromptParser.PromptNode`.\n\n### `generation_token` Function\n\n```typescript\ngeneration_token(nodes: SDPromptParser.PromptNode[], options?: GenerationOptions): string[];\n```\n\n- `nodes`: An array of nodes for which to generate prompt strings.\n- `options`: Optional parameters for configuring generation behavior.\n  - `remove_1_weighted`: When set to `true`, nodes with a weight of 1 are removed. The default is `false`.\n- Returns: An array of generated prompt strings.\n\n### `generation_str` Function\n\n```typescript\ngeneration_str(nodes: SDPromptParser.PromptNode[], options?: GenerationOptions): string;\n```\n\n- `nodes`: An array of nodes for which to generate the prompt string.\n- `options`: Optional parameters for configuring generation behavior.\n  - `remove_1_weighted`: When set to `true`, nodes with a weight of 1 are removed. The default is `false`.\n- Returns: The generated prompt string.\n\n## Build\n\n### 1. Build the Parser\n\n#### 1.1 Install Lark.js\n\n```\npip install lark-js\n```\n\n#### 1.2 Build\n\n```\npnpm build-lark\n```\n\n### 2. Build the Package\n\n```\npnpm build\n```\n\n## Test\n\n```\npnpm test\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstablecanvas%2Fsd-webui-a1111-prompt-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstablecanvas%2Fsd-webui-a1111-prompt-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstablecanvas%2Fsd-webui-a1111-prompt-parser/lists"}