11const ansiToSVG = require ( 'ansi-to-svg' ) ;
22const emphasize = require ( 'emphasize' ) ;
33const path = require ( 'path' ) ;
4+
45const options = {
56 fontSize : 12 ,
67 lineHeight : 25.6 ,
@@ -24,20 +25,26 @@ function highlightCode(code, lang = '') {
2425 return emphasize . highlightAuto ( code ) ;
2526}
2627
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 ( '' ) ) ;
3335}
3436
3537function codeToSVG ( code , range , { lang, theme = '3024.night' } ) {
3638 const extractedCode = extract ( code , range ) ;
3739 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+ ) ;
4148}
4249
4350module . exports = codeToSVG ;
0 commit comments