/
githubmirror
/
markdown-here
Обзор
Документация
Войти
/
githubmirror
/
markdown-here
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
v2.9.3
src/common/markdown-render.js
77 строк
2 KB
Adam Pritchard
Fixed bug #112: Syntax Highlighting crashing rendering on bad language name
10 окт 2013, 20:13
10 окт 2013, 20:13
21a2231
Код
Авторство
О чём код?
/* * Copyright Adam Pritchard 2013 * MIT License : http://adampritchard.mit-license.org/ */ /* * The function that does the basic raw-Markdown-in-HTML to rendered-HTML * conversion. * The reason we keep this function -- specifically, the function that uses our * external markdown renderer (marked.js), text-from-HTML module (jsHtmlToText.js), * and CSS -- separate is that it allows us to keep the bulk of the rendering * code (and the bulk of the code in our extension) out of the content script. * That way, we minimize the amount of code that needs to be loaded in every page. */ ;(function() { "use strict"; /*global module:false*/ var MarkdownRender = {}; /** Using the functionality provided by the functions htmlToText and markdownToHtml, render html into pretty text. */ function markdownRender(mdText, userprefs, marked, hljs) { function mathify(mathcode) { return userprefs['math-value'] .replace(/\{mathcode\}/ig, mathcode) .replace(/\{urlmathcode\}/ig, encodeURIComponent(mathcode)); } var markedOptions = { gfm: true, pedantic: false, sanitize: false, tables: true, smartLists: true, breaks: true, smartypants: true, langPrefix: 'language-', math: userprefs['math-enabled'] ? mathify : null, highlight: function(codeText, codeLanguage) { if (codeLanguage && ((codeLanguage in hljs.LANGUAGES) || ((codeLanguage = codeLanguage.toLowerCase()) in hljs.LANGUAGES))) { return hljs.highlight(codeLanguage, codeText).value; } return codeText; } }; var renderedMarkdown = marked(mdText, markedOptions); return renderedMarkdown; } // Expose these functions MarkdownRender.markdownRender = markdownRender; var EXPORTED_SYMBOLS = ['MarkdownRender']; if (typeof module !== 'undefined') { module.exports = MarkdownRender; } else { this.MarkdownRender = MarkdownRender; this.EXPORTED_SYMBOLS = EXPORTED_SYMBOLS; } }).call(function() { return this || (typeof window !== 'undefined' ? window : global); }());