@mdit-vue/shared 0.4.0 → 0.7.0

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/CHANGELOG.md CHANGED
@@ -3,6 +3,20 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [0.7.0](https://github.com/mdit-vue/mdit-vue/compare/v0.6.0...v0.7.0) (2022-07-18)
7
+
8
+ **Note:** Version bump only for package @mdit-vue/shared
9
+
10
+ # [0.6.0](https://github.com/mdit-vue/mdit-vue/compare/v0.5.0...v0.6.0) (2022-07-11)
11
+
12
+ ### Features
13
+
14
+ - **types:** extract types from shared package ([5fc56ce](https://github.com/mdit-vue/mdit-vue/commit/5fc56ce6439159584e09e13ca9a6e87abe8f4389))
15
+
16
+ # [0.5.0](https://github.com/mdit-vue/mdit-vue/compare/v0.4.0...v0.5.0) (2022-07-06)
17
+
18
+ **Note:** Version bump only for package @mdit-vue/shared
19
+
6
20
  # [0.4.0](https://github.com/mdit-vue/mdit-vue/compare/v0.3.1...v0.4.0) (2022-07-02)
7
21
 
8
22
  **Note:** Version bump only for package @mdit-vue/shared
package/README.md CHANGED
@@ -1,32 +1,11 @@
1
1
  # @mdit-vue/shared
2
2
 
3
- [![npm](https://badgen.net/npm/v/@mdit-vue/shared)](https://www.npmjs.com/package/@mdit-vue/plugin-sfc)
3
+ [![npm](https://badgen.net/npm/v/@mdit-vue/shared)](https://www.npmjs.com/package/@mdit-vue/shared)
4
4
 
5
- Shared utils and types of mdit-vue.
5
+ Shared utils of mdit-vue.
6
6
 
7
7
  ## Install
8
8
 
9
9
  ```sh
10
10
  npm i @mdit-vue/shared
11
11
  ```
12
-
13
- ## Usage
14
-
15
- Add more properties to `env` via [TypeScript module augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation):
16
-
17
- ```ts
18
- declare module '@mdit-vue/shared' {
19
- interface MarkdownItEnv {
20
- foo?: string[];
21
- }
22
- }
23
- ```
24
-
25
- ```ts
26
- import MarkdownIt from 'markdown-it';
27
- import type { MarkdownItEnv } from '@mdit-vue/shared';
28
-
29
- const md = MarkdownIt({ html: true });
30
- const env: MarkdownItEnv = {};
31
- const rendered = md.render('raw markdown text', env);
32
- ```
package/dist/index.cjs CHANGED
@@ -27,10 +27,7 @@ const htmlUnescapeMap = {
27
27
  const htmlUnescapeRegexp = /&(amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g;
28
28
  const htmlUnescape = (str) => str.replace(htmlUnescapeRegexp, (char) => htmlUnescapeMap[char]);
29
29
 
30
- const resolveTitleFromToken = (token, {
31
- shouldAllowHtml,
32
- shouldEscapeText
33
- }) => {
30
+ const resolveTitleFromToken = (token, { shouldAllowHtml, shouldEscapeText }) => {
34
31
  const children = token.children ?? [];
35
32
  const titleTokenTypes = ["text", "emoji", "code_inline"];
36
33
  if (shouldAllowHtml) {
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { MarkdownItHeader } from '@mdit-vue/types';
1
2
  import Token from 'markdown-it/lib/token';
2
3
 
3
4
  /**
@@ -10,39 +11,53 @@ declare const htmlEscape: (str: string) => string;
10
11
  */
11
12
  declare const htmlUnescape: (str: string) => string;
12
13
 
13
- interface MarkdownItEnv {
14
- }
15
- interface MarkdownItHeader {
16
- level: number;
17
- title: string;
18
- slug: string;
19
- children: MarkdownItHeader[];
20
- }
21
-
22
- /**
23
- * Resolve headers from markdown-it tokens
24
- */
25
- declare const resolveHeadersFromTokens: (tokens: Token[], { level, shouldAllowHtml, shouldEscapeText, slugify, format, }: {
26
- level: number[];
14
+ interface ResolveTitleOptions {
15
+ /**
16
+ * Should allow inline HTML tags or not.
17
+ *
18
+ * If the result is going to be used as Vue template, it should allow inline
19
+ * HTML tags so that Vue custom components would be kept.
20
+ */
27
21
  shouldAllowHtml: boolean;
22
+ /**
23
+ * Should escape the text content or not.
24
+ *
25
+ * If the result is going to be used in HTML directly, it should be escaped
26
+ * so that the text content won't be wrongly treated as HTML tags.
27
+ */
28
28
  shouldEscapeText: boolean;
29
- slugify: (str: string) => string;
30
- format?: ((str: string) => string) | undefined;
31
- }) => MarkdownItHeader[];
32
-
29
+ }
33
30
  /**
34
31
  * Resolve header title from markdown-it token
35
32
  *
36
33
  * Typically using the next token of `heading_open` token
37
34
  */
38
- declare const resolveTitleFromToken: (token: Token, { shouldAllowHtml, shouldEscapeText, }: {
39
- shouldAllowHtml: boolean;
40
- shouldEscapeText: boolean;
41
- }) => string;
35
+ declare const resolveTitleFromToken: (token: Token, { shouldAllowHtml, shouldEscapeText }: ResolveTitleOptions) => string;
36
+
37
+ interface ResolveHeadersOptions extends ResolveTitleOptions {
38
+ /**
39
+ * Heading level that going to be resolved
40
+ */
41
+ level: number[];
42
+ /**
43
+ * A custom slugification function
44
+ *
45
+ * Would be ignored if the `id` attr of the token is set.
46
+ */
47
+ slugify: (str: string) => string;
48
+ /**
49
+ * A function for formatting headings
50
+ */
51
+ format?: (str: string) => string;
52
+ }
53
+ /**
54
+ * Resolve headers from markdown-it tokens
55
+ */
56
+ declare const resolveHeadersFromTokens: (tokens: Token[], { level, shouldAllowHtml, shouldEscapeText, slugify, format, }: ResolveHeadersOptions) => MarkdownItHeader[];
42
57
 
43
58
  /**
44
59
  * Default slugification function
45
60
  */
46
61
  declare const slugify: (str: string) => string;
47
62
 
48
- export { MarkdownItEnv, MarkdownItHeader, htmlEscape, htmlUnescape, resolveHeadersFromTokens, resolveTitleFromToken, slugify };
63
+ export { ResolveHeadersOptions, ResolveTitleOptions, htmlEscape, htmlUnescape, resolveHeadersFromTokens, resolveTitleFromToken, slugify };
package/dist/index.mjs CHANGED
@@ -23,10 +23,7 @@ const htmlUnescapeMap = {
23
23
  const htmlUnescapeRegexp = /&(amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g;
24
24
  const htmlUnescape = (str) => str.replace(htmlUnescapeRegexp, (char) => htmlUnescapeMap[char]);
25
25
 
26
- const resolveTitleFromToken = (token, {
27
- shouldAllowHtml,
28
- shouldEscapeText
29
- }) => {
26
+ const resolveTitleFromToken = (token, { shouldAllowHtml, shouldEscapeText }) => {
30
27
  const children = token.children ?? [];
31
28
  const titleTokenTypes = ["text", "emoji", "code_inline"];
32
29
  if (shouldAllowHtml) {
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@mdit-vue/shared",
3
- "version": "0.4.0",
3
+ "version": "0.7.0",
4
4
  "description": "Shared utils and types of mdit-vue",
5
5
  "keywords": [
6
6
  "markdown-it",
7
- "vue"
7
+ "vue",
8
+ "utils"
8
9
  ],
9
10
  "homepage": "https://github.com/mdit-vue",
10
11
  "bugs": {
@@ -31,16 +32,17 @@
31
32
  "test": "vitest"
32
33
  },
33
34
  "dependencies": {
35
+ "@mdit-vue/types": "0.7.0",
34
36
  "@types/markdown-it": "^12.2.3",
35
37
  "markdown-it": "^13.0.1"
36
38
  },
37
39
  "devDependencies": {
38
40
  "c8": "^7.11.3",
39
41
  "unbuild": "^0.7.4",
40
- "vitest": "^0.16.0"
42
+ "vitest": "^0.18.1"
41
43
  },
42
44
  "publishConfig": {
43
45
  "access": "public"
44
46
  },
45
- "gitHead": "744887e6f4733af8da2045625e72a476947cfc25"
47
+ "gitHead": "dd30ddd75ca461f775ccc35556132851ebc5e58a"
46
48
  }
package/src/index.ts CHANGED
@@ -3,4 +3,3 @@ export * from './html-unescape';
3
3
  export * from './resolve-headers-from-tokens';
4
4
  export * from './resolve-title-from-token';
5
5
  export * from './slugify';
6
- export * from './types';
@@ -1,6 +1,26 @@
1
+ import type { MarkdownItHeader } from '@mdit-vue/types';
1
2
  import type Token from 'markdown-it/lib/token';
2
3
  import { resolveTitleFromToken } from './resolve-title-from-token';
3
- import type { MarkdownItHeader } from './types';
4
+ import type { ResolveTitleOptions } from './resolve-title-from-token';
5
+
6
+ export interface ResolveHeadersOptions extends ResolveTitleOptions {
7
+ /**
8
+ * Heading level that going to be resolved
9
+ */
10
+ level: number[];
11
+
12
+ /**
13
+ * A custom slugification function
14
+ *
15
+ * Would be ignored if the `id` attr of the token is set.
16
+ */
17
+ slugify: (str: string) => string;
18
+
19
+ /**
20
+ * A function for formatting headings
21
+ */
22
+ format?: (str: string) => string;
23
+ }
4
24
 
5
25
  /**
6
26
  * Resolve headers from markdown-it tokens
@@ -13,13 +33,7 @@ export const resolveHeadersFromTokens = (
13
33
  shouldEscapeText,
14
34
  slugify,
15
35
  format,
16
- }: {
17
- level: number[];
18
- shouldAllowHtml: boolean;
19
- shouldEscapeText: boolean;
20
- slugify: (str: string) => string;
21
- format?: (str: string) => string;
22
- },
36
+ }: ResolveHeadersOptions,
23
37
  ): MarkdownItHeader[] => {
24
38
  // store the result of headers
25
39
  const headers: MarkdownItHeader[] = [];
@@ -1,6 +1,24 @@
1
1
  import type Token from 'markdown-it/lib/token';
2
2
  import { htmlEscape } from './html-escape';
3
3
 
4
+ export interface ResolveTitleOptions {
5
+ /**
6
+ * Should allow inline HTML tags or not.
7
+ *
8
+ * If the result is going to be used as Vue template, it should allow inline
9
+ * HTML tags so that Vue custom components would be kept.
10
+ */
11
+ shouldAllowHtml: boolean;
12
+
13
+ /**
14
+ * Should escape the text content or not.
15
+ *
16
+ * If the result is going to be used in HTML directly, it should be escaped
17
+ * so that the text content won't be wrongly treated as HTML tags.
18
+ */
19
+ shouldEscapeText: boolean;
20
+ }
21
+
4
22
  /**
5
23
  * Resolve header title from markdown-it token
6
24
  *
@@ -8,13 +26,7 @@ import { htmlEscape } from './html-escape';
8
26
  */
9
27
  export const resolveTitleFromToken = (
10
28
  token: Token,
11
- {
12
- shouldAllowHtml,
13
- shouldEscapeText,
14
- }: {
15
- shouldAllowHtml: boolean;
16
- shouldEscapeText: boolean;
17
- },
29
+ { shouldAllowHtml, shouldEscapeText }: ResolveTitleOptions,
18
30
  ): string => {
19
31
  // children of the token contains the parsed result of the heading title
20
32
  const children = token.children ?? [];
package/src/types.ts DELETED
@@ -1,11 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
2
- export interface MarkdownItEnv {
3
- // to be extended with module augmentation
4
- }
5
-
6
- export interface MarkdownItHeader {
7
- level: number;
8
- title: string;
9
- slug: string;
10
- children: MarkdownItHeader[];
11
- }