`')
+ '<http://example.com>
'
> Ox.parseMarkdown('[example](http://example.com "example.com")')
'example'
> Ox.parseMarkdown('[example](http://example.com?foo=bar&bar=baz)')
@@ -393,7 +400,29 @@
*/
Ox.parseMarkdown = function(string) {
// see https://github.com/coreyti/showdown/blob/master/src/showdown.js
+ var array = [];
return string.replace(/\r\n/g, '\n').replace(/\r/g, '\n')
+ .replace(
+ /(?:^|\n)```(.*)\n([^`]+)\n```/g,
+ function(match, classname, code) {
+ array.push(
+ ''
+ + code.trim().replace(/
'
+ );
+ return salt.join(array.length - 1);
+ }
+ )
+ .replace(
+ /(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,
+ function(match, prev, backticks, code, next) {
+ array.push(
+ prev + ''
+ + code.trim().replace(/'
+ );
+ return salt.join(array.length - 1);
+ }
+ )
.replace(
/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g,
'$2'
@@ -402,21 +431,6 @@
/(\*|_)(?=\S)([^\r]*?\S)\1/g,
'$2'
)
- .replace(
- /\n```(.*)\n([^`]+)\n```/g,
- function(match, classname, code) {
- return ''
- + code.trim().replace(/
';
- }
- )
- .replace(
- /(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,
- function(match, prev, backticks, code, next) {
- return prev + ''
- + code.trim().replace(/';
- }
- )
.replace(
/(\[((?:\[[^\]]*\]|[^\[\]])*)\]\([ \t]*()(.*?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,
function(match, all, text, id, url, rest, quote, title) {
@@ -435,7 +449,13 @@
return Ox.encodeEmailAddress(mail);
}
)
- .replace(/\n\n/g, '
');
+ .replace(/\n\n/g, '
')
+ .replace(
+ new RegExp(salt.join('(\\d+)'), 'g'),
+ function(match, index) {
+ return array[parseInt(index)];
+ }
+ );
};
/*@
@@ -476,13 +496,18 @@
'foo'
> Ox.sanitizeHTML('&&')
'&&'
+ > Ox.sanitizeHTML('')
+ '<http://foo.com>'
@*/
Ox.sanitizeHTML = function(html, tags) {
var matches = [];
tags = tags || defaultTags;
// html = Ox.clean(html); fixme: can this be a parameter?
if (tags.indexOf('[]') > -1) {
- html = html.replace(/\[((\/|https?:\/\/|mailto:).+?) (.+?)\]/gi, '$3');
+ html = html.replace(
+ /\[((\/|https?:\/\/|mailto:).+?) (.+?)\]/gi,
+ '$3'
+ );
tags = tags.filter(function(tag) {
return tag != '[]';
});