Merge branch 'compliant'
This commit is contained in:
commit
141accbfaf
@ -54,7 +54,6 @@ There may also be some bugs.
|
||||
- Find a better way of testing. Create a test suite from scratch because most
|
||||
markdown compilers don't appear to be working properly in every aspect (but
|
||||
it's hard to tell because the markdown "spec" is so vague).
|
||||
- Possibly alter rules to recognize arbitrary blocks of HTML better.
|
||||
- Recognize and parse paragraph list items better.
|
||||
- Add an explicit pretty printing and minification feature.
|
||||
|
||||
|
@ -196,25 +196,25 @@ block.token = function(str, tokens, line) {
|
||||
*/
|
||||
|
||||
var inline = {
|
||||
escape: /^\\([\\`*{}\[\]()#+\-.!])/,
|
||||
autolink: /^<([^ >]+(:|@)[^ >]+)>/,
|
||||
tag: /^<[^\n>]+>/,
|
||||
img: /^!\[([^\]]+)\]\(([^\s\)]+)\s*([^\)]*)\)/,
|
||||
link: /^\[([^\]]+)\]\(([^\)]+)\)/,
|
||||
reflink: /^\[([^\]]+)\]\[([^\]]+)\]/,
|
||||
link: /^!?\[([^\]]+)\]\(([^\)]+)\)/,
|
||||
reflink: /^!?\[([^\]]+)\]\[([^\]]+)\]/,
|
||||
strong: /^__([\s\S]+?)__|^\*\*([\s\S]+?)\*\*/,
|
||||
em: /^_([^_]+)_|^\*([^*]+)\*/,
|
||||
escape: /^`([^`]+)`|^``([\s\S]+?)``/
|
||||
code: /^`([^`]+)`|^``([\s\S]+?)``/
|
||||
};
|
||||
|
||||
inline.keys = [
|
||||
'escape',
|
||||
'autolink',
|
||||
'tag',
|
||||
'img',
|
||||
'link',
|
||||
'reflink',
|
||||
'strong',
|
||||
'em',
|
||||
'escape'
|
||||
'code'
|
||||
];
|
||||
|
||||
// hacky, but performant
|
||||
@ -245,9 +245,10 @@ inline.text = (function(rules) {
|
||||
inline.lexer = function(str) {
|
||||
var out = ''
|
||||
, links = tokens.links
|
||||
, link
|
||||
, link = {}
|
||||
, text
|
||||
, href;
|
||||
, href
|
||||
, val;
|
||||
|
||||
var rules = inline
|
||||
, keys = inline.keys
|
||||
@ -268,35 +269,52 @@ inline.lexer = function(str) {
|
||||
|
||||
while (scan()) {
|
||||
switch (key) {
|
||||
case 'escape':
|
||||
out += cap[1];
|
||||
break;
|
||||
case 'tag':
|
||||
out += cap[0];
|
||||
break;
|
||||
case 'img':
|
||||
out += '<img src="'
|
||||
+ escape(cap[2])
|
||||
+ '" alt="' + escape(cap[1])
|
||||
+ '"'
|
||||
+ (cap[3]
|
||||
? ' title="'
|
||||
+ escape(cap[3])
|
||||
+ '"'
|
||||
: '')
|
||||
+ '>';
|
||||
break;
|
||||
case 'link':
|
||||
case 'reflink':
|
||||
link = links[cap[2]] || '';
|
||||
out += '<a href="'
|
||||
+ escape(link.href || cap[2])
|
||||
+ '"'
|
||||
+ (link.title
|
||||
? ' title="'
|
||||
+ escape(link.title)
|
||||
+ '"'
|
||||
: '')
|
||||
+ '>'
|
||||
+ inline.lexer(cap[1])
|
||||
+ '</a>';
|
||||
if (cap[0][0] !== '!') {
|
||||
if (key === 'reflink') {
|
||||
link = links[cap[2]];
|
||||
} else {
|
||||
link.href = cap[2];
|
||||
link.title = cap[3];
|
||||
}
|
||||
out += '<a href="'
|
||||
+ escape(link.href)
|
||||
+ '"'
|
||||
+ (link.title
|
||||
? ' title="'
|
||||
+ escape(link.title)
|
||||
+ '"'
|
||||
: '')
|
||||
+ '>'
|
||||
+ inline.lexer(cap[1])
|
||||
+ '</a>';
|
||||
} else {
|
||||
if (key === 'reflink') {
|
||||
link = links[cap[2]];
|
||||
} else {
|
||||
val = cap[2].match(/^([^\s]+)\s*(.+)?/);
|
||||
link.href = val[1];
|
||||
link.title = val[2];
|
||||
}
|
||||
out += '<img src="'
|
||||
+ escape(link.href)
|
||||
+ '" alt="'
|
||||
+ escape(cap[1])
|
||||
+ '"'
|
||||
+ (link.title
|
||||
? ' title="'
|
||||
+ escape(link.title)
|
||||
+ '"'
|
||||
: '')
|
||||
+ '>';
|
||||
}
|
||||
break;
|
||||
case 'autolink':
|
||||
if (cap[2] === '@') {
|
||||
@ -320,7 +338,7 @@ inline.lexer = function(str) {
|
||||
+ inline.lexer(cap[2] || cap[1])
|
||||
+ '</em>';
|
||||
break;
|
||||
case 'escape':
|
||||
case 'code':
|
||||
out += '<code>'
|
||||
+ escape(cap[2] || cap[1])
|
||||
+ '</code>';
|
||||
|
Loading…
x
Reference in New Issue
Block a user