Skip to content

Commit

Permalink
fix(eslint): auto fix
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanGerbeth committed Aug 24, 2018
1 parent fd0caa0 commit 26af0a5
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const ansiToSVG = require('ansi-to-svg');
const emphasize = require('emphasize');
const path = require('path');

const options = {
fontSize: 12,
lineHeight: 25.6,
Expand All @@ -24,20 +25,26 @@ function highlightCode(code, lang = '') {
return emphasize.highlightAuto(code);
}

function modifySVG(svg) {
return svg.replace(/viewBox="([0-9.]+), ([0-9.]+), ([0-9.]+), ([0-9.]+)"/, (match, g1, g2, g3, g4) => {
return `height="${g4}" preserveAspectRatio="xMinYMax slice" viewBox="${g1}, ${g2}, 898, ${g4}"`;
}).replace(/(<rect x="0" y="0" width=")([0-9.]+)(")/, (match, g1, g2, g3) => {
return [g1, 898, g3].join('');
});
function modifySVG(svg) {
return svg
.replace(
/viewBox="([0-9.]+), ([0-9.]+), ([0-9.]+), ([0-9.]+)"/,
(match, g1, g2, g3, g4) => `height="${g4}" preserveAspectRatio="xMinYMax slice" viewBox="${g1}, ${g2}, 898, ${g4}"`
)
.replace(/(<rect x="0" y="0" width=")([0-9.]+)(")/, (match, g1, g2, g3) => [g1, 898, g3].join(''));
}

function codeToSVG(code, range, { lang, theme = '3024.night' }) {
const extractedCode = extract(code, range);
const highlightedCode = highlightCode(extractedCode, lang);
return modifySVG(ansiToSVG(highlightedCode.value, Object.assign(options, {
colors: path.resolve(__dirname, `../schemes/${theme}.itermcolors`)
})));
return modifySVG(
ansiToSVG(
highlightedCode.value,
Object.assign(options, {
colors: path.resolve(__dirname, `../schemes/${theme}.itermcolors`)
})
)
);
}

module.exports = codeToSVG;

0 comments on commit 26af0a5

Please sign in to comment.