{"id":18434334,"url":"https://github.com/cycraft/starkdown","last_synced_at":"2025-04-07T19:31:38.167Z","repository":{"id":58938673,"uuid":"534633509","full_name":"CyCraft/starkdown","owner":"CyCraft","description":"🦾 Tiny \u003c3kb Markdown parser written, almost as fast and smart as Tony Stark","archived":false,"fork":false,"pushed_at":"2025-02-19T19:01:23.000Z","size":2010,"stargazers_count":8,"open_issues_count":7,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-22T23:51:13.138Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CyCraft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"mesqueeb","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2022-09-09T12:28:44.000Z","updated_at":"2025-02-23T07:27:44.000Z","dependencies_parsed_at":"2024-11-06T06:03:27.908Z","dependency_job_id":"0f22798d-6582-44fc-b59a-6b2147598c0f","html_url":"https://github.com/CyCraft/starkdown","commit_stats":{"total_commits":119,"total_committers":17,"mean_commits":7.0,"dds":0.6974789915966386,"last_synced_commit":"704d29fc389f7325567680e461fb3d20ab534ab6"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CyCraft%2Fstarkdown","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CyCraft%2Fstarkdown/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CyCraft%2Fstarkdown/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CyCraft%2Fstarkdown/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CyCraft","download_url":"https://codeload.github.com/CyCraft/starkdown/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247716296,"owners_count":20984214,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-11-06T06:03:11.370Z","updated_at":"2025-04-07T19:31:38.153Z","avatar_url":"https://github.com/CyCraft.png","language":"TypeScript","funding_links":["https://github.com/sponsors/mesqueeb"],"categories":[],"sub_categories":[],"readme":"# Starkdown 🦾\n\n\u003ca href=\"https://www.npmjs.com/package/starkdown\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/starkdown.svg\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/starkdown\"\u003e\u003cimg src=\"https://img.shields.io/npm/dw/starkdown.svg\" alt=\"Latest Stable Version\"\u003e\u003c/a\u003e\n\nStarkdown is a Tiny \u003c4kb Markdown parser written, almost as fast and smart as Tony Stark.\n\n```sh\nnpm i starkdown\n```\n\n## Motivation\n\nIt is a continuation on a similar package called [Snarkdown](https://github.com/developit/snarkdown), which had stopped development at 1kb, but doesn't include basic support for paragraphs, tables, fenced divs, etc.\n\nStarkdown stays around 1.6kb and adds these additional enhancements:\n\n- [Paragraphs](#paragraphs)\n- [Tables](#tables)\n- [Fenced Divs](#fenced-divs)\n- [Escaping snake_case words](#escaping-snake_case-words)\n\nPackage size wise, compared to other Markdown parsers, it's **8 ~ 18 times smaller!** See the [Package Size Comparison Chart](#package-size-comparison-chart)\n\n## Usage\n\nStarkdown is really easy to use, a single function which parses a string of Markdown and returns a String of HTML. Couldn't be simpler.\n\n```js\nimport { starkdown } from 'starkdown'\n\nconst str = '_This_ is **easy** to `use`.'\n\nconst html = starkdown(str)\n```\n\nThe `html` returned will look like:\n\n```html\n\u003cp\u003e\u003cem\u003eThis\u003c/em\u003e is \u003cstrong\u003eeasy\u003c/strong\u003e to \u003ccode\u003euse\u003c/code\u003e.\u003c/p\u003e\n```\n\n### Paragraphs\n\nWith most Markdown implementations, paragraphs are wrapped in `\u003cp\u003e` tags. With Starkdown, this is no different.\n\n- All paragraphs and \"inline\" elements are wrapped in a `\u003cp\u003e` tags\n  (See [List of \"inline\" elements](https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements#list_of_inline_elements) on MDN)\n  - Eg. a standalone image will still be wrapped in a `\u003cp\u003e` tag, because it's an inline element.\n- All non-inline elements will not be wrapped in `\u003cp\u003e` tags\n  - Eg. a table will not be wrapped in a `\u003cp\u003e` tag.\n\n```md\nCheck [github](https://github.com)\n\nImg: ![](/some-image.png)\n```\n\nconverts to\n\n```html\n\u003cp\u003eCheck \u003ca href=\"https://github.com\"\u003egithub\u003c/a\u003e\u003c/p\u003e\n\u003cp\u003eImg: \u003cimg src=\"/some-image.png\" alt=\"\" /\u003e\u003c/p\u003e\n```\n\nBut also, when _just_ using images and links:\n\n```md\n[github](https://github.com)\n\n![](/some-image.png)\n```\n\nconverts to\n\n```html\n\u003cp\u003e\u003ca href=\"https://github.com\"\u003egithub\u003c/a\u003e\u003c/p\u003e\n\u003cp\u003e\u003cimg src=\"/some-image.png\" alt=\"\" /\u003e\u003c/p\u003e\n```\n\nIn contrast, non-inline elements won't get a `\u003cp\u003e` tag:\n\n```md\n### Code\n\n\\`\\`\\`js\nconst a = 1\n\\`\\`\\`\n```\n\nconverts to\n\n```html\n\u003ch3\u003eCode\u003c/h3\u003e\n\u003cpre class=\"code js\"\u003e\u003ccode class=\"language-js\"\u003econst a = 1\u003c/code\u003e\u003c/pre\u003e\n```\n\n### Links\n\nUsual markdown for links works, i.e\n\n```md\n[github](https://github.com)\n```\n\nbecomes\n\n```html\n\u003cp\u003e\u003ca href=\"https://github.com\"\u003egithub\u003c/a\u003e\u003c/p\u003e\n```\n\nBut you can also add properties and classes to links using attribute lists like so:\n\n```md\n[github](https://github.com){:target=\"\\_blank\" .foo .bar #baz}\n```\n\nbecomes\n\n```html\n\u003cp\u003e\u003ca href=\"https://github.com\" target=\"_blank\" class=\"foo bar\" id=\"baz\"\u003egithub\u003c/a\u003e\u003c/p\u003e\n```\n\n### Tables\n\n```md\n| My | Table |\n```\n\nconverts to\n\n```html\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eMy\u003c/td\u003e\n    \u003ctd\u003eTable\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n```\n\n### Fenced Divs\n\n```md\n:::\nthis is some info\n:::\n```\n\nconverts to\n\n```html\n\u003cdiv class=\"fenced\"\u003e\u003cp\u003ethis is some info\u003c/p\u003e\u003c/div\u003e\n```\n\n**Or with a custom class.**\n\n```md\n::: info\nthis is some info\n:::\n```\n\nconverts to\n\n```html\n\u003cdiv class=\"fenced info\"\u003e\u003cp\u003ethis is some info\u003c/p\u003e\u003c/div\u003e\n```\n\n### Escaping snake_case words\n\nYou need to escape your formatting with `\\` in order to correctly convert sentences like these:\n\n```md\nsnake*case is \\_so-so*\n```\n\nwill convert to:\n\n```html\n\u003cp\u003esnake\u003cem\u003ecase is \u003c/em\u003eso-so\u003c/p\u003e\n```\n\nInstead you should write\n\n```md\nsnake*case is \\_so-so*\n```\n\nwhich will convert to:\n\n```html\n\u003cp\u003esnake_case is \u003cem\u003eso-so\u003c/em\u003e\u003c/p\u003e\n```\n\n## Disable MarkDown Features\n\nStarkdown comes built in with several \"parsers\" that each are responsible to convert a part of the markdown to HTML. You can filter out certain parsers to get different results.\n\nThe list of enabled default parsers can be inspected at [./src/defaultParsers.ts](./src/defaultParsers.ts).\n\n```js\nimport { starkdown, defaultParsers } from 'starkdown'\n\nconst str = '_This_ is **easy** to `use`.'\n\n// implicitly uses defaultParsers\nconst html = starkdown(str)\n\n// this is a quick way to parse the string without the table tokeniser\n// however, even though the parser is not used, it will not get tree-shaked\nconst htmlWithoutTables = starkdown(str, {\n  plugins: defaultParsers.filter((x) =\u003e x.name !== 'table'),\n})\n```\n\nYou can also add your own parsers this way. See [#Custom Parsers](#custom-parsers) below.\n\n## Tree-Shaking\n\nYou can slim down the import \u0026 bundle size of Starkdown if you don't need all of the parsers provided in Starkdown by default.\n\nThe list of default parsers can be inspected at [./src/defaultParsers.ts](./src/defaultParsers.ts).\n\n```js\nimport { createTokenizerParser } from 'starkdown'\nimport { escape, boldItalicsStrikethrough, codeblocks, inlineCode, quote } from 'starkdown/parsers'\n\nconst str = '_This_ is **easy** to `use`.'\n\n// This will tree-shake out any parser that is not used\nconst mdDiscordPlugins = [escape, boldItalicsStrikethrough, codeblock, inlineCode, quote]\nconst mdDiscord = createTokenizerParser(mdDiscordPlugins)\nconst html = mdDiscord(str, { plugins: mdDiscordPlugins })\n\n// Note: These are in order of priority so the order can matter, e.g `escape` must come first to escape markdown\n```\n\nYou can also add your own parsers this way. See [#Custom Parsers](#custom-parsers) below.\n\n## Custom Parsers\n\nParsers are defined as objects that match the following TypeScript definition.\n\n```ts\nimport type { ParserDef } from 'starkdown'\n// use this to create your custom parser\n```\n\n- Check the source code of [`ParserDef`](./src/types.ts) for more info.\n- Examples can be found in the [parsers folder](./src/parsers/).\n\n## Security\n\n**Note on XSS:** Starkdown doesn't sanitize HTML. Please bring your own HTML sanitation for any place where user input will be converted into HTML.\n\n## Package Size Comparison Chart\n\n![Package Size Comparison Chart](./.github/markdown-parsers.jpg)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcycraft%2Fstarkdown","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcycraft%2Fstarkdown","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcycraft%2Fstarkdown/lists"}