-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
853 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
zig-out | ||
*.wasm | ||
*.zip | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[submodule "vendor/md4c"] | ||
path = vendor/md4c | ||
[submodule "md4c"] | ||
path = packages/core/vendor/md4c | ||
url = https://github.com/mity/md4c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,17 @@ | ||
{ | ||
"name": "md4w", | ||
"description": "A Markdown renderer written in Zig & C, compiled to WebAssymbly for all JS runtimes.", | ||
"version": "0.2.6", | ||
"name": "md4w-monorepo", | ||
"version": "1.0.0", | ||
"description": "", | ||
"type": "module", | ||
"module": "./js/index.js", | ||
"main": "./js/index.js", | ||
"types": "./js/md4w.d.ts", | ||
"exports": { | ||
".": { | ||
"unwasm": "./js/unwasm.js", | ||
"workerd": "./js/workerd.js", | ||
"import": "./js/index.js", | ||
"types": "./js/md4w.d.ts" | ||
} | ||
"license": "MIT", | ||
"packageManager": "[email protected]", | ||
"engines": { | ||
"pnpm": "^9.0.0" | ||
}, | ||
"scripts": { | ||
"prepublishOnly": "zig build" | ||
}, | ||
"files": [ | ||
"js/", | ||
"README.md" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/ije/md4w" | ||
}, | ||
"license": "MIT" | ||
"scripts": {}, | ||
"devDependencies": {} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "md4w", | ||
"description": "A Markdown renderer written in Zig & C, compiled to WebAssymbly for all JS runtimes.", | ||
"version": "0.2.6", | ||
"type": "module", | ||
"module": "./js/index.js", | ||
"main": "./js/index.js", | ||
"types": "./js/md4w.d.ts", | ||
"exports": { | ||
".": { | ||
"unwasm": "./js/unwasm.js", | ||
"workerd": "./js/workerd.js", | ||
"import": "./js/index.js", | ||
"types": "./js/md4w.d.ts" | ||
} | ||
}, | ||
"scripts": { | ||
"prepublishOnly": "zig build" | ||
}, | ||
"files": [ | ||
"js/", | ||
"README.md" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/ije/md4w" | ||
}, | ||
"license": "MIT" | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
Submodule md4c
updated
from 000000 to 481fbf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
``` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": "workspace:*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import terser from "@rollup/plugin-terser"; | ||
import resolve from "@rollup/plugin-node-resolve"; | ||
import { defineConfig } from "rollup"; | ||
|
||
export default defineConfig({ | ||
input: "src/index.js", | ||
output: [ | ||
{ | ||
dir: "dist", | ||
format: "es", | ||
exports: "named", | ||
preserveModules: true, | ||
preserveModulesRoot: "src", | ||
sourcemap: true, | ||
}, | ||
], | ||
external: ["md4w"], | ||
plugins: [resolve(), terser()], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import fs from "node:fs"; | ||
import { fileURLToPath } from "node:url"; | ||
import { createBundle } from "dts-buddy"; | ||
|
||
const dir = fileURLToPath(new URL("..", import.meta.url)); | ||
const pkg = JSON.parse(fs.readFileSync(`${dir}/package.json`, "utf-8")); | ||
|
||
await createBundle({ | ||
output: `${dir}/types/index.d.ts`, | ||
modules: { | ||
[pkg.name]: `${dir}/src/index.d.ts`, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { mdToHtml } from "md4w"; | ||
import { LightElement } from "@karesztrk/webcomponent-base"; | ||
|
||
class MarkdownContent extends LightElement { | ||
/** | ||
* @type {string| undefined} content | ||
*/ | ||
content; | ||
|
||
constructor() { | ||
super(); | ||
|
||
this.addEventListener("render", (e) => { | ||
if (e instanceof CustomEvent) { | ||
const content = e.detail; | ||
this.content = content; | ||
this.render(); | ||
} | ||
}); | ||
} | ||
|
||
render() { | ||
if (this.content) { | ||
this.innerHTML = mdToHtml(this.content); | ||
} | ||
} | ||
} | ||
|
||
export default MarkdownContent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { init } from "md4w"; | ||
import { LightElement } from "@karesztrk/webcomponent-base"; | ||
|
||
class MarkdownContext extends LightElement { | ||
constructor() { | ||
super(); | ||
this.init(); | ||
} | ||
|
||
/** | ||
* Initializes the context. | ||
* @returns {Promise<void>} href | ||
*/ | ||
init() { | ||
return new Promise((resolve, reject) => { | ||
if (this.href) { | ||
init(this.href) | ||
.then(() => { | ||
resolve(); | ||
}) | ||
.catch(() => reject()); | ||
} else { | ||
reject(); | ||
} | ||
}); | ||
} | ||
|
||
get href() { | ||
return this.getAttribute("href"); | ||
} | ||
|
||
render() {} | ||
} | ||
|
||
export default MarkdownContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import MarkdownContext from "./MarkdownContext"; | ||
import MarkdownContent from "./MarkdownContent"; | ||
|
||
export { MarkdownContext, MarkdownContent }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"include": ["./*.js", "./src/"], | ||
"compilerOptions": { | ||
"module": "esnext", | ||
"lib": ["esnext", "dom", "dom.iterable"], | ||
"target": "esnext", | ||
"moduleResolution": "bundler", | ||
"noEmit": true, | ||
"resolveJsonModule": true, | ||
"noEmitOnError": true, | ||
"noErrorTruncation": true, | ||
"allowSyntheticDefaultImports": true, | ||
"verbatimModuleSyntax": true, | ||
"strict": true, | ||
"allowJs": true, | ||
"checkJs": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
declare module 'md4wc' { | ||
import type { LightElement } from '@karesztrk/webcomponent-base'; | ||
export default MarkdownContext; | ||
class MarkdownContext extends LightElement { | ||
/** | ||
* Initializes the context. | ||
* @returns href | ||
*/ | ||
init(): Promise<void>; | ||
get href(): string | null; | ||
} | ||
export default MarkdownContent; | ||
class MarkdownContent extends LightElement { | ||
/** | ||
* @type {string| undefined} content | ||
*/ | ||
content: string | undefined; | ||
} | ||
|
||
export { MarkdownContext, MarkdownContent }; | ||
} | ||
|
||
//# sourceMappingURL=index.d.ts.map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"version": 3, | ||
"file": "index.d.ts", | ||
"names": [], | ||
"sources": [], | ||
"sourcesContent": [], | ||
"mappings": "", | ||
"ignoreList": [] | ||
} |
Oops, something went wrong.