Comparing version 1.0.4 to 1.0.5-v
@@ -21,4 +21,14 @@ 'use strict' | ||
text: /^[^\n]+/, | ||
heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/ | ||
heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/, | ||
list: /^( *)(bull) [\s\S]+?(?:hr|\n*$)/ | ||
} | ||
block.bullet = /(?:[*+-]|\d\.)/ | ||
block.item = /( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/ | ||
block.item = replace(block.item, 'gm') | ||
(/bull/g, block.bullet) | ||
() | ||
block.list = replace(block.list) | ||
('bull', block.bullet) | ||
('hr', '\\n+(?=\\1(?:[*-_] *){3,}(?:\\n+|$))') | ||
() | ||
/** | ||
@@ -41,2 +51,3 @@ * 语法解析器 | ||
parse(src) { | ||
debugger; | ||
this.inline = new InlineLexer(src.links, this.options) | ||
@@ -56,2 +67,17 @@ this.tokens = src.reverse() | ||
} | ||
peek() { | ||
return this.tokens[this.tokens.length] || 0 | ||
} | ||
parseText() { | ||
var body = this.token.text | ||
while(this.peek().type === 'text') { | ||
body += '\n' + this.next().text | ||
} | ||
return this.inline.output(body) | ||
} | ||
tok() { | ||
@@ -74,2 +100,23 @@ switch(this.token.type) { | ||
} | ||
case 'list_start': { | ||
var body = '' | ||
, ordered = this.token.ordered | ||
while(this.next().type !== 'list_end') { | ||
body += this.tok() | ||
} | ||
return this.renderer.list(body, ordered) | ||
} | ||
case 'list_item_start': { | ||
var body = '' | ||
while(this.next().type !== 'list_item_end') { | ||
body += this.token.type === 'text' | ||
? this.parseText() | ||
: this.tok() | ||
} | ||
return this.renderer.listitem(body) | ||
} | ||
} | ||
@@ -127,3 +174,2 @@ } | ||
out += this.renderer.codespan(cap[2]) | ||
debugger; | ||
continue | ||
@@ -169,3 +215,3 @@ } | ||
+ ' id="' | ||
+ id.replace(/ /g, this.options.gap) | ||
+ id.replace(/ +?[^ ]/g, this.options.gap) | ||
+ '">' | ||
@@ -199,2 +245,31 @@ + text | ||
list(text, ordered) { | ||
debugger | ||
var bull = ordered ? 'ol' : 'ul' | ||
if(ordered) { | ||
return '<' | ||
+ bull | ||
+ ' start=' | ||
+ ordered | ||
+ '>' | ||
+ text | ||
+ '</' | ||
+ bull | ||
+ '>' | ||
} | ||
return '<' | ||
+ bull | ||
+ '>' | ||
+ text | ||
+ '</' | ||
+ bull | ||
+ '>' | ||
} | ||
listitem(text) { | ||
return '<li>' + text + '</li>' | ||
} | ||
text(text) { | ||
@@ -210,10 +285,11 @@ return text | ||
constructor() { | ||
constructor(options) { | ||
this.tokens = [] | ||
this.tokens.links = {} | ||
this.rules = block | ||
this.options = options || cmarked.options | ||
} | ||
static lex(src) { | ||
let lexer = new Lexer() | ||
static lex(src, options) { | ||
let lexer = new Lexer(options) | ||
return lexer.lex(src) | ||
@@ -230,5 +306,22 @@ } | ||
token(src) { | ||
token(src, top, bq) { | ||
/* | ||
* 解释每一个变量 | ||
* src 源代码 | ||
* cap 根据规则匹配出来的数组 | ||
* bull 列表符号 | ||
* next 未知 | ||
* i 循环的控制变量 | ||
* item 循环中的用来根据索引取出数组中的变量 | ||
*/ | ||
var src = src.replace(/^ +$/gm, '') | ||
, cap | ||
, bull | ||
, next | ||
, i | ||
, item | ||
, space | ||
, loose | ||
, l | ||
, ordered | ||
@@ -250,4 +343,66 @@ while(src) { | ||
}) | ||
continue | ||
} | ||
if(cap = this.rules.list.exec(src)) { | ||
debugger | ||
src = src.substring(cap[0].length) | ||
bull = cap[2] | ||
ordered = parseInt(bull) | ||
debugger | ||
if(this.options.smartOrderList && !ordered) { | ||
ordered = false | ||
} | ||
this.tokens.push({ | ||
type: 'list_start', | ||
ordered: ordered | ||
}) | ||
// 获得每一个顶级li元素 | ||
cap = cap[0].match(this.rules.item) | ||
// next = false | ||
l = cap.length | ||
i = 0 | ||
for(; i < l; i++) { | ||
item = cap[i] | ||
space = item.length | ||
item = item.replace(/^ *(?:[*+-]|\d\.) +/, '') | ||
if(~item.indexOf('\n ')) { | ||
space -= item.length | ||
item = this.options.pedantic | ||
? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') | ||
: item.replace(/ {1,4}/gm, '') | ||
} | ||
loose = next || /\n\n(?!\s*$)/.test(item) | ||
if(i !== l - 1) { | ||
next = item.charAt(item.length - 1) === '\n' | ||
if(!loose) loose = next | ||
} | ||
this.tokens.push({ | ||
type: loose | ||
? 'loose_item_start' | ||
: 'list_item_start' | ||
}) | ||
this.token(item, false, bq) | ||
this.tokens.push({ | ||
type: 'list_item_end' | ||
}) | ||
} | ||
this.tokens.push({ | ||
type: 'list_end' | ||
}) | ||
continue | ||
} | ||
if(cap = this.rules.code.exec(src)) { | ||
@@ -263,3 +418,4 @@ src = src.substring(cap[0].length) | ||
if(cap = this.rules.paragraph.exec(src)) { | ||
// 顶级的p标签,只有top为true的时候才能进行该匹配 | ||
if(top && (cap = this.rules.paragraph.exec(src))) { | ||
src = src.substring(cap[0].length) | ||
@@ -313,3 +469,4 @@ this.tokens.push({ | ||
// h1-h6空格填充物 | ||
gap: '-' | ||
gap: '-', | ||
smartOrderList: true | ||
} | ||
@@ -316,0 +473,0 @@ |
{ | ||
"name": "cmarked", | ||
"version": "1.0.4", | ||
"version": "1.0.5v", | ||
"description": "更符合汉语的markdown编译器", | ||
@@ -23,3 +23,6 @@ "main": "index.js", | ||
}, | ||
"homepage": "https://github.com/Jiang-Xuan/cmarked#readme" | ||
"homepage": "https://github.com/Jiang-Xuan/cmarked#readme", | ||
"devDependencies": { | ||
"chai": "^3.5.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
16273
8
486
1
2
1
1