{"id":26499683,"url":"https://github.com/executablebooks/markdown-it-dollarmath","last_synced_at":"2025-03-20T15:18:30.337Z","repository":{"id":37907457,"uuid":"381692352","full_name":"executablebooks/markdown-it-dollarmath","owner":"executablebooks","description":"A markdown-it plugin for $-delimited math","archived":false,"fork":false,"pushed_at":"2023-09-26T21:49:22.000Z","size":279,"stargazers_count":4,"open_issues_count":4,"forks_count":5,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-02-20T03:16:22.636Z","etag":null,"topics":["markdown-it","markdown-it-plugin"],"latest_commit_sha":null,"homepage":"https://executablebooks.github.io/markdown-it-dollarmath/","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/executablebooks.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2021-06-30T12:20:21.000Z","updated_at":"2023-05-19T02:47:16.000Z","dependencies_parsed_at":"2024-06-19T01:33:37.478Z","dependency_job_id":"686ff7a5-be0b-431c-a897-5e559a40c31f","html_url":"https://github.com/executablebooks/markdown-it-dollarmath","commit_stats":{"total_commits":25,"total_committers":4,"mean_commits":6.25,"dds":0.4,"last_synced_commit":"b3c9f097c8ce040698b40191221afa0d441150f4"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":"executablebooks/markdown-it-plugin-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/executablebooks%2Fmarkdown-it-dollarmath","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/executablebooks%2Fmarkdown-it-dollarmath/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/executablebooks%2Fmarkdown-it-dollarmath/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/executablebooks%2Fmarkdown-it-dollarmath/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/executablebooks","download_url":"https://codeload.github.com/executablebooks/markdown-it-dollarmath/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244591477,"owners_count":20477709,"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":["markdown-it","markdown-it-plugin"],"created_at":"2025-03-20T15:18:29.522Z","updated_at":"2025-03-20T15:18:30.318Z","avatar_url":"https://github.com/executablebooks.png","language":"TypeScript","readme":"# markdown-it-dollarmath\n\n[![ci-badge]][ci-link]\n[![npm-badge]][npm-link]\n\nA [markdown-it](https://github.com/markdown-it/markdown-it) plugin for $-delimited math environments.\n\nSee \u003chttps://executablebooks.github.io/markdown-it-dollarmath/\u003e for a demonstration!\n\nNote there is a similar plugin [markdown-it-texmath](https://github.com/goessner/markdown-it-texmath).\n`markdown-it-dollarmath` package differs in that it is optimised for dollar math:\nit is more performant, handles backslash `\\\\` escaping properly, and allows for more configuration.\n\n## Usage\n\nOptions:\n\n- `allow_space`: Parse inline math when there is space after/before the opening/closing `$`, e.g. `$ a $`\n- `allow_digits`: Parse inline math when there is a digit before/after the opening/closing `$`, e.g. `1$` or `$2`\n- `double_inline`: Search for double-dollar math within inline contexts\n- `allow_labels`: Capture math blocks with label suffix, e.g. `$$a=1$$ (eq1)`\n- `labelNormalizer`: Function to normalize the label, by default replaces whitespace with `-` (to align with [HTML5 ids](https://html.spec.whatwg.org/multipage/dom.html#global-attributes:the-id-attribute-2))\n\nYou should \"bring your own\" math render, provided as an option to the plugin.\nThis function should take the string plus (optional) options, and return a string.\nFor example, below the [KaTeX](https://github.com/Khan/KaTeX) render is used.\n\nAs a Node module:\n\n```javascript\nimport { renderToString } from \"katex\"\nimport MarkdownIt from \"markdown-it\"\nimport dollarmathPlugin from \"markdown-it-dollarmath\"\n\nconst mdit = MarkdownIt().use(dollarmathPlugin, {\n  allow_space: true,\n  allow_digits: true,\n  double_inline: true,\n  allow_labels: true,\n  labelNormalizer(label) {\n    return label.replace(/[\\s]+/g, \"-\")\n  },\n  renderer(content, { displayMode }) {\n    return renderToString(content, { displayMode, throwOnError: false })\n  },\n  labelRenderer(label) {\n    return `\u003ca href=\"#${label}\" class=\"mathlabel\" title=\"Permalink to this equation\"\u003e¶\u003ca\u003e`\n  }\n})\nconst text = mdit.render(\"$a = 1$\")\n```\n\nIn the browser:\n\n```html\n\u003c!doctype html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003ctitle\u003eExample Page\u003c/title\u003e\n    \u003clink\n      rel=\"stylesheet\"\n      href=\"https://cdn.jsdelivr.net/npm/katex/dist/katex.min.css\"\n    /\u003e\n    \u003cscript src=\"https://cdn.jsdelivr.net/npm/markdown-it@12/dist/markdown-it.min.js\"\u003e\u003c/script\u003e\n    \u003cscript src=\"https://cdn.jsdelivr.net/npm/katex/dist/katex.min.js\"\u003e\u003c/script\u003e\n    \u003cscript src=\"https://unpkg.com/markdown-it-dollarmath\"\u003e\u003c/script\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003cdiv id=\"demo\"\u003e\u003c/div\u003e\n    \u003cscript\u003e\n      const options = {\n        renderer: (content, { displayMode }) =\u003e\n          katex.renderToString(content, { displayMode, throwOnError: false })\n      }\n      const text = markdownit()\n        .use(window.markdownitDollarmath, options)\n        .render(\"$a = 1$\")\n      document.getElementById(\"demo\").innerHTML = text\n    \u003c/script\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n## Development\n\n### Features\n\n- TypeScript\n- Code Formatting ([prettier])\n- Code Linting ([eslint])\n- Testing and coverage ([vitest])\n- Continuous Integration ([GitHub Actions])\n- Bundled as both UMD and ESM ([rollup])\n- Upload as [NPM] package and [unpkg] CDN\n- Simple demonstration website ([GitHub Pages])\n\n### Getting Started\n\n1. Create a GitHub repository [from the template](https://docs.github.com/en/github-ae@latest/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/creating-a-repository-from-a-template).\n2. Replace package details in the following files:\n   - `package.json`\n   - `LICENSE`\n   - `README.md`\n   - `rollup.config.js`\n3. Install the `node_module` dependencies: `npm install` or `npm ci` (see [Install a project with a clean slate](https://docs.npmjs.com/cli/v7/commands/npm-ci)).\n4. Run code formatting; `npm run format`, and linting: `npm run lint:fix`.\n5. Run the unit tests; `npm test`, or with coverage; `npm test -- --coverage`.\n\nNow you can start to adapt the code in `src/index.ts` for your plugin, starting with the [markdown-it development recommendations](https://github.com/markdown-it/markdown-it/blob/master/docs/development.md).\n\nModify the test in `tests/fixtures.spec.ts`, to load your plugin, then the \"fixtures\" in `tests/fixtures`, to provide a set of potential Markdown inputs and expected HTML outputs.\n\nOn commits/PRs to the `main` branch, the GH actions will trigger, running the linting, unit tests, and build tests.\nAdditionally setup and uncomment the [codecov](https://about.codecov.io/) action in `.github/workflows/ci.yml`, to provide automated CI coverage.\n\nFinally, you can update the version of your package, e.g.: `npm version patch -m \"🚀 RELEASE: v%s\"` (patch/minor/major), push to GitHub; `git push --follow-tags`, build; `npm run build`, and publish; `npm publish`.\n\nFinally, you can adapt the HTML document in `docs/`, to load both markdown-it and the plugin (from [unpkg]), then render text from an input area.\nThis can be deployed by [GitHub Pages].\n\n[ci-badge]: https://github.com/executablebooks/markdown-it-dollarmath/workflows/CI/badge.svg\n[ci-link]: https://github.com/executablebooks/markdown-it--plugin-template/actions\n[npm-badge]: https://img.shields.io/npm/v/markdown-it-dollarmath.svg\n[npm-link]: https://www.npmjs.com/package/markdown-it-dollarmath\n[github actions]: https://docs.github.com/en/actions\n[github pages]: https://docs.github.com/en/pages\n[prettier]: https://prettier.io/\n[eslint]: https://eslint.org/\n[vitest]: https://vitest.dev/\n[rollup]: https://rollupjs.org\n[npm]: https://www.npmjs.com\n[unpkg]: https://unpkg.com/\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexecutablebooks%2Fmarkdown-it-dollarmath","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexecutablebooks%2Fmarkdown-it-dollarmath","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexecutablebooks%2Fmarkdown-it-dollarmath/lists"}