1
1
const ansiToSVG = require ( 'ansi-to-svg' ) ;
2
2
const emphasize = require ( 'emphasize' ) ;
3
3
const path = require ( 'path' ) ;
4
+
4
5
const options = {
5
6
fontSize : 12 ,
6
7
lineHeight : 25.6 ,
@@ -24,20 +25,26 @@ function highlightCode(code, lang = '') {
24
25
return emphasize . highlightAuto ( code ) ;
25
26
}
26
27
27
- function modifySVG ( svg ) {
28
- return svg . replace ( / v i e w B o x = " ( [ 0 - 9 . ] + ) , ( [ 0 - 9 . ] + ) , ( [ 0 - 9 . ] + ) , ( [ 0 - 9 . ] + ) " / , ( match , g1 , g2 , g3 , g4 ) => {
29
- return `height="${ g4 } " preserveAspectRatio="xMinYMax slice" viewBox="${ g1 } , ${ g2 } , 898, ${ g4 } "` ;
30
- } ) . replace ( / ( < r e c t x = " 0 " y = " 0 " w i d t h = " ) ( [ 0 - 9 . ] + ) ( " ) / , ( match , g1 , g2 , g3 ) => {
31
- return [ g1 , 898 , g3 ] . join ( '' ) ;
32
- } ) ;
28
+ function modifySVG ( svg ) {
29
+ return svg
30
+ . replace (
31
+ / v i e w B o x = " ( [ 0 - 9 . ] + ) , ( [ 0 - 9 . ] + ) , ( [ 0 - 9 . ] + ) , ( [ 0 - 9 . ] + ) " / ,
32
+ ( match , g1 , g2 , g3 , g4 ) => `height="${ g4 } " preserveAspectRatio="xMinYMax slice" viewBox="${ g1 } , ${ g2 } , 898, ${ g4 } "`
33
+ )
34
+ . replace ( / ( < r e c t x = " 0 " y = " 0 " w i d t h = " ) ( [ 0 - 9 . ] + ) ( " ) / , ( match , g1 , g2 , g3 ) => [ g1 , 898 , g3 ] . join ( '' ) ) ;
33
35
}
34
36
35
37
function codeToSVG ( code , range , { lang, theme = '3024.night' } ) {
36
38
const extractedCode = extract ( code , range ) ;
37
39
const highlightedCode = highlightCode ( extractedCode , lang ) ;
38
- return modifySVG ( ansiToSVG ( highlightedCode . value , Object . assign ( options , {
39
- colors : path . resolve ( __dirname , `../schemes/${ theme } .itermcolors` )
40
- } ) ) ) ;
40
+ return modifySVG (
41
+ ansiToSVG (
42
+ highlightedCode . value ,
43
+ Object . assign ( options , {
44
+ colors : path . resolve ( __dirname , `../schemes/${ theme } .itermcolors` )
45
+ } )
46
+ )
47
+ ) ;
41
48
}
42
49
43
50
module . exports = codeToSVG ;
0 commit comments