@mdit-vue/plugin-title 0.7.0 → 0.9.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 -1
- package/dist/index.d.ts +7 -7
- package/package.json +11 -7
- package/CHANGELOG.md +0 -24
- package/build.config.ts +0 -11
- package/src/index.ts +0 -3
- package/src/title-plugin.ts +0 -35
- package/src/types.ts +0 -10
- package/tests/title-plugin.spec.ts +0 -30
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
A [markdown-it](https://github.com/markdown-it/markdown-it) plugin to get page title.
|
|
7
7
|
|
|
8
|
-
-
|
|
8
|
+
- Extracts title (the content of the first level-1 heading) into markdown-it `env.title`.
|
|
9
9
|
|
|
10
10
|
## Install
|
|
11
11
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { PluginSimple } from 'markdown-it';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Get markdown page title info
|
|
5
|
+
*
|
|
6
|
+
* Extract it into env
|
|
7
|
+
*/
|
|
8
|
+
declare const titlePlugin: PluginSimple;
|
|
9
|
+
|
|
3
10
|
declare module '@mdit-vue/types' {
|
|
4
11
|
interface MarkdownItEnv {
|
|
5
12
|
/**
|
|
@@ -9,11 +16,4 @@ declare module '@mdit-vue/types' {
|
|
|
9
16
|
}
|
|
10
17
|
}
|
|
11
18
|
|
|
12
|
-
/**
|
|
13
|
-
* Get markdown page title info
|
|
14
|
-
*
|
|
15
|
-
* Extract it to env
|
|
16
|
-
*/
|
|
17
|
-
declare const titlePlugin: PluginSimple;
|
|
18
|
-
|
|
19
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.9.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.9.0",
|
|
41
|
+
"@mdit-vue/types": "0.9.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.
|
|
49
|
+
"unbuild": "^0.7.6",
|
|
50
|
+
"vitest": "^0.19.1"
|
|
47
51
|
},
|
|
48
52
|
"publishConfig": {
|
|
49
53
|
"access": "public"
|
|
50
54
|
},
|
|
51
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "4279fc7ac1db0b585ffb395f55a07038af2a7263"
|
|
52
56
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,24 +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.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/plugin-title
|
|
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/plugin-title
|
|
19
|
-
|
|
20
|
-
# [0.4.0](https://github.com/mdit-vue/mdit-vue/compare/v0.3.1...v0.4.0) (2022-07-02)
|
|
21
|
-
|
|
22
|
-
### Features
|
|
23
|
-
|
|
24
|
-
- **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
|
-
});
|