@@ -2,8 +2,6 @@ import markdown from '@wcj/markdown-to-html';
2
2
import rehypeDocument from 'rehype-document' ;
3
3
import remarkGemoji from 'remark-gemoji' ;
4
4
import rehypeRaw from 'rehype-raw' ;
5
- import rehypeAttrs from 'rehype-attr' ;
6
- import rehypeKatex from 'rehype-katex' ;
7
5
import rehypeAutolinkHeadings from 'rehype-autolink-headings' ;
8
6
import rehypeSlug from 'rehype-slug' ;
9
7
import { htmlTagAddAttri } from './nodes/htmlTagAddAttri.mjs' ;
@@ -23,37 +21,41 @@ export function create(str = '', options = {}) {
23
21
let title = str . match ( / [ ^ = = = ] + (? = [ = = = ] ) / g) || [ ] ;
24
22
let description = str . match ( / \n = = = { 1 , } \n + ( [ \s \S ] * ?) \n / g) || [ ] ;
25
23
title = title [ 0 ] || '' ;
26
- description = ( description [ 0 ] || '' ) . replace ( / ^ \n [ = \n ] + / , '' ) . replace ( / \[ ( [ \s \S ] * ?) ? \] \( ( [ \s \S ] * ?) ? \) / g, '$1' ) . replace ( / \n / , '' ) ;
27
- const subTitle = options . filename && ! options . isHome ? `${ options . filename } cheatsheet & ` : ''
24
+ description = ( description [ 0 ] || '' )
25
+ . replace ( / ^ \n [ = \n ] + / , '' )
26
+ . replace ( / \[ ( [ \s \S ] * ?) ? \] \( ( [ \s \S ] * ?) ? \) / g, '$1' )
27
+ . replace ( / \n / , '' ) ;
28
+ const subTitle = options . filename && ! options . isHome ? `${ options . filename } cheatsheet & ` : '' ;
28
29
const mdOptions = {
29
30
showLineNumbers : false ,
30
31
hastNode : false ,
31
32
remarkPlugins : [ remarkGemoji ] ,
32
33
rehypePlugins : [
33
34
rehypeSlug ,
34
35
rehypeAutolinkHeadings ,
35
- [ rehypeDocument , {
36
+ [
37
+ rehypeDocument ,
38
+ {
36
39
title : `${ title ? `${ title } & ` : '' } ${ subTitle } Quick Reference` ,
37
- css : [ ...options . css ] ,
38
- link : [
39
- { rel : 'icon' , href : favicon , type : 'image/svg+xml' }
40
- ] ,
40
+ css : [ ...options . css ] ,
41
+ link : [ { rel : 'icon' , href : favicon , type : 'image/svg+xml' } ] ,
41
42
meta : [
42
43
{ description : `${ description } 为开发人员分享快速参考备忘单。` } ,
43
- { keywords : `Quick,Reference,cheatsheet,${ ! options . isHome && options . filename || '' } ` }
44
- ]
45
- } ]
44
+ { keywords : `Quick,Reference,cheatsheet,${ ( ! options . isHome && options . filename ) || '' } ` } ,
45
+ ] ,
46
+ } ,
47
+ ] ,
46
48
] ,
47
49
filterPlugins : ( type , plugins = [ ] ) => {
48
50
if ( type === 'rehype' ) {
49
- const dt = plugins . filter ( plug => {
51
+ const dt = plugins . filter ( ( plug ) => {
50
52
return / ( r e h y p e R a w ) / . test ( plug . name ) ? false : true ;
51
53
} ) ;
52
54
// 放在 rehypeDocument 前面
53
- dt . unshift ( rehypeRaw )
55
+ dt . unshift ( rehypeRaw ) ;
54
56
return dt ;
55
57
}
56
- return plugins
58
+ return plugins ;
57
59
} ,
58
60
rewrite : ( node , index , parent ) => {
59
61
rehypePreviewHTML ( node , parent ) ;
@@ -64,10 +66,10 @@ export function create(str = '', options = {}) {
64
66
rehypeUrls ( node ) ;
65
67
if ( node . children ) {
66
68
if ( node . type === 'element' && node . tagName === 'body' ) {
67
- const tocsData = getTocsTree ( [ ...node . children ] ) ;
69
+ const tocsData = getTocsTree ( [ ...node . children ] ) ;
68
70
if ( ! options . isHome ) {
69
71
const tocsMenus = getTocsTitleNode ( [ ...tocsData ] ) ;
70
- node . children = addTocsInWarp ( [ ...tocsData ] , getTocsTitleNodeWarpper ( tocsMenus ) )
72
+ node . children = addTocsInWarp ( [ ...tocsData ] , getTocsTitleNodeWarpper ( tocsMenus ) ) ;
71
73
} else {
72
74
node . children = tocsData ;
73
75
}
@@ -76,9 +78,8 @@ export function create(str = '', options = {}) {
76
78
node . children . push ( anchorPoint ( ) ) ;
77
79
}
78
80
}
79
- }
80
- }
81
-
81
+ } ,
82
+ } ;
82
83
83
84
return markdown ( str , mdOptions ) ;
84
- }
85
+ }
0 commit comments