{"id":25006605,"url":"https://github.com/croct-tech/md-lite-js","last_synced_at":"2025-04-12T15:51:47.380Z","repository":{"id":206216476,"uuid":"691269193","full_name":"croct-tech/md-lite-js","owner":"croct-tech","description":"📝 A simple and easy-to-use Markdown parser and render for basic formatting. Only 1.5 KB gzipped!","archived":false,"fork":false,"pushed_at":"2025-04-10T11:18:48.000Z","size":610,"stargazers_count":21,"open_issues_count":2,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-10T12:47:41.807Z","etag":null,"topics":["browser","client-side","cms","fast","formatting","js","lightweight","markdown","node","server-side","typescript","zero-dependency"],"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/croct-tech.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":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-13T20:48:00.000Z","updated_at":"2025-04-10T11:18:51.000Z","dependencies_parsed_at":"2023-12-24T14:23:30.634Z","dependency_job_id":"faa473b5-8397-430e-938a-30865593a134","html_url":"https://github.com/croct-tech/md-lite-js","commit_stats":null,"previous_names":["croct-tech/md-lite-js"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/croct-tech%2Fmd-lite-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/croct-tech%2Fmd-lite-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/croct-tech%2Fmd-lite-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/croct-tech%2Fmd-lite-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/croct-tech","download_url":"https://codeload.github.com/croct-tech/md-lite-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248224071,"owners_count":21068072,"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":["browser","client-side","cms","fast","formatting","js","lightweight","markdown","node","server-side","typescript","zero-dependency"],"created_at":"2025-02-05T01:50:21.066Z","updated_at":"2025-04-12T15:51:47.359Z","avatar_url":"https://github.com/croct-tech.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://croct.com\"\u003e\n        \u003cimg src=\"https://cdn.croct.io/brand/logo/repo-icon-green.svg\" alt=\"Croct\" height=\"80\"/\u003e\n    \u003c/a\u003e\n    \u003cbr /\u003e\n    \u003cstrong\u003eMD Lite\u003c/strong\u003e\n    \u003cbr /\u003e\n    A minimalist Markdown parser and render for basic formatting.\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://www.npmjs.com/package/@croct/md-lite\"\u003e\u003cimg alt=\"Version\" src=\"https://img.shields.io/npm/v/@croct/md-lite\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/croct-tech/md-lite-js/actions/workflows/validate-branch.yaml\"\u003e\u003cimg alt=\"Build\" src=\"https://github.com/croct-tech/md-lite-js/actions/workflows/validate-branch.yaml/badge.svg\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://codeclimate.com/repos/654abd6e5167670cf20e64a0/maintainability\"\u003e\u003cimg src=\"https://api.codeclimate.com/v1/badges/d8dfc7cb03405d137fbd/maintainability\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://codeclimate.com/repos/654abd6e5167670cf20e64a0/test_coverage\"\u003e\u003cimg src=\"https://api.codeclimate.com/v1/badges/d8dfc7cb03405d137fbd/test_coverage\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://bundlephobia.com/package/@croct/md-lite\"\u003e\u003cimg alt=\"Gzipped bundle size\" src=\"https://badgen.net/bundlephobia/minzip/@croct/md-lite\"\u003e\u003c/a\u003e\n    \u003cbr /\u003e\n    \u003cbr /\u003e\n    \u003ca href=\"https://github.com/croct-tech/md-lite-js/releases\"\u003e📦 Releases\u003c/a\u003e\n    ·\n    \u003ca href=\"https://github.com/croct-tech/md-lite-js/issues/new?labels=bug\u0026template=bug-report.md\"\u003e🐞 Report Bug\u003c/a\u003e\n    ·\n    \u003ca href=\"https://github.com/croct-tech/md-lite-js/issues/new?labels=enhancement\u0026template=feature-request.md\"\u003e✨ Request Feature\u003c/a\u003e\n\u003c/p\u003e\n\n## Introduction\n\nThis library provides a fast and simple Markdown parser with zero dependencies.\nPerfect for those who need to handle basic Markdown syntax without the overhead of a full-featured Markdown parser.\n\n**Features**\n\n- 🪶 **Lightweight:**  Zero dependencies, about 1.5 KB gzipped.\n- 🌐 **Cross-environment:**  Works in Node.js and browsers.\n- ✍️ **Minimalist:** Supports only _italic_, **bold**, ~~strikethrough~~, `inline code`, [links](#), 🖼️ images, and ¶ paragraphs.\n- 🛠 **Flexible:** Render whatever you want, from HTML to JSX.\n\n### Who is this library for?\n\nIf you're working on a project that requires rendering Markdown for short texts like titles, subtitles, and descriptions, but you don't need a full-featured Markdown parser, this library is for you.\n\n## Installation\n\nWe recommend using [NPM](https://www.npmjs.com) to install the package:\n\n```sh\nnpm install @croct/md-lite\n```\n\nAlternatively, you can use [Yarn](https://yarnpkg.com):\n\n```sh\nyarn add @croct/md-lite\n```\n\n## Basic usage\n\nThe following sections show how to parse and render Markdown using this library.\n\n### Parsing Markdown\n\nTo parse a Markdown string into an AST, use the `parse` function:\n\n```ts\nimport {parse} from '@croct/md-lite';\n\nconst markdown = '**Hello**, [World](https://example.com)';\n\nconst ast = parse(markdown);\n```\n\nThe `parse` function returns a tree-like structure called an [Abstract Syntax Tree](https://en.wikipedia.org/wiki/Abstract_syntax_tree) (AST).\nYou can find the full AST definition [here](/src/ast.ts).\n\n### Rendering Markdown\n\nTo render an AST into whatever you want, use the `render` function.\nIt accepts as input either a Markdown string or an AST:\n\n```ts\nimport {render} from '@croct/md-lite';\n\n// Passing a string as input is equivalent to calling `parse` first\nconst markdown = '**Hello**, [World](https://example.com)';\n\nconst html = render(markdown, {\n    fragment: node =\u003e node.children.join(''),\n    text: node =\u003e node.content,\n    bold: node =\u003e `\u003cb\u003e${node.children}\u003c/b\u003e`,\n    italic: node =\u003e `\u003ci\u003e${node.children}\u003c/i\u003e`,\n    strike: node =\u003e `\u003cs\u003e${node.children}\u003c/s\u003e`,\n    code: node =\u003e `\u003ccode\u003e${node.content}\u003c/code\u003e`,\n    link: node =\u003e `\u003ca href=\"${node.href}\"\u003e${node.children}\u003c/a\u003e`,\n    image: node =\u003e `\u003cimg src=\"${node.src}\" alt=\"${node.alt}\"\u003e`,\n    paragraph: node =\u003e `\u003cp\u003e${node.children.join('')}\u003c/p\u003e`,\n});\n```\n\nHere is an example of how to render the Markdown string above into JSX:\n\n```tsx\nimport {render} from '@croct/md-lite';\n\n// Passing a string as input is equivalent to calling `parse` first\nconst markdown = '**Hello**, [World](https://example.com)';\n\nconst jsx = render(markdown, {\n    fragment: node =\u003e node.children,\n    text: node =\u003e node.content,\n    bold: node =\u003e \u003cb key={node.index}\u003e{node.children}\u003c/b\u003e,\n    italic: node =\u003e \u003ci key={node.index}\u003e{node.children}\u003c/i\u003e,\n    strike: node =\u003e \u003cs key={node.index}\u003e{node.children}\u003c/s\u003e,\n    code: node =\u003e \u003ccode key={node.index}\u003e{node.content}\u003c/code\u003e,\n    link: node =\u003e \u003ca key={node.index} href={node.href}\u003e{node.children}\u003c/a\u003e,\n    image: node =\u003e \u003cimg key={node.index} src={node.src} alt={node.alt} /\u003e,\n    paragraph: node =\u003e \u003cp key={node.index}\u003e{node.children}\u003c/p\u003e,\n});\n```\n\n#### Handling unsupported features\n\nIn some cases, you might want to intentionally omit certain features from your \nrendered Markdown. For instance, if your platform doesn't support image rendering, \nou can simply return the original source text instead of trying to display the image.\n\n```ts\nimport {render, unescape} from '@croct/md-lite';\n\nrender(markdown, {\n    // ... other render functions\n    image: node =\u003e unescape(node.source),\n});\n```\n\nThis code snippet will simply return the raw source code of the image node \ninstead of trying to render it as an image. You can adapt this approach \nto handle any other unsupported feature by defining appropriate render \nfunctions and accessing the relevant data from the AST.\n\n## Contributing\n\nContributions to the package are always welcome! \n\n- Report any bugs or issues on the [issue tracker](https://github.com/croct-tech/md-lite-js/issues).\n- For major changes, please [open an issue](https://github.com/croct-tech/md-lite-js/issues) first to discuss what you would like to change.\n- Please make sure to update tests as appropriate.\n\n## Testing\n\nBefore running the test suites, the development dependencies must be installed:\n\n```sh\nnpm install\n```\n\nThen, to run all tests:\n\n```sh\nnpm run test\n```\n\nRun the following command to check the code against the style guide:\n\n```sh\nnpm run lint\n```\n\n## Building\n\nBefore building the project, the dependencies must be installed:\n\n```sh\nnpm install\n```\n\nThen, to build the project:\n\n```sh\nnpm run build\n```\n\n\n## License\n\nCopyright © 2015-2023 Croct Limited, All Rights Reserved.\n\nAll information contained herein is, and remains the property of Croct Limited. The intellectual, design and technical concepts contained herein are proprietary to Croct Limited s and may be covered by U.S. and Foreign Patents, patents in process, and are protected by trade secret or copyright law. Dissemination of this information or reproduction of this material is strictly forbidden unless prior written permission is obtained from Croct Limited.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcroct-tech%2Fmd-lite-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcroct-tech%2Fmd-lite-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcroct-tech%2Fmd-lite-js/lists"}