{"id":13727357,"url":"https://github.com/michael-klein/htmdx","last_synced_at":"2025-08-20T16:32:58.516Z","repository":{"id":42959493,"uuid":"229466965","full_name":"michael-klein/htmdx","owner":"michael-klein","description":"HTMDX: Lightweight runtime for mdx-like markdown","archived":false,"fork":false,"pushed_at":"2023-01-07T13:04:12.000Z","size":4138,"stargazers_count":88,"open_issues_count":24,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-09T08:18:59.512Z","etag":null,"topics":["javascript","markdown","mdx","preact","react"],"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/michael-klein.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}},"created_at":"2019-12-21T18:24:56.000Z","updated_at":"2024-11-20T05:27:47.000Z","dependencies_parsed_at":"2023-02-07T05:42:16.397Z","dependency_job_id":null,"html_url":"https://github.com/michael-klein/htmdx","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/michael-klein/htmdx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michael-klein%2Fhtmdx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michael-klein%2Fhtmdx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michael-klein%2Fhtmdx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michael-klein%2Fhtmdx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michael-klein","download_url":"https://codeload.github.com/michael-klein/htmdx/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michael-klein%2Fhtmdx/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271350071,"owners_count":24744400,"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","status":"online","status_checked_at":"2025-08-20T02:00:09.606Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["javascript","markdown","mdx","preact","react"],"created_at":"2024-08-03T01:03:51.668Z","updated_at":"2025-08-20T16:32:57.386Z","avatar_url":"https://github.com/michael-klein.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","📦 Legacy \u0026 Inactive Projects"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg alt=\"HTMDX logo\" src=\"./htmdx.svg\" width=\"100\" /\u003e\n\u003c/p\u003e\n\n# HTMDX: Lightweight runtime for mdx-like markdown\n\n\u003cimg alt=\"build badge\" src=\"https://github.com/michael-klein/htmdx/workflows/CI/badge.svg\" /\u003e [\u003cimg alt=\"npm\" src=\"https://img.shields.io/npm/v/htmdx\"\u003e](https://www.npmjs.com/package/htmdx)\n\nThis library is an attempt to provide a runtime to compile [mdx](https://github.com/mdx-js/mdx)-like markdown files (with the goal to support full JSX inside of markdown) using [htm](https://github.com/developit/htm) + [marked](https://github.com/markedjs/marked) that is much smaller in file-size as opposed to the official runtime (which we are not encouraged to use on actual websites).\n\n[Here is a simple example playground using HTMDX](https://michael-klein.github.io/htmdx/example/dist/index.html)\n\n## Usage\n\nSimple example:\n\n```javascript\nimport * as React from 'react';\nimport * as ReactDOM from 'react-dom';\nimport { htmdx } from 'htmdx';\nimport * as Prism from 'prismjs';\n\nfunction SomeComponent() {\n  return 'something';\n}\n\nconst markDownWithJSX = `\n  # Hello World\n\n  \u003cSomeComponent /\u003e\n\n  Mardown will be interpreted as tagged templates from htm:\n  \u003cinput type=\"text\" style=\\${{width: '100%'}} value=\\${this.state.inputValue || ''} onChange=\\${e =\u003e {this.setState({inputValue:e.target.value});console.log(e.target.value)}}/\u003e\n  We're also using the setState method and state property passed into using the thisValue options (see below)\n\n  With the transformJSXToHTM option enabled, you may also use normal brackets:\n  \u003cinput type=\"text\" style={{width: '100%'}} value={this.state.inputValue || ''} onChange={e =\u003e this.setState({inputValue:e.target.value})}/\u003e\n  \n  Here's some code with code highlighting:\n  \\`\\`\\`\n  function SomeComponent() {\n    return \"Some component ouput.\";\n  }\n  \\`\\`\\`\n`;\n\nfunction App() {\n  const [state, setState] = React.useState({});\n\n  return htmdx(\n    markDownWithJSX,\n    React.createElement, // provide a h function. You can also use HTMDX with preact or any other library that supports the format\n    {\n      components: { SomeComponent }, // provide components that will be available in markdown files,\n      configureMarked: (\n        marked // configure the underlying marked parser, e.x.: to add code highlighting:\n      ) =\u003e\n        marked.setOptions({\n          highlight: function(code) {\n            return Prism.highlight(\n              code,\n              Prism.languages.javascript,\n              'javascript'\n            ).replace(/\\n/g, '\u003cbr/\u003e');\n          },\n        }),\n      transformClassToClassname: true, // transforms class=\"some-class\" to className=\"some-class\" (default: true)\n      transformJSXToHTM: true, // transforms some JSX to htm template literal syntax (such as value={} to value=${}) (default: true)\n      thisValue: {\n        // the this value passed to the compiled JSX\n        state,\n        setState: newState =\u003e setState(Object.assign({}, state, newState)),\n      },\n    }\n  );\n}\n\nReactDOM.render(React.createElement(App), document.getElementById('root'));\n```\n\n[![Edit htmdx example](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/romantic-liskov-m4x35?fontsize=14\u0026hidenavigation=1\u0026theme=dark)\n\n### Pluggable MDX transforms\n\nYou can supply MDX transforms, which will be applied to mdx strings before anything else:\n\n```javascript\nhtmdx('# Hello World', React.createElement, {\n  mdxTransforms: [m =\u003e m.replace('# Hello World', '# foo')], // will replace # Hello world with # foo\n})\n```\n\n### Pluggable JSX transforms\n\nYou can supply JSX transforms which allow you to apply further transforms before the JSX pragma runs, like so:\n\n```javascript\nhtmdx('# Hello World', React.createElement, {\n  jsxTransforms: [\n    (props, type, children) =\u003e {\n      if (children \u0026\u0026 children[0] === 'Hello World') {\n        children[0] = 'Foo'; // this will output \u003ch1\u003eFoo\u003c/h1\u003e instead of \u003ch1\u003eHello World\u003c/h1\u003e now!\n      }\n      return [props, type, children];\n    },\n  ],\n})\n```\n\n### Overwriting normal generated html elements with components:\n\nYou can also provide components for basic html elements that are generated by the markdown compiler:\n\n```javascript\nhtmdx(\"# Hello World\", React.createElement, {\n  components: {\n    TestComponent,\n    h1: props =\u003e\n      html`\n        \u003ch1 style=${{ color: 'red' }}\u003e${props.children}\u003c/h1\u003e\n      `,\n  }\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichael-klein%2Fhtmdx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichael-klein%2Fhtmdx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichael-klein%2Fhtmdx/lists"}