').html(html).html();
};
+ /*@
+ Ox.parseMarkdown
Parses (a tiny subset of) Markdown.
+ \*foo\* -> foo
+ \*\*foo\*\* -> foo
+ \`foo\` -> foo
+ \`\`\`code\`\`\` -> foo
+ [example](http://example.com "example.com") -> example
+ > Ox.parseMarkdown('*foo* **bar** `baz` ``back`tick``')
+ 'foo bar baz
back`tick
'
+ > Ox.parseMarkdown('[example](http://example.com "example.com")')
+ 'example'
+ > Ox.parseMarkdown('[example](http://example.com?foo=bar&bar=baz)')
+ 'example'
+ */
+ Ox.parseMarkdown = function(string) {
+ // see https://github.com/coreyti/showdown/blob/master/src/showdown.js
+ return string.replace(/\r\n/g, '\n').replace(/\r/g, '\n')
+ .replace(/\n\n/g, '
')
+ .replace(
+ /(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g,
+ '$2'
+ )
+ .replace(
+ /(\*|_)(?=\S)([^\r]*?\S)\1/g,
+ '$2'
+ )
+ .replace(
+ /\n```(.*)\n([^`]+)\n```/g,
+ function(match, a, b) {
+ return ''
+ + Ox.encodeHTMLEntities(b) + '\n
';
+ }
+ )
+ .replace(
+ /(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,
+ function(match, a, b, c, d) {
+ return a + ''
+ + Ox.encodeHTMLEntities(c.trim()) + '
';
+ }
+ )
+ .replace(
+ /(\[((?:\[[^\]]*\]|[^\[\]])*)\]\([ \t]*()(.*?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,
+ function(match, a, b, c, d, e, f, g) {
+ return '' + b + '';
+ }
+ );
+ };
+
/*@
Ox.sanitizeHTML Takes untrusted HTML and returns something trustworthy
- > Ox.sanitizeHTML('http://foo.com, bar')
- 'http://foo.com, bar'
- > Ox.sanitizeHTML('http://foo.com/foo?bar, bar')
- 'http://foo.com/foo?bar, bar'
+ > Ox.sanitizeHTML('http://foo.com, ...')
+ 'http://foo.com, ...'
+ > Ox.sanitizeHTML('http://foo.com/foo?bar&baz, ...')
+ 'http://foo.com/foo?bar&baz, ...'
> Ox.sanitizeHTML('(see: www.foo.com)')
'(see: www.foo.com)'
> Ox.sanitizeHTML('foo@bar.com')