Example #1
0
    registerLanguageDefinitions = function () {
        highlight.registerLanguage('plain', function() {
            return { case_insensitive: true };
        });

        highlight.registerLanguage('cli', function() {
            return { case_insensitive: true };
        });
    };
Example #2
0
var PARTIALS = path.join(__dirname, 'templates', 'partials');
var partials = fs.readdirSync(PARTIALS);

partials.forEach(function(filename) {
  var name = path.basename(filename, '.hbs');
  var source = fs.readFileSync(path.join(PARTIALS, filename)).toString();
  handlebars.registerPartial(name, source);
});

//
// Highlight JS custom languages
//

hljs.registerLanguage('tokens', function() {
  return customLang.tokens;
});

//
// Render Markdown
// And prepend a named anchor before all H1 headings
//

handlebars.registerHelper('markdown', function(text) {
  var r = new markit.Renderer();
  r.header = function(text, level) {
    var anchor  = '<a name="' + slug.from(text) + '"></a>';
    var heading = '<h' + level + '>' + text + '</h' + level + '>';
    return new handlebars.SafeString(anchor + '\n' + heading);
  };
  r.blockcode = function(code, language) {
Example #3
0
require('../../css/pdf.scss');

import hljs from 'highlight.js';
import kotlin from 'highlight.js/lib/languages/kotlin';

hljs.registerLanguage('kotlin', kotlin);

const $ = require('jquery');
const SAMPLE_START = '//sampleStart';
const SAMPLE_END = '//sampleEnd';

$(document).ready(function () {
  $('.sample').each((ind, element) => {
    const codeElement = $(element).find('code')[0];
    let code = codeElement.textContent;
    const startIndex = code.indexOf(SAMPLE_START);
    const endIndex = code.indexOf(SAMPLE_END);
    if (startIndex > -1 && endIndex > -1) {
      code = code.substring(code.indexOf(SAMPLE_START) + SAMPLE_START.length + 1);
      code = code.substring(0, code.indexOf(SAMPLE_END));
      if (!code.charAt(0).trim()) code = code.split('\n').map(l => l.substring(4)).join("\n")
    }
    codeElement.textContent = code;
    hljs.highlightBlock(codeElement);
  });
});