/
githubmirror
/
markdown-here
Обзор
Документация
Войти
/
githubmirror
/
markdown-here
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
v2.9.0
src/common/markdown-render.js
75 строк
2 KB
Adam Pritchard
Changed markdownRender to be passed plaintext MD. Forgot-to-render check is now done at send time rather than periodically. Made new HTML-to-text code also take a range. Test cases need updating.
30 сен 2013, 15:51
30 сен 2013, 15:51
26aa3a4
Код
Авторство
О чём код?
/* * 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) { 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); }());