Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
highlight: function (code, type) {
var scope = {
js: "source.js",
javascript: "source.js",
html: "text.html.gohtml",
block: "text.html.gohtml",
css: "source.css"
};
var scopeName = scope[type] || "text.html.gohtml";
var highlighter = new Highlights();
var html = highlighter.highlightSync({
fileContents: code,
scopeName
});
if (type) {
html = `<div class="ronde-codeblock__header">${type}</div>${html}`;
}
return html;
}
});
highlight: function (code, type) {
var scope = {
js: "source.js",
javascript: "source.js",
html: "text.html.gohtml",
block: "text.html.gohtml",
css: "source.css"
};
var scopeName = scope[type] || "text.html.gohtml";
var highlighter = new Highlights();
var html = highlighter.highlightSync({
fileContents: code,
scopeName
});
if (type) {
html = `<div class="ronde-codeblock__header">${type}</div>${html}`;
}
return html;
}
});
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { CodeLine } from '../model';
import Selector from 'first-mate-select-grammar';
import Highlights from 'highlights';
const highlighter = new Highlights();
highlighter.loadGrammarsSync();
const selector = Selector();
export function tokenizeLines(filePath: string, fileContents: string): CodeLine[] {
const grammar = selector.selectGrammar(highlighter.registry, filePath, fileContents);
if (grammar) {
return grammar.tokenizeLines(fileContents);
} else {
return [];
}
}
export function computeRanges(lines: CodeLine[]) {
let pos = 0;