Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
karesztrk committed Jul 24, 2024
0 parents commit 298c323
Show file tree
Hide file tree
Showing 13 changed files with 818 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# md4wc

A Web component for rendering Markdown to HTML.

## Features

- ⚡ Insane fast rendering using [md4w](https://github.com/ije/md4w) (written in Zig)
- ✨ Declarative usage
- 💡 Lightweight
- 📘 ESM modules

## Installation

```sh
npm install md4wc md4c
# or pnpm install md4wc md4c
```

## How to use

### Register

Register the `MarkdownContent` and optionally `MarkdownContext`.

```js
import { MarkdownContent } from "md4wc";
customElements.define("md-content", new MarkdownContent());
```

Or you can use the static helper

```js
import { MarkdownContent } from "md4wc";
class YourComponent extends MarkdownContent {
static {
this.register("md-content", YourComponent);
}
}

export default MarkdownContextComponent;
```

### Usage

Declare your markup and pass the `WASM` module path as `href`. This will initialize the `md4c` module under to hood. But you can do the same thing manually using `import { init } from "md4w`.

```html
<md-context href="/path/to/md4w.wasm">
<md-content></md-content>
</md-context>
```

```js
const md = this.querySelector("md-content");
md.dispatchEvent(new CustomEvent("render", { detail: "Markdown content" }));
```

## References

- https://developer.mozilla.org/en-US/docs/Web/API/Web_components

```
```
7 changes: 7 additions & 0 deletions jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "md4wc",
"version": "1.0.1",
"exports": {
".": "./src/index.js"
}
}
41 changes: 41 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "md4wc",
"repository": "https://github.com/karesztrk/md4wc",
"version": "1.0.1",
"description": "",
"type": "module",
"types": "./types/index.d.ts",
"module": "./dist/index.js",
"scripts": {
"build": "rollup -c && pnpm generate:types",
"generate:types": "node ./scripts/generate-types.js",
"prepublishOnly": "pnpm build"
},
"exports": {
".": {
"types": "./types/index.d.ts",
"browser": "./dist/index.js",
"default": "./dist/index.js"
},
"./package.json": "./package.json"
},
"files": [
"dist",
"types"
],
"author": "",
"license": "MIT",
"dependencies": {
"@karesztrk/webcomponent-base": "^1.0.9"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"dts-buddy": "^0.5.1",
"prettier": "^3.3.3",
"rollup": "^4.19.0"
},
"peerDependencies": {
"md4w": "^0.2.6"
}
}
Loading

0 comments on commit 298c323

Please sign in to comment.