ultramarked
Advanced tools
Comparing version 1.5.4 to 1.6.0
@@ -10,3 +10,3 @@ { | ||
}, | ||
"version": "1.5.4", | ||
"version": "1.6.0", | ||
"repository": { | ||
@@ -13,0 +13,0 @@ "type": "git", |
@@ -12,3 +12,3 @@ 'use strict'; | ||
if (item.hasOwnProperty(key)) { | ||
if (result[key]) { | ||
if (result[key] && typeof result[key] === 'object') { | ||
result[key] = assign(result[key], item[key]); | ||
@@ -15,0 +15,0 @@ } else { |
139
src/core.js
@@ -6,84 +6,93 @@ 'use strict'; | ||
var assign = require('./assign'); | ||
var exports = module.exports = ultramarked; | ||
var alises = exports.aliases = { | ||
'js': 'javascript', | ||
'md': 'markdown', | ||
'html': 'xml', // next best thing | ||
'jade': 'css' // next best thing | ||
}; | ||
hljs.configure({ classPrefix: 'hljs-' }); | ||
function createRenderer (options) { | ||
var renderer = new marked.Renderer(); | ||
Object.keys(options).forEach(function map (key) { | ||
renderer[key] = options[key]; | ||
}); | ||
return renderer; | ||
var renderer = new marked.Renderer(); | ||
Object.keys(options).forEach(function map (key) { | ||
renderer[key] = options[key]; | ||
}); | ||
return renderer; | ||
} | ||
function getHighlightingRenderer (prev) { | ||
var renderer = prev || new marked.Renderer(); | ||
var baseCodeRenderer = renderer.code; | ||
var baseCodeSpanRenderer = renderer.codespan; | ||
var s = (prev || renderer); | ||
var renderer = new marked.Renderer(); | ||
var baseCodeRenderer = s.code; | ||
var baseCodeSpanRenderer = s.codespan; | ||
Object.keys(prev).forEach(function (key) { | ||
renderer[key] = prev[key]; | ||
}); | ||
renderer.code = function () { | ||
var result = baseCodeRenderer.apply(this, arguments); | ||
var classed = result.replace(/^<pre><code>/i, '<pre class="hljs-pre"><code class="hljs">'); | ||
return classed; | ||
}; | ||
renderer.codespan = function () { | ||
var result = baseCodeSpanRenderer.apply(this, arguments); | ||
var classed = result.replace(/^<code>/i, '<code class="hljs">'); | ||
return classed; | ||
}; | ||
return renderer; | ||
renderer.code = function () { | ||
var result = baseCodeRenderer.apply(this, arguments); | ||
var classed = result.replace(/^<pre><code>/i, '<pre class="hljs-pre"><code class="hljs">'); | ||
return classed; | ||
}; | ||
renderer.codespan = function () { | ||
var result = baseCodeSpanRenderer.apply(this, arguments); | ||
var classed = result.replace(/^<code>/i, '<code class="hljs">'); | ||
return classed; | ||
}; | ||
renderer._highlighting = true; | ||
return renderer; | ||
} | ||
function ultramarked(src, opt) { | ||
var options = assign({}, marked.defaults, opt), | ||
aliases = options.aliases || exports.aliases, | ||
no = 'no-highlight'; | ||
function ultramarked (src, opt) { | ||
var options = assign({}, marked.defaults, opt); | ||
var aliases = options.aliases || ultramarked.aliases; | ||
var no = 'no-highlight'; | ||
if (options.terminal){ | ||
delete options.ultralight; | ||
delete options.ultrasanitize; | ||
if (options.terminal) { | ||
delete options.ultralight; | ||
delete options.ultrasanitize; | ||
} | ||
if (options.ultralight) { | ||
options.langPrefix = 'ultralight-lang-'; // placeholder | ||
options.highlight = function (code, lang) { | ||
if (!lang) { | ||
return code; | ||
} | ||
var lower = lang.toLowerCase(); | ||
try { | ||
return hljs.highlight(aliases[lower] || lower, code).value; | ||
} catch (ex) {} // marked will know what to do. | ||
}; | ||
if (!options.renderer || !options.renderer._highlighting) { | ||
options.renderer = getHighlightingRenderer(options.renderer); | ||
} | ||
if (options.ultralight){ | ||
options.langPrefix = 'ultralight-lang-'; // placeholder | ||
options.highlight = function (code, lang) { | ||
if (!lang) { | ||
return code; | ||
} | ||
var lower = lang.toLowerCase(); | ||
try{ | ||
return hljs.highlight(aliases[lower] || lower, code).value; | ||
} catch (ex) {} // marked will know what to do. | ||
}; | ||
options.renderer = getHighlightingRenderer(options.renderer); | ||
} | ||
} | ||
var tokens = marked.lexer(src, options), | ||
result = marked.parser(tokens, options); | ||
var tokens = marked.lexer(src, options); | ||
var result = marked.parser(tokens, options); | ||
if (options.ultralight) { // fix the language class using common aliases | ||
result = result.replace(/"ultralight-lang-([\w-]+)"/ig, function (match, lang) { | ||
var lower = lang.toLowerCase(), | ||
result = aliases[lower] || lower || no; | ||
if (options.ultralight) { // fix the language class using common aliases | ||
result = result.replace(/"ultralight-lang-([\w-]+)"/ig, replacer); | ||
result = result.replace(/^<pre>/, '<pre class="hljs-pre">'); | ||
} | ||
return '"hljs ' + result + '"'; | ||
}); | ||
result = result.replace(/^<pre>/, '<pre class="hljs-pre">'); | ||
} | ||
function replacer (match, lang) { | ||
var lower = lang.toLowerCase(); | ||
var result = aliases[lower] || lower || no; | ||
if(options.ultrasanitize){ | ||
result = require('./sanitizer.js')(result, options); | ||
}else if(options.sanitizer){ | ||
result = options.sanitizer(result, options); | ||
} | ||
return result; | ||
return '"hljs ' + result + '"'; | ||
} | ||
if (options.ultrasanitize) { | ||
result = require('./sanitizer.js')(result, options); | ||
} else if (options.sanitizer) { | ||
result = options.sanitizer(result, options); | ||
} | ||
return result; | ||
} | ||
hljs.configure({ classPrefix: 'hljs-' }); | ||
ultramarked.setOptions = marked.setOptions; | ||
ultramarked.renderer = createRenderer; | ||
ultramarked.aliases = { | ||
js: 'javascript', | ||
md: 'markdown', | ||
html: 'xml', // next best thing | ||
jade: 'css' // next best thing | ||
}; | ||
module.exports = ultramarked; |
@@ -8,3 +8,3 @@ 'use strict'; | ||
function fwd (src, opt) { | ||
if (opt.terminal) { | ||
if (opt && opt.terminal) {console.log('TERM!'); | ||
opt.renderer = term; | ||
@@ -16,3 +16,3 @@ } | ||
fwd.setOptions = function (opt) { | ||
if (opt.terminal) { | ||
if (opt && opt.terminal) { | ||
opt.renderer = term; | ||
@@ -19,0 +19,0 @@ } |
@@ -41,77 +41,83 @@ 'use strict'; | ||
var renderer = new marked.Renderer(); | ||
function get () { | ||
var renderer = new marked.Renderer(); | ||
renderer.hr = function () { | ||
var line = (function () { | ||
var separator = process.platform == 'win32' ? '-' : '⎽'; | ||
return ' ' + new Array(width - 2).join(separator); | ||
}()); | ||
return line + '\n\n'; | ||
}; | ||
renderer.hr = function () { | ||
var line = (function () { | ||
var separator = process.platform == 'win32' ? '-' : '⎽'; | ||
return ' ' + new Array(width - 2).join(separator); | ||
}()); | ||
return line + '\n\n'; | ||
}; | ||
renderer.heading = function (text, level) { | ||
text = fixWhitespace(text); | ||
switch (level) { | ||
case 1: return wrap(chalk.bold.white.underline(text)) + '\n\n'; | ||
case 2: return wrap(chalk.bold.underline(text)) + '\n\n'; | ||
default: return wrap(chalk.bold(text)) + '\n\n'; | ||
} | ||
}; | ||
renderer.heading = function (text, level) { | ||
text = fixWhitespace(text); | ||
switch (level) { | ||
case 1: return wrap(chalk.bold.white.underline(text)) + '\n\n'; | ||
case 2: return wrap(chalk.bold.underline(text)) + '\n\n'; | ||
default: return wrap(chalk.bold(text)) + '\n\n'; | ||
} | ||
}; | ||
renderer.code = function (text, lang) { | ||
text = indent(text); | ||
return colorize(text, 'gray') + '\n\n'; | ||
}; | ||
renderer.code = function (text, lang) { | ||
text = indent(text); | ||
return colorize(text, 'gray') + '\n\n'; | ||
}; | ||
renderer.blockquote = function (body) { | ||
body = fixWhitespace(body); | ||
return chalk.gray(indent(body)) + '\n\n'; | ||
}; | ||
renderer.blockquote = function (body) { | ||
body = fixWhitespace(body); | ||
return chalk.gray(indent(body)) + '\n\n'; | ||
}; | ||
renderer.list = function (body, ordered) { | ||
return body + '\n\n'; | ||
}; | ||
renderer.list = function (body, ordered) { | ||
return body + '\n\n'; | ||
}; | ||
renderer.listitem = function (text) { | ||
text = fixWhitespace(text); | ||
return indent(text.replace(/\n/g, ' ')).replace(' ', ' * ') + '\n'; | ||
}; | ||
renderer.listitem = function (text) { | ||
text = fixWhitespace(text); | ||
return indent(text.replace(/\n/g, ' ')).replace(' ', ' * ') + '\n'; | ||
}; | ||
renderer.paragraph = function (body) { | ||
body = body | ||
.replace(/\n/g, ' ') | ||
.replace(/[\s]+/g, ' '); | ||
renderer.paragraph = function (body) { | ||
body = body | ||
.replace(/\n/g, ' ') | ||
.replace(/[\s]+/g, ' '); | ||
body = _s.trim(body); | ||
return paragraph(body.replace(/\n/g, ' ').replace(/[\s]+/g, ' ')) + '\n\n'; | ||
}; | ||
body = _s.trim(body); | ||
return paragraph(body.replace(/\n/g, ' ').replace(/[\s]+/g, ' ')) + '\n\n'; | ||
}; | ||
renderer.strong = function (text) { | ||
return chalk.bold(text); | ||
}; | ||
renderer.strong = function (text) { | ||
return chalk.bold(text); | ||
}; | ||
renderer.em = function (text) { | ||
return chalk.bold.underline(text); | ||
}; | ||
renderer.em = function (text) { | ||
return chalk.bold.underline(text); | ||
}; | ||
renderer.del = function (text) { | ||
return chalk.strikethrough(text); | ||
}; | ||
renderer.del = function (text) { | ||
return chalk.strikethrough(text); | ||
}; | ||
renderer.codespan = function (text) { | ||
return chalk.gray(text); | ||
}; | ||
renderer.codespan = function (text) { | ||
return chalk.gray(text); | ||
}; | ||
renderer.br = function () { | ||
return '\n'; | ||
}; | ||
renderer.br = function () { | ||
return '\n'; | ||
}; | ||
renderer.link = function (href, title, text) { | ||
return autolink(href, text || title); | ||
}; | ||
renderer.link = function (href, title, text) { | ||
return autolink(href, text || title); | ||
}; | ||
renderer.image = function (href, title, text) { | ||
return autolink(href, text || title); | ||
}; | ||
renderer.image = function (href, title, text) { | ||
return autolink(href, text || title); | ||
}; | ||
module.exports = renderer; | ||
renderer._term = true; | ||
return renderer; | ||
} | ||
module.exports = get(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53422
594