{"id":46453544,"url":"https://github.com/kimhongyeon/safe-markdown2html","last_synced_at":"2026-05-24T00:02:47.461Z","repository":{"id":342428478,"uuid":"1152458498","full_name":"kimhongyeon/safe-markdown2html","owner":"kimhongyeon","description":"Convert Markdown to sanitized HTML with DOMPurify. Safe by default — prevents XSS and malformed markup.","archived":false,"fork":false,"pushed_at":"2026-05-12T03:57:38.000Z","size":282,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-12T05:38:54.366Z","etag":null,"topics":["browser","converter","dompurify","html","isomorphic","markdown","marked","node","safe","sanitize","security","xss"],"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/kimhongyeon.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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-02-07T22:44:48.000Z","updated_at":"2026-05-12T03:57:41.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/kimhongyeon/safe-markdown2html","commit_stats":null,"previous_names":["kimhongyeon/safe-markdown2html"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/kimhongyeon/safe-markdown2html","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimhongyeon%2Fsafe-markdown2html","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimhongyeon%2Fsafe-markdown2html/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimhongyeon%2Fsafe-markdown2html/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimhongyeon%2Fsafe-markdown2html/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kimhongyeon","download_url":"https://codeload.github.com/kimhongyeon/safe-markdown2html/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimhongyeon%2Fsafe-markdown2html/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33416315,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-23T22:14:44.296Z","status":"ssl_error","status_checked_at":"2026-05-23T22:14:43.778Z","response_time":53,"last_error":"SSL_read: 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":["browser","converter","dompurify","html","isomorphic","markdown","marked","node","safe","sanitize","security","xss"],"created_at":"2026-03-06T01:03:39.121Z","updated_at":"2026-05-24T00:02:47.449Z","avatar_url":"https://github.com/kimhongyeon.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# safe-markdown2html\n\nConvert Markdown to **sanitized HTML**. Safe by default — prevents XSS and fixes malformed markup.\n\n[![CI](https://github.com/kimhongyeon/safe-markdown2html/actions/workflows/ci.yml/badge.svg)](https://github.com/kimhongyeon/safe-markdown2html/actions/workflows/ci.yml)\n[![npm version](https://img.shields.io/npm/v/safe-markdown2html.svg)](https://www.npmjs.com/package/safe-markdown2html)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n## Features\n\n- **XSS Prevention** — HTML is sanitized via [DOMPurify](https://github.com/cure53/DOMPurify) after conversion\n- **Markdown Parsing** — Powered by [marked](https://github.com/markedjs/marked)\n- **Safe Links** — All `\u003ca\u003e` tags automatically get `target=\"_blank\"`\n- **Bold Syntax Fix** — Handles edge cases where `**bold**` with parentheses fails to parse\n- **Malformed URL Correction** — Fixes URLs broken by parentheses (common in Korean text)\n- **Strikethrough** — Standard `\u003cdel\u003e` tags preserved by default, optional tilde conversion\n- **Environment Aware** — Uses native DOM in browser, `jsdom` in Node.js (optional peer dependency)\n- **Dual Build** — ESM and CommonJS both supported\n\n## Install\n\n```bash\nnpm install safe-markdown2html\n```\n\nFor Node.js (server-side), also install `jsdom`:\n\n```bash\nnpm install safe-markdown2html jsdom\n```\n\nIn browser environments, `jsdom` is not needed — the native `window` object is used automatically.\n\n## Usage\n\n```ts\nimport { safeMarkdown2Html } from 'safe-markdown2html';\n\nconst html = safeMarkdown2Html('**Hello** [world](https://example.com)');\n// \u003cp\u003e\u003cstrong\u003eHello\u003c/strong\u003e \u003ca href=\"https://example.com\" target=\"_blank\"\u003eworld\u003c/a\u003e\u003c/p\u003e\n```\n\nDefault import is also supported:\n\n```ts\nimport safeMarkdown2Html from 'safe-markdown2html';\n```\n\n## Environment Support\n\n| Environment | DOM Source | `jsdom` Required |\n|---|---|---|\n| Browser (React, Vue, etc.) | Native `window` | No |\n| Node.js / SSR | `jsdom` | Yes |\n| Custom | `window` option | No |\n\nIn the **browser**, the native `window` object is used automatically — no extra dependencies needed.\n\nIn **Node.js**, `jsdom` provides the DOM environment that DOMPurify needs. Install it as a peer dependency:\n\n```bash\nnpm install jsdom\n```\n\nYou can also pass a custom `window` object directly via the `window` option for full control.\n\n## Options\n\nAll options are optional. Sensible defaults are applied.\n\n```ts\nsafeMarkdown2Html(markdown, {\n  linkTargetBlank: true,       // Add target=\"_blank\" to links (default: true)\n  fixMalformedUrls: true,      // Fix URLs broken by parentheses (default: true)\n  fixBoldSyntax: true,         // Fix bold syntax with parentheses (default: true)\n  convertStrikethrough: false, // Convert \u003cdel\u003e to tilde ~ (default: false)\n  window: customWindow,        // Custom window object for DOMPurify\n});\n```\n\n| Option | Type | Default | Description |\n|---|---|---|---|\n| `linkTargetBlank` | `boolean` | `true` | Add `target=\"_blank\"` to all anchor tags |\n| `fixMalformedUrls` | `boolean` | `true` | Fix URLs broken by parentheses + non-ASCII characters |\n| `fixBoldSyntax` | `boolean` | `true` | Fix `**bold**` syntax that fails with parentheses |\n| `convertStrikethrough` | `boolean` | `false` | Convert `\u003cdel\u003e` tags to tilde (`~`) notation |\n| `window` | `object` | auto-detect | Window object for DOMPurify (browser: native, server: JSDOM) |\n\n### Examples\n\n#### Disable target=\"_blank\"\n\n```ts\nsafeMarkdown2Html('[link](https://example.com)', {\n  linkTargetBlank: false,\n});\n```\n\n#### Enable strikethrough conversion\n\n```ts\nsafeMarkdown2Html('~~deleted text~~', {\n  convertStrikethrough: true,\n});\n// \u003cp\u003e~deleted text~\u003c/p\u003e\n```\n\n#### Custom window (testing / custom environments)\n\n```ts\nimport { JSDOM } from 'jsdom';\n\nsafeMarkdown2Html('**hello**', {\n  window: new JSDOM('').window,\n});\n```\n\n## API\n\n### `safeMarkdown2Html(markdown: string, options?: SafeMarkdown2HtmlOptions): string`\n\nConverts a Markdown string to sanitized HTML.\n\n**Pipeline:**\n\n1. Preprocess bold syntax (`**text**` → `\u003cstrong\u003e`) — if `fixBoldSyntax` enabled\n2. Parse Markdown → HTML (via `marked`)\n3. Sanitize HTML (via `DOMPurify`)\n4. Fix malformed URLs — if `fixMalformedUrls` enabled\n5. Add `target=\"_blank\"` to all links — if `linkTargetBlank` enabled\n6. Replace `\u003cdel\u003e` tags with `~` — if `convertStrikethrough` enabled\n7. Fix remaining unconverted bold syntax — if `fixBoldSyntax` enabled\n\n## Development\n\n```bash\nnpm install\nnpm test          # Run tests\nnpm run build     # Build (ESM + CJS + d.ts)\nnpm run lint      # Lint\nnpm run typecheck # Type check\n```\n\n## License\n\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkimhongyeon%2Fsafe-markdown2html","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkimhongyeon%2Fsafe-markdown2html","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkimhongyeon%2Fsafe-markdown2html/lists"}