@mdit-vue/plugin-title 0.6.0 → 0.8.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/README.md +1 -0
- package/dist/index.d.ts +9 -6
- package/package.json +11 -7
- package/CHANGELOG.md +0 -20
- package/build.config.ts +0 -11
- package/src/index.ts +0 -3
- package/src/title-plugin.ts +0 -35
- package/src/types.ts +0 -7
- package/tests/title-plugin.spec.ts +0 -30
package/README.md
CHANGED
|
@@ -18,6 +18,7 @@ npm i @mdit-vue/plugin-title
|
|
|
18
18
|
```ts
|
|
19
19
|
import MarkdownIt from 'markdown-it';
|
|
20
20
|
import { titlePlugin } from '@mdit-vue/plugin-title';
|
|
21
|
+
import type { MarkdownItEnv } from '@mdit-vue/types';
|
|
21
22
|
|
|
22
23
|
const md = MarkdownIt({ html: true }).use(titlePlugin);
|
|
23
24
|
const env: MarkdownItEnv = {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { PluginSimple } from 'markdown-it';
|
|
2
2
|
|
|
3
|
-
declare module '@mdit-vue/types' {
|
|
4
|
-
interface MarkdownItEnv {
|
|
5
|
-
title?: string;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
|
|
9
3
|
/**
|
|
10
4
|
* Get markdown page title info
|
|
11
5
|
*
|
|
@@ -13,4 +7,13 @@ declare module '@mdit-vue/types' {
|
|
|
13
7
|
*/
|
|
14
8
|
declare const titlePlugin: PluginSimple;
|
|
15
9
|
|
|
10
|
+
declare module '@mdit-vue/types' {
|
|
11
|
+
interface MarkdownItEnv {
|
|
12
|
+
/**
|
|
13
|
+
* The title that extracted by `@mdit-vue/plugin-title`
|
|
14
|
+
*/
|
|
15
|
+
title?: string;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
16
19
|
export { titlePlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdit-vue/plugin-title",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "A markdown-it plugin to get markdown page title",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown-it",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"author": "meteorlxy <meteor.lxy@foxmail.com>",
|
|
21
|
+
"type": "module",
|
|
21
22
|
"exports": {
|
|
22
23
|
".": {
|
|
23
24
|
"types": "./dist/index.d.ts",
|
|
@@ -28,25 +29,28 @@
|
|
|
28
29
|
"main": "./dist/index.cjs",
|
|
29
30
|
"module": "./dist/index.mjs",
|
|
30
31
|
"types": "./dist/index.d.ts",
|
|
32
|
+
"files": [
|
|
33
|
+
"./dist"
|
|
34
|
+
],
|
|
31
35
|
"scripts": {
|
|
32
36
|
"build": "unbuild",
|
|
33
37
|
"test": "vitest"
|
|
34
38
|
},
|
|
35
39
|
"dependencies": {
|
|
36
|
-
"@mdit-vue/shared": "0.
|
|
37
|
-
"@mdit-vue/types": "0.
|
|
40
|
+
"@mdit-vue/shared": "0.8.0",
|
|
41
|
+
"@mdit-vue/types": "0.8.0",
|
|
38
42
|
"@types/markdown-it": "^12.2.3",
|
|
39
43
|
"markdown-it": "^13.0.1"
|
|
40
44
|
},
|
|
41
45
|
"devDependencies": {
|
|
42
46
|
"@types/markdown-it-emoji": "^2.0.2",
|
|
43
|
-
"c8": "^7.
|
|
47
|
+
"c8": "^7.12.0",
|
|
44
48
|
"markdown-it-emoji": "^2.0.2",
|
|
45
|
-
"unbuild": "^0.7.
|
|
46
|
-
"vitest": "^0.18.
|
|
49
|
+
"unbuild": "^0.7.6",
|
|
50
|
+
"vitest": "^0.18.1"
|
|
47
51
|
},
|
|
48
52
|
"publishConfig": {
|
|
49
53
|
"access": "public"
|
|
50
54
|
},
|
|
51
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "7fd357a18b8bcc347cf17e2e78da3b3ed4242e58"
|
|
52
56
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
# [0.6.0](https://github.com/mdit-vue/mdit-vue/compare/v0.5.0...v0.6.0) (2022-07-11)
|
|
7
|
-
|
|
8
|
-
### Features
|
|
9
|
-
|
|
10
|
-
- **types:** extract types from shared package ([5fc56ce](https://github.com/mdit-vue/mdit-vue/commit/5fc56ce6439159584e09e13ca9a6e87abe8f4389))
|
|
11
|
-
|
|
12
|
-
# [0.5.0](https://github.com/mdit-vue/mdit-vue/compare/v0.4.0...v0.5.0) (2022-07-06)
|
|
13
|
-
|
|
14
|
-
**Note:** Version bump only for package @mdit-vue/plugin-title
|
|
15
|
-
|
|
16
|
-
# [0.4.0](https://github.com/mdit-vue/mdit-vue/compare/v0.3.1...v0.4.0) (2022-07-02)
|
|
17
|
-
|
|
18
|
-
### Features
|
|
19
|
-
|
|
20
|
-
- **plugin-title:** add title plugin ([662e153](https://github.com/mdit-vue/mdit-vue/commit/662e153b74226df6db57531e71ab5f8d563da780))
|
package/build.config.ts
DELETED
package/src/index.ts
DELETED
package/src/title-plugin.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { resolveTitleFromToken } from '@mdit-vue/shared';
|
|
2
|
-
import type { MarkdownItEnv } from '@mdit-vue/types';
|
|
3
|
-
import type { PluginSimple } from 'markdown-it';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Get markdown page title info
|
|
7
|
-
*
|
|
8
|
-
* Extract it to env
|
|
9
|
-
*/
|
|
10
|
-
export const titlePlugin: PluginSimple = (md): void => {
|
|
11
|
-
let title: string;
|
|
12
|
-
|
|
13
|
-
// push the rule to the end of the chain
|
|
14
|
-
// resolve title from the parsed tokens
|
|
15
|
-
md.core.ruler.push('resolveTitle', (state) => {
|
|
16
|
-
const tokenIdx = state.tokens.findIndex((token) => token.tag === 'h1');
|
|
17
|
-
if (tokenIdx > -1) {
|
|
18
|
-
title = resolveTitleFromToken(state.tokens[tokenIdx + 1], {
|
|
19
|
-
shouldAllowHtml: false,
|
|
20
|
-
shouldEscapeText: false,
|
|
21
|
-
});
|
|
22
|
-
} else {
|
|
23
|
-
title = '';
|
|
24
|
-
}
|
|
25
|
-
return true;
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
// extract title to env
|
|
29
|
-
const render = md.render.bind(md);
|
|
30
|
-
md.render = (src, env: MarkdownItEnv = {}) => {
|
|
31
|
-
const result = render(src, env);
|
|
32
|
-
env.title = title;
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
};
|
package/src/types.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { MarkdownItEnv } from '@mdit-vue/types';
|
|
2
|
-
import MarkdownIt from 'markdown-it';
|
|
3
|
-
import emojiPlugin from 'markdown-it-emoji';
|
|
4
|
-
import { describe, expect, it } from 'vitest';
|
|
5
|
-
import { titlePlugin } from '../src';
|
|
6
|
-
|
|
7
|
-
describe('@mdit-vue/plugin-title > title-plugin', () => {
|
|
8
|
-
const md = MarkdownIt().use(emojiPlugin).use(titlePlugin);
|
|
9
|
-
|
|
10
|
-
describe('should extract title from h1 heading', () => {
|
|
11
|
-
const testCases = [
|
|
12
|
-
['# title from h1 :tada:', 'title from h1 🎉'],
|
|
13
|
-
['# title from h1 `foobar`', 'title from h1 foobar'],
|
|
14
|
-
];
|
|
15
|
-
|
|
16
|
-
testCases.forEach(([source, expected]) =>
|
|
17
|
-
it(source, () => {
|
|
18
|
-
const env: MarkdownItEnv = {};
|
|
19
|
-
md.render(source, env);
|
|
20
|
-
expect(env.title).toEqual(expected);
|
|
21
|
-
}),
|
|
22
|
-
);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('should extract empty title', () => {
|
|
26
|
-
const env: MarkdownItEnv = {};
|
|
27
|
-
md.render('', env);
|
|
28
|
-
expect(env.title).toEqual('');
|
|
29
|
-
});
|
|
30
|
-
});
|