diff --git a/README.md b/README.md index 5b59d08..0c039d3 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,20 @@ Provides the `x-safehtml` directive, which sanitizes reactive HTML with DOMPurif ``` +**[@ramstack/alpinegear-markdown](https://www.npmjs.com/package/@ramstack/alpinegear-markdown)** ([README](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/markdown))
+Provides the `x-markdown` directive, which renders reactive Markdown with TanStack Markdown. + +```html +
+
+ +
+ ## Rendered from the element content +
+
+``` + + **[@ramstack/alpinegear-hotkey](https://www.npmjs.com/package/@ramstack/alpinegear-hotkey)** ([README](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/hotkey))
Provides the `x-hotkey` directive, allowing easily handle keyboard shortcuts. diff --git a/package.json b/package.json index 8118baf..3d90baf 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "@rollup/plugin-replace": "^6.0.3", "@rollup/plugin-terser": "^1.0.0", "@rollup/plugin-virtual": "^3.0.2", + "@tanstack/markdown": "^0.0.14", "@testing-library/dom": "^10.4.1", "@testing-library/jest-dom": "^7.0.1", "@vitest/coverage-v8": "^5.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b57a718..4a735f6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -36,6 +36,9 @@ importers: '@rollup/plugin-virtual': specifier: ^3.0.2 version: 3.0.2(rollup@4.63.1) + '@tanstack/markdown': + specifier: ^0.0.14 + version: 0.0.14 '@testing-library/dom': specifier: ^10.4.1 version: 10.4.1 @@ -544,6 +547,17 @@ packages: resolution: {integrity: sha512-fCTuZK4QBa+39Oz9l4OGfJfz+GpwCp3AqO7Zch3to99xHPgstVsRFpeQ8LNd2o1Gv8raL2mCFwiaHh7bFSp5DQ==} engines: {node: '>=22'} + '@tanstack/markdown@0.0.14': + resolution: {integrity: sha512-NNjOoA7Zbmh3LG6MTxTBX3zM8sGe5bMfH3xxX5oCt1zh75TiCiaQFoQ4FKSNNhVKqpD0zzNd+qNdmA+sXR5XTw==} + peerDependencies: + octane: '>=0.1.12' + react: '>=18' + peerDependenciesMeta: + octane: + optional: true + react: + optional: true + '@testing-library/dom@10.4.1': resolution: {integrity: sha512-o4PXJQidqJl82ckFaXUeoAW+XysPLauYI43Abki5hABd853iMhitooc6znOnczgbTYmEP6U6/y1ZyKAIsvMKGg==} engines: {node: '>=18'} @@ -2189,6 +2203,8 @@ snapshots: '@simple-libs/stream-utils@2.0.0': {} + '@tanstack/markdown@0.0.14': {} + '@testing-library/dom@10.4.1': dependencies: '@babel/code-frame': 7.29.7 diff --git a/rollup.config.js b/rollup.config.js index 68b6be5..43d743c 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -91,7 +91,11 @@ function create_configuration({ plugin_name, input, format, optimize }) { function remove_comments() { return { name: "remove_comments", - transform(source) { + transform(source, id) { + if (id.includes("node_modules")) { + return; + } + return { code: strip_comments(source, {}) }; diff --git a/src/plugins/markdown/README.md b/src/plugins/markdown/README.md new file mode 100644 index 0000000..9829117 --- /dev/null +++ b/src/plugins/markdown/README.md @@ -0,0 +1,106 @@ +# @ramstack/alpinegear-markdown + +`@ramstack/alpinegear-markdown` provides the `x-markdown` Alpine.js directive. +It renders Markdown with [TanStack Markdown](https://github.com/TanStack/markdown), which is bundled into the plugin. + +## Installation + +### Using CDN + +Include the plugin before Alpine.js: + +```html + + +``` + +### Using NPM + +```bash +npm install --save @ramstack/alpinegear-markdown +``` + +```js +import Alpine from "alpinejs"; +import markdown from "@ramstack/alpinegear-markdown"; + +Alpine.plugin(markdown); +Alpine.start(); +``` + +## Usage + +### Expression + +```html +
+
+
+``` + +Whenever `content` changes, the directive renders the new value and replaces the element's contents. + +### Element content + +Use the `.content` modifier to render the element's own text as Markdown. +The `.static` modifier is an alias: + +```html +
+ # Hello + + Some **bold** text +
+``` + +The source is taken from `textContent` once, when the directive is initialized. + +The directive must not be used on a `