@oiij/markdown-it 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,32 +1,12 @@
1
- # library-starter
1
+ # Use Markdown-it
2
2
 
3
- Features:
3
+ [![NPM version](https://img.shields.io/npm/v/@oiij/markdown-it)](https://www.npmjs.com/package/@oiij/markdown-it)
4
+ [![MIT-license](https://img.shields.io/npm/l/@oiij/markdown-it)](https://github.com/Eiog/@oiij/markdown-it/blob/main/LICENSE)
4
5
 
5
- - Bundle with [tsup](https://github.com/egoist/tsup)
6
- - Test with [vitest](https://vitest.dev)
7
-
8
- # Usage
9
-
10
- ### 安装
6
+ ## Usage
11
7
 
12
8
  ```bash
13
- pnpm add @oiij/v-charts
14
- ```
15
-
16
- ### 使用
17
-
18
- ```vue
19
- <script setup lang="ts">
20
- import { useMarkdownIt } from '@oiij/markdown-it'
21
-
22
- const { domRef, html } = useMarkdownIt('# Hello World')
23
- </script>
24
-
25
- <template>
26
- <div ref="domRef" style="width: 100%; height: 100%;" />
27
- </template>
9
+ pnpm add @oiij/markdown-it
28
10
  ```
29
11
 
30
- ## License
31
-
32
- MIT
12
+ [在线文档](https://oiij-use.vercel.app/examples/markdown-it/started)
package/dist/index.cjs CHANGED
@@ -1,75 +1,68 @@
1
- "use strict";
1
+ //#region rolldown:runtime
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
8
  var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+ const dompurify = __toESM(require("dompurify"));
25
+ const markdown_it = __toESM(require("markdown-it"));
26
+ const vue = __toESM(require("vue"));
29
27
 
30
- // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
33
- useMarkdownIt: () => useMarkdownIt
34
- });
35
- module.exports = __toCommonJS(index_exports);
36
- var import_markdown_it = __toESM(require("markdown-it"), 1);
37
- var import_vue = require("vue");
28
+ //#region src/index.ts
38
29
  function useMarkdownIt(defaultValue, options) {
39
- const value = (0, import_vue.ref)((0, import_vue.isRef)(defaultValue) ? (0, import_vue.toValue)(defaultValue.value) : (0, import_vue.isReactive)(defaultValue) ? (0, import_vue.toValue)(defaultValue) : defaultValue);
40
- if ((0, import_vue.isRef)(defaultValue)) {
41
- (0, import_vue.watchEffect)(() => {
42
- value.value = (0, import_vue.toValue)(defaultValue.value);
43
- });
44
- }
45
- const html = (0, import_vue.ref)("");
46
- const domRef = (0, import_vue.ref)();
47
- const md = (0, import_markdown_it.default)({
48
- ...options
49
- });
50
- function render(value2) {
51
- html.value = md.render(value2);
52
- if (domRef.value) {
53
- domRef.value.innerHTML = html.value;
54
- }
55
- }
56
- (0, import_vue.watch)(value, (v) => {
57
- render(v ?? "");
58
- });
59
- (0, import_vue.onMounted)(() => {
60
- if (value.value) {
61
- render(value.value);
62
- }
63
- });
64
- return {
65
- value,
66
- html,
67
- domRef,
68
- md,
69
- render
70
- };
30
+ const { manual = false, domPurify = true,..._options } = options ?? {};
31
+ const value = (0, vue.ref)((0, vue.isRef)(defaultValue) ? (0, vue.toValue)(defaultValue.value) : (0, vue.isReactive)(defaultValue) ? (0, vue.toValue)(defaultValue) : defaultValue);
32
+ if ((0, vue.isRef)(defaultValue)) (0, vue.watchEffect)(() => {
33
+ value.value = (0, vue.toValue)(defaultValue.value);
34
+ });
35
+ const html = (0, vue.ref)("");
36
+ const domRef = (0, vue.ref)();
37
+ const md = (0, markdown_it.default)({ ..._options });
38
+ function render(value$1) {
39
+ const mdValue = md.render(value$1);
40
+ html.value = domPurify ? dompurify.default.sanitize(mdValue) : mdValue;
41
+ if (domRef.value) domRef.value.innerHTML = html.value;
42
+ else {
43
+ const unWatch = (0, vue.watch)(domRef, (v) => {
44
+ if (v) {
45
+ v.innerHTML = html.value;
46
+ unWatch();
47
+ }
48
+ });
49
+ }
50
+ return html.value;
51
+ }
52
+ if (!manual) {
53
+ render(value.value ?? "");
54
+ (0, vue.watch)(value, (v) => {
55
+ render(v ?? "");
56
+ });
57
+ }
58
+ return {
59
+ value,
60
+ html,
61
+ domRef,
62
+ md,
63
+ render
64
+ };
71
65
  }
72
- // Annotate the CommonJS export names for ESM import in node:
73
- 0 && (module.exports = {
74
- useMarkdownIt
75
- });
66
+
67
+ //#endregion
68
+ exports.useMarkdownIt = useMarkdownIt;
package/dist/index.d.cts CHANGED
@@ -1,14 +1,18 @@
1
- import markdownIt, { Options } from 'markdown-it';
2
- export { Options } from 'markdown-it';
3
- import { Ref } from 'vue';
1
+ import markdownIt, { Options } from "markdown-it";
2
+ import { Ref } from "vue";
4
3
 
5
- interface MarkdownItReturns {
6
- value: Ref<string | undefined>;
7
- html: Ref<string>;
8
- domRef: Ref<HTMLElement | undefined>;
9
- md: markdownIt;
10
- render: (value: string) => void;
11
- }
12
- declare function useMarkdownIt(defaultValue?: Ref<string> | string, options?: Options): MarkdownItReturns;
13
-
14
- export { type MarkdownItReturns, useMarkdownIt };
4
+ //#region src/index.d.ts
5
+ type MarkDownItOptions = Options & {
6
+ manual?: boolean;
7
+ domPurify?: boolean;
8
+ };
9
+ declare function useMarkdownIt(defaultValue?: Ref<string> | string, options?: MarkDownItOptions): {
10
+ value: Ref<string | undefined, string | undefined>;
11
+ html: Ref<string, string>;
12
+ domRef: Ref<HTMLElement | undefined, HTMLElement | undefined>;
13
+ md: markdownIt;
14
+ render: (value: string) => string;
15
+ };
16
+ type MarkdownItReturns = ReturnType<typeof useMarkdownIt>;
17
+ //#endregion
18
+ export { MarkDownItOptions, MarkdownItReturns, useMarkdownIt };
package/dist/index.d.ts CHANGED
@@ -1,14 +1,18 @@
1
- import markdownIt, { Options } from 'markdown-it';
2
- export { Options } from 'markdown-it';
3
- import { Ref } from 'vue';
1
+ import markdownIt, { Options } from "markdown-it";
2
+ import { Ref } from "vue";
4
3
 
5
- interface MarkdownItReturns {
6
- value: Ref<string | undefined>;
7
- html: Ref<string>;
8
- domRef: Ref<HTMLElement | undefined>;
9
- md: markdownIt;
10
- render: (value: string) => void;
11
- }
12
- declare function useMarkdownIt(defaultValue?: Ref<string> | string, options?: Options): MarkdownItReturns;
13
-
14
- export { type MarkdownItReturns, useMarkdownIt };
4
+ //#region src/index.d.ts
5
+ type MarkDownItOptions = Options & {
6
+ manual?: boolean;
7
+ domPurify?: boolean;
8
+ };
9
+ declare function useMarkdownIt(defaultValue?: Ref<string> | string, options?: MarkDownItOptions): {
10
+ value: Ref<string | undefined, string | undefined>;
11
+ html: Ref<string, string>;
12
+ domRef: Ref<HTMLElement | undefined, HTMLElement | undefined>;
13
+ md: markdownIt;
14
+ render: (value: string) => string;
15
+ };
16
+ type MarkdownItReturns = ReturnType<typeof useMarkdownIt>;
17
+ //#endregion
18
+ export { MarkDownItOptions, MarkdownItReturns, useMarkdownIt };
package/dist/index.js CHANGED
@@ -1,40 +1,45 @@
1
- // src/index.ts
1
+ import DOMPurify from "dompurify";
2
2
  import markdownIt from "markdown-it";
3
- import { isReactive, isRef, onMounted, ref, toValue, watch, watchEffect } from "vue";
3
+ import { isReactive, isRef, ref, toValue, watch, watchEffect } from "vue";
4
+
5
+ //#region src/index.ts
4
6
  function useMarkdownIt(defaultValue, options) {
5
- const value = ref(isRef(defaultValue) ? toValue(defaultValue.value) : isReactive(defaultValue) ? toValue(defaultValue) : defaultValue);
6
- if (isRef(defaultValue)) {
7
- watchEffect(() => {
8
- value.value = toValue(defaultValue.value);
9
- });
10
- }
11
- const html = ref("");
12
- const domRef = ref();
13
- const md = markdownIt({
14
- ...options
15
- });
16
- function render(value2) {
17
- html.value = md.render(value2);
18
- if (domRef.value) {
19
- domRef.value.innerHTML = html.value;
20
- }
21
- }
22
- watch(value, (v) => {
23
- render(v ?? "");
24
- });
25
- onMounted(() => {
26
- if (value.value) {
27
- render(value.value);
28
- }
29
- });
30
- return {
31
- value,
32
- html,
33
- domRef,
34
- md,
35
- render
36
- };
7
+ const { manual = false, domPurify = true,..._options } = options ?? {};
8
+ const value = ref(isRef(defaultValue) ? toValue(defaultValue.value) : isReactive(defaultValue) ? toValue(defaultValue) : defaultValue);
9
+ if (isRef(defaultValue)) watchEffect(() => {
10
+ value.value = toValue(defaultValue.value);
11
+ });
12
+ const html = ref("");
13
+ const domRef = ref();
14
+ const md = markdownIt({ ..._options });
15
+ function render(value$1) {
16
+ const mdValue = md.render(value$1);
17
+ html.value = domPurify ? DOMPurify.sanitize(mdValue) : mdValue;
18
+ if (domRef.value) domRef.value.innerHTML = html.value;
19
+ else {
20
+ const unWatch = watch(domRef, (v) => {
21
+ if (v) {
22
+ v.innerHTML = html.value;
23
+ unWatch();
24
+ }
25
+ });
26
+ }
27
+ return html.value;
28
+ }
29
+ if (!manual) {
30
+ render(value.value ?? "");
31
+ watch(value, (v) => {
32
+ render(v ?? "");
33
+ });
34
+ }
35
+ return {
36
+ value,
37
+ html,
38
+ domRef,
39
+ md,
40
+ render
41
+ };
37
42
  }
38
- export {
39
- useMarkdownIt
40
- };
43
+
44
+ //#endregion
45
+ export { useMarkdownIt };
package/package.json CHANGED
@@ -1,91 +1,56 @@
1
- {
2
- "name": "@oiij/markdown-it",
3
- "type": "module",
4
- "version": "0.0.1",
5
- "description": "A Vue Composable for markdown-it",
6
- "author": "oiij",
7
- "license": "MIT",
8
- "homepage": "https://github.com/oiij/markdown-it",
9
- "repository": {
10
- "type": "git",
11
- "url": "git@github.com:oiij/markdown-it.git"
12
- },
13
- "bugs": "https://github.com/oiij/markdown-it/issues",
14
- "keywords": [
15
- "markdown-it"
16
- ],
17
- "sideEffects": false,
18
- "exports": {
19
- ".": {
20
- "types": "./dist/index.d.ts",
21
- "import": "./dist/index.js",
22
- "require": "./dist/index.cjs"
23
- }
24
- },
25
- "main": "./dist/index.js",
26
- "module": "./dist/index.js",
27
- "types": "./dist/index.d.ts",
28
- "files": [
29
- "LICENSE",
30
- "README.md",
31
- "dist",
32
- "package.json"
33
- ],
34
- "scripts": {
35
- "dev": "tsup --watch",
36
- "build": "tsc --noEmit && tsup",
37
- "lint": "eslint .",
38
- "lint:fix": "eslint . --fix",
39
- "prepublishOnly": "pnpm build",
40
- "release": "bumpp && npm publish",
41
- "awe": "pnpx are-we-esm",
42
- "nmi": "pnpx node-modules-inspector",
43
- "start": "esno src/index.ts",
44
- "test": "vitest",
45
- "update:deps": "taze -w && pnpm i",
46
- "type:check": "tsc --noEmit",
47
- "cz": "czg",
48
- "commit": "git pull && git add -A && pnpm cz && git push",
49
- "link": "pnpm link --global",
50
- "preinstall": "npx only-allow pnpm"
51
- },
52
- "peerDependencies": {
53
- "@vueuse/core": "^13.1.0",
54
- "markdown-it": "^14.1.0",
55
- "vue": "^3.5.13"
56
- },
57
- "devDependencies": {
58
- "@antfu/eslint-config": "^4.12.0",
59
- "@oiij/tsconfig": "^0.0.1",
60
- "@types/markdown-it": "^14.1.2",
61
- "@types/node": "^22.14.1",
62
- "@vitest/ui": "^3.1.2",
63
- "@vueuse/core": "^13.1.0",
64
- "bumpp": "^10.1.0",
65
- "commitlint": "^19.8.0",
66
- "cz-git": "^1.11.1",
67
- "czg": "^1.11.1",
68
- "eslint": "^9.25.1",
69
- "eslint-plugin-format": "^1.0.1",
70
- "esno": "^4.8.0",
71
- "lint-staged": "^15.5.1",
72
- "markdown-it": "^14.1.0",
73
- "simple-git-hooks": "^2.12.1",
74
- "taze": "^19.0.4",
75
- "tsup": "^8.4.0",
76
- "typescript": "^5.8.3",
77
- "vitest": "^3.1.2",
78
- "vue": "^3.5.13"
79
- },
80
- "simple-git-hooks": {
81
- "pre-commit": "pnpm lint-staged && pnpm type:check"
82
- },
83
- "lint-staged": {
84
- "*.{js,jsx,ts,tsx}": [
85
- "pnpm lint:fix"
86
- ]
87
- },
88
- "publishConfig": {
89
- "access": "public"
90
- }
91
- }
1
+ {
2
+ "name": "@oiij/markdown-it",
3
+ "type": "module",
4
+ "version": "0.0.2",
5
+ "description": "A Vue Composable for markdown-it",
6
+ "author": "oiij",
7
+ "license": "MIT",
8
+ "homepage": "https://github.com/oiij/use",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git@github.com:oiij/use.git"
12
+ },
13
+ "bugs": "https://github.com/oiij/use/issues",
14
+ "keywords": [
15
+ "@oiij/use",
16
+ "markdown-it"
17
+ ],
18
+ "sideEffects": false,
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js",
23
+ "require": "./dist/index.cjs"
24
+ }
25
+ },
26
+ "main": "./dist/index.js",
27
+ "module": "./dist/index.js",
28
+ "types": "./dist/index.d.ts",
29
+ "files": [
30
+ "LICENSE",
31
+ "README.md",
32
+ "dist",
33
+ "package.json"
34
+ ],
35
+ "peerDependencies": {
36
+ "@vueuse/core": "^13.1.0",
37
+ "dompurify": "^3.2.5",
38
+ "markdown-it": "^14.1.0",
39
+ "vue": "^3.5.13"
40
+ },
41
+ "devDependencies": {
42
+ "@types/markdown-it": "^14.1.2",
43
+ "@vueuse/core": "^13.3.0",
44
+ "dompurify": "^3.2.6",
45
+ "markdown-it": "^14.1.0",
46
+ "vue": "^3.5.16"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public"
50
+ },
51
+ "scripts": {
52
+ "dev": "tsdown --watch",
53
+ "build": "tsc --noEmit && tsdown",
54
+ "bumpp": "bumpp --no-push"
55
+ }
56
+ }