@oiij/markdown-it 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 oiij <https://github.com/oiij>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # library-starter
2
+
3
+ Features:
4
+
5
+ - Bundle with [tsup](https://github.com/egoist/tsup)
6
+ - Test with [vitest](https://vitest.dev)
7
+
8
+ # Usage
9
+
10
+ ### 安装
11
+
12
+ ```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>
28
+ ```
29
+
30
+ ## License
31
+
32
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
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
+ 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;
19
+ };
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);
29
+
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");
38
+ 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
+ };
71
+ }
72
+ // Annotate the CommonJS export names for ESM import in node:
73
+ 0 && (module.exports = {
74
+ useMarkdownIt
75
+ });
@@ -0,0 +1,14 @@
1
+ import markdownIt, { Options } from 'markdown-it';
2
+ export { Options } from 'markdown-it';
3
+ import { Ref } from 'vue';
4
+
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 };
@@ -0,0 +1,14 @@
1
+ import markdownIt, { Options } from 'markdown-it';
2
+ export { Options } from 'markdown-it';
3
+ import { Ref } from 'vue';
4
+
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 };
package/dist/index.js ADDED
@@ -0,0 +1,40 @@
1
+ // src/index.ts
2
+ import markdownIt from "markdown-it";
3
+ import { isReactive, isRef, onMounted, ref, toValue, watch, watchEffect } from "vue";
4
+ 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
+ };
37
+ }
38
+ export {
39
+ useMarkdownIt
40
+ };
package/package.json ADDED
@@ -0,0 +1,91 @@
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
+ }