File tree 3 files changed +14
-11
lines changed
3 files changed +14
-11
lines changed Original file line number Diff line number Diff line change
1
+ import type { HLJSApi } from 'highlight.js' ;
1
2
import { escapeHtml } from 'markdown-it/lib/common/utils' ;
2
- import { HighlightLangMap } from './typings' ;
3
+ import type { HighlightLangMap } from './typings' ;
3
4
4
5
export = function makeHighlight ( langs : HighlightLangMap = { } ) {
5
6
try {
6
7
// Important require.
7
8
// Because we want to have a posibility to run in projects without hljs dependency
8
- const hljs = require ( 'highlight.js' ) ;
9
+ const hljs : HLJSApi = require ( 'highlight.js/lib/core ' ) ;
9
10
10
11
Object . keys ( langs ) . forEach ( ( lang ) => {
11
12
hljs . registerLanguage ( lang , langs [ lang ] ) ;
12
13
} ) ;
13
14
14
15
return function highlight ( str : string , lang : string ) {
15
- let highlightedStr ;
16
+ let highlightedStr : string | undefined ;
16
17
const classNames = [ 'hljs' ] ;
17
18
18
19
if ( lang && hljs . getLanguage ( lang ) ) {
Original file line number Diff line number Diff line change 1
- import { LanguageFn } from 'highlight.js' ;
2
- import DefaultMarkdownIt from 'markdown-it' ;
3
- import DefaultStateCore from 'markdown-it/lib/rules_core/state_core' ;
4
- import { SanitizeOptions } from './sanitize' ;
5
- import { MarkdownItPluginCb } from './plugins/typings' ;
6
- import { LogLevels } from './log' ;
7
- import { ChangelogItem } from './plugins/changelog/types' ;
1
+ import type { LanguageFn } from 'highlight.js' ;
2
+ import type DefaultMarkdownIt from 'markdown-it' ;
3
+ import type DefaultStateCore from 'markdown-it/lib/rules_core/state_core' ;
4
+ import type { SanitizeOptions } from './sanitize' ;
5
+ import type { MarkdownItPluginCb } from './plugins/typings' ;
6
+ import type { LogLevels } from './log' ;
7
+ import type { ChangelogItem } from './plugins/changelog/types' ;
8
8
9
9
export interface MarkdownIt extends DefaultMarkdownIt {
10
10
assets ?: string [ ] ;
Original file line number Diff line number Diff line change 1
- import { dirname } from 'path' ;
1
+ import { dirname } from 'node:path' ;
2
+ import typescript from 'highlight.js/lib/languages/typescript' ;
2
3
import transform from '../src/transform' ;
3
4
4
5
const mocksPath = require . resolve ( './utils.ts' ) ;
@@ -7,6 +8,7 @@ const transformYfm = (text: string) => {
7
8
result : { html} ,
8
9
} = transform ( text , {
9
10
plugins : [ ] ,
11
+ highlightLangs : { ts : typescript } ,
10
12
path : mocksPath ,
11
13
root : dirname ( mocksPath ) ,
12
14
} ) ;
You can’t perform that action at this time.
0 commit comments