@mdit-vue/plugin-title 0.7.0 → 0.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdit-vue/plugin-title",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
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.7.0",
37
- "@mdit-vue/types": "0.7.0",
40
+ "@mdit-vue/shared": "0.7.1",
41
+ "@mdit-vue/types": "0.7.1",
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.11.3",
47
+ "c8": "^7.12.0",
44
48
  "markdown-it-emoji": "^2.0.2",
45
- "unbuild": "^0.7.4",
49
+ "unbuild": "^0.7.6",
46
50
  "vitest": "^0.18.1"
47
51
  },
48
52
  "publishConfig": {
49
53
  "access": "public"
50
54
  },
51
- "gitHead": "dd30ddd75ca461f775ccc35556132851ebc5e58a"
55
+ "gitHead": "b4b8bc6c054ea2dd9ad9ec7a37a58b5a2147b2bd"
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
@@ -1,11 +0,0 @@
1
- import { defineBuildConfig } from 'unbuild';
2
-
3
- export default defineBuildConfig({
4
- clean: true,
5
- declaration: true,
6
- entries: ['src/index'],
7
- rollup: {
8
- emitCJS: true,
9
- inlineDependencies: false,
10
- },
11
- });
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- import './types';
2
-
3
- export * from './title-plugin';
@@ -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,10 +0,0 @@
1
- export {};
2
-
3
- declare module '@mdit-vue/types' {
4
- interface MarkdownItEnv {
5
- /**
6
- * The title that extracted by `@mdit-vue/plugin-title`
7
- */
8
- title?: string;
9
- }
10
- }
@@ -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
- });