remark-parse
Advanced tools
Comparing version 5.0.0 to 6.0.0
21
index.js
@@ -1,14 +0,17 @@ | ||
'use strict'; | ||
'use strict' | ||
var unherit = require('unherit'); | ||
var xtend = require('xtend'); | ||
var Parser = require('./lib/parser.js'); | ||
var unherit = require('unherit') | ||
var xtend = require('xtend') | ||
var Parser = require('./lib/parser.js') | ||
module.exports = parse; | ||
parse.Parser = Parser; | ||
module.exports = parse | ||
parse.Parser = Parser | ||
function parse(options) { | ||
var Local = unherit(Parser); | ||
Local.prototype.options = xtend(Local.prototype.options, this.data('settings'), options); | ||
this.Parser = Local; | ||
var settings = this.data('settings') | ||
var Local = unherit(Parser) | ||
Local.prototype.options = xtend(Local.prototype.options, settings, options) | ||
this.Parser = Local | ||
} |
@@ -1,46 +0,32 @@ | ||
'use strict'; | ||
'use strict' | ||
var xtend = require('xtend'); | ||
var entities = require('parse-entities'); | ||
var xtend = require('xtend') | ||
var entities = require('parse-entities') | ||
module.exports = factory; | ||
module.exports = factory | ||
/* Factory to create an entity decoder. */ | ||
// Factory to create an entity decoder. | ||
function factory(ctx) { | ||
decoder.raw = decodeRaw; | ||
decoder.raw = decodeRaw | ||
return decoder; | ||
return decoder | ||
/* Normalize `position` to add an `indent`. */ | ||
// Normalize `position` to add an `indent`. | ||
function normalize(position) { | ||
var offsets = ctx.offset; | ||
var line = position.line; | ||
var result = []; | ||
var offsets = ctx.offset | ||
var line = position.line | ||
var result = [] | ||
while (++line) { | ||
if (!(line in offsets)) { | ||
break; | ||
break | ||
} | ||
result.push((offsets[line] || 0) + 1); | ||
result.push((offsets[line] || 0) + 1) | ||
} | ||
return { | ||
start: position, | ||
indent: result | ||
}; | ||
return {start: position, indent: result} | ||
} | ||
/* Handle a warning. | ||
* See https://github.com/wooorm/parse-entities | ||
* for the warnings. */ | ||
function handleWarning(reason, position, code) { | ||
if (code === 3) { | ||
return; | ||
} | ||
ctx.file.message(reason, position); | ||
} | ||
/* Decode `value` (at `position`) into text-nodes. */ | ||
// Decode `value` (at `position`) into text-nodes. | ||
function decoder(value, position, handler) { | ||
@@ -54,12 +40,20 @@ entities(value, { | ||
referenceContext: ctx | ||
}); | ||
}) | ||
} | ||
/* Decode `value` (at `position`) into a string. */ | ||
// Decode `value` (at `position`) into a string. | ||
function decodeRaw(value, position, options) { | ||
return entities(value, xtend(options, { | ||
position: normalize(position), | ||
warning: handleWarning | ||
})); | ||
return entities( | ||
value, | ||
xtend(options, {position: normalize(position), warning: handleWarning}) | ||
) | ||
} | ||
// Handle a warning. | ||
// See <https://github.com/wooorm/parse-entities> for the warnings. | ||
function handleWarning(reason, position, code) { | ||
if (code !== 3) { | ||
ctx.file.message(reason, position) | ||
} | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
'use strict' | ||
@@ -10,2 +10,2 @@ module.exports = { | ||
blocks: require('./block-elements.json') | ||
}; | ||
} |
@@ -1,17 +0,17 @@ | ||
'use strict'; | ||
'use strict' | ||
module.exports = locate; | ||
module.exports = locate | ||
function locate(value, fromIndex) { | ||
var index = value.indexOf('\n', fromIndex); | ||
var index = value.indexOf('\n', fromIndex) | ||
while (index > fromIndex) { | ||
if (value.charAt(index - 1) !== ' ') { | ||
break; | ||
break | ||
} | ||
index--; | ||
index-- | ||
} | ||
return index; | ||
return index | ||
} |
@@ -1,7 +0,7 @@ | ||
'use strict'; | ||
'use strict' | ||
module.exports = locate; | ||
module.exports = locate | ||
function locate(value, fromIndex) { | ||
return value.indexOf('`', fromIndex); | ||
return value.indexOf('`', fromIndex) | ||
} |
@@ -1,7 +0,7 @@ | ||
'use strict'; | ||
'use strict' | ||
module.exports = locate; | ||
module.exports = locate | ||
function locate(value, fromIndex) { | ||
return value.indexOf('~~', fromIndex); | ||
return value.indexOf('~~', fromIndex) | ||
} |
@@ -1,18 +0,18 @@ | ||
'use strict'; | ||
'use strict' | ||
module.exports = locate; | ||
module.exports = locate | ||
function locate(value, fromIndex) { | ||
var asterisk = value.indexOf('*', fromIndex); | ||
var underscore = value.indexOf('_', fromIndex); | ||
var asterisk = value.indexOf('*', fromIndex) | ||
var underscore = value.indexOf('_', fromIndex) | ||
if (underscore === -1) { | ||
return asterisk; | ||
return asterisk | ||
} | ||
if (asterisk === -1) { | ||
return underscore; | ||
return underscore | ||
} | ||
return underscore < asterisk ? underscore : asterisk; | ||
return underscore < asterisk ? underscore : asterisk | ||
} |
@@ -1,7 +0,7 @@ | ||
'use strict'; | ||
'use strict' | ||
module.exports = locate; | ||
module.exports = locate | ||
function locate(value, fromIndex) { | ||
return value.indexOf('\\', fromIndex); | ||
return value.indexOf('\\', fromIndex) | ||
} |
@@ -1,16 +0,16 @@ | ||
'use strict'; | ||
'use strict' | ||
module.exports = locate; | ||
module.exports = locate | ||
function locate(value, fromIndex) { | ||
var link = value.indexOf('[', fromIndex); | ||
var image = value.indexOf('![', fromIndex); | ||
var link = value.indexOf('[', fromIndex) | ||
var image = value.indexOf('![', fromIndex) | ||
if (image === -1) { | ||
return link; | ||
return link | ||
} | ||
/* Link can never be `-1` if an image is found, so we don’t need | ||
* to check for that :) */ | ||
return link < image ? link : image; | ||
// Link can never be `-1` if an image is found, so we don’t need to check | ||
// for that :) | ||
return link < image ? link : image | ||
} |
@@ -1,18 +0,18 @@ | ||
'use strict'; | ||
'use strict' | ||
module.exports = locate; | ||
module.exports = locate | ||
function locate(value, fromIndex) { | ||
var asterisk = value.indexOf('**', fromIndex); | ||
var underscore = value.indexOf('__', fromIndex); | ||
var asterisk = value.indexOf('**', fromIndex) | ||
var underscore = value.indexOf('__', fromIndex) | ||
if (underscore === -1) { | ||
return asterisk; | ||
return asterisk | ||
} | ||
if (asterisk === -1) { | ||
return underscore; | ||
return underscore | ||
} | ||
return underscore < asterisk ? underscore : asterisk; | ||
return underscore < asterisk ? underscore : asterisk | ||
} |
@@ -1,7 +0,7 @@ | ||
'use strict'; | ||
'use strict' | ||
module.exports = locate; | ||
module.exports = locate | ||
function locate(value, fromIndex) { | ||
return value.indexOf('<', fromIndex); | ||
return value.indexOf('<', fromIndex) | ||
} |
@@ -1,26 +0,26 @@ | ||
'use strict'; | ||
'use strict' | ||
module.exports = locate; | ||
module.exports = locate | ||
var PROTOCOLS = ['https://', 'http://', 'mailto:']; | ||
var protocols = ['https://', 'http://', 'mailto:'] | ||
function locate(value, fromIndex) { | ||
var length = PROTOCOLS.length; | ||
var index = -1; | ||
var min = -1; | ||
var position; | ||
var length = protocols.length | ||
var index = -1 | ||
var min = -1 | ||
var position | ||
if (!this.options.gfm) { | ||
return -1; | ||
return -1 | ||
} | ||
while (++index < length) { | ||
position = value.indexOf(PROTOCOLS[index], fromIndex); | ||
position = value.indexOf(protocols[index], fromIndex) | ||
if (position !== -1 && (position < min || min === -1)) { | ||
min = position; | ||
min = position | ||
} | ||
} | ||
return min; | ||
return min | ||
} |
@@ -1,29 +0,29 @@ | ||
'use strict'; | ||
'use strict' | ||
var xtend = require('xtend'); | ||
var removePosition = require('unist-util-remove-position'); | ||
var xtend = require('xtend') | ||
var removePosition = require('unist-util-remove-position') | ||
module.exports = parse; | ||
module.exports = parse | ||
var C_NEWLINE = '\n'; | ||
var EXPRESSION_LINE_BREAKS = /\r\n|\r/g; | ||
var lineFeed = '\n' | ||
var lineBreaksExpression = /\r\n|\r/g | ||
/* Parse the bound file. */ | ||
// Parse the bound file. | ||
function parse() { | ||
var self = this; | ||
var value = String(self.file); | ||
var start = {line: 1, column: 1, offset: 0}; | ||
var content = xtend(start); | ||
var node; | ||
var self = this | ||
var value = String(self.file) | ||
var start = {line: 1, column: 1, offset: 0} | ||
var content = xtend(start) | ||
var node | ||
/* Clean non-unix newlines: `\r\n` and `\r` are all | ||
* changed to `\n`. This should not affect positional | ||
* information. */ | ||
value = value.replace(EXPRESSION_LINE_BREAKS, C_NEWLINE); | ||
// Clean non-unix newlines: `\r\n` and `\r` are all changed to `\n`. | ||
// This should not affect positional information. | ||
value = value.replace(lineBreaksExpression, lineFeed) | ||
if (value.charCodeAt(0) === 0xFEFF) { | ||
value = value.slice(1); | ||
// BOM. | ||
if (value.charCodeAt(0) === 0xfeff) { | ||
value = value.slice(1) | ||
content.column++; | ||
content.offset++; | ||
content.column++ | ||
content.offset++ | ||
} | ||
@@ -34,13 +34,10 @@ | ||
children: self.tokenizeBlock(value, content), | ||
position: { | ||
start: start, | ||
end: self.eof || xtend(start) | ||
} | ||
}; | ||
position: {start: start, end: self.eof || xtend(start)} | ||
} | ||
if (!self.options.position) { | ||
removePosition(node, true); | ||
removePosition(node, true) | ||
} | ||
return node; | ||
return node | ||
} |
@@ -1,52 +0,51 @@ | ||
'use strict'; | ||
'use strict' | ||
var xtend = require('xtend'); | ||
var toggle = require('state-toggle'); | ||
var vfileLocation = require('vfile-location'); | ||
var unescape = require('./unescape'); | ||
var decode = require('./decode'); | ||
var tokenizer = require('./tokenizer'); | ||
var xtend = require('xtend') | ||
var toggle = require('state-toggle') | ||
var vfileLocation = require('vfile-location') | ||
var unescape = require('./unescape') | ||
var decode = require('./decode') | ||
var tokenizer = require('./tokenizer') | ||
module.exports = Parser; | ||
module.exports = Parser | ||
function Parser(doc, file) { | ||
this.file = file; | ||
this.offset = {}; | ||
this.options = xtend(this.options); | ||
this.setOptions({}); | ||
this.file = file | ||
this.offset = {} | ||
this.options = xtend(this.options) | ||
this.setOptions({}) | ||
this.inList = false; | ||
this.inBlock = false; | ||
this.inLink = false; | ||
this.atStart = true; | ||
this.inList = false | ||
this.inBlock = false | ||
this.inLink = false | ||
this.atStart = true | ||
this.toOffset = vfileLocation(file).toOffset; | ||
this.unescape = unescape(this, 'escape'); | ||
this.decode = decode(this); | ||
this.toOffset = vfileLocation(file).toOffset | ||
this.unescape = unescape(this, 'escape') | ||
this.decode = decode(this) | ||
} | ||
var proto = Parser.prototype; | ||
var proto = Parser.prototype | ||
/* Expose core. */ | ||
proto.setOptions = require('./set-options'); | ||
proto.parse = require('./parse'); | ||
// Expose core. | ||
proto.setOptions = require('./set-options') | ||
proto.parse = require('./parse') | ||
/* Expose `defaults`. */ | ||
proto.options = require('./defaults'); | ||
// Expose `defaults`. | ||
proto.options = require('./defaults') | ||
/* Enter and exit helpers. */ | ||
proto.exitStart = toggle('atStart', true); | ||
proto.enterList = toggle('inList', false); | ||
proto.enterLink = toggle('inLink', false); | ||
proto.enterBlock = toggle('inBlock', false); | ||
// Enter and exit helpers. | ||
proto.exitStart = toggle('atStart', true) | ||
proto.enterList = toggle('inList', false) | ||
proto.enterLink = toggle('inLink', false) | ||
proto.enterBlock = toggle('inBlock', false) | ||
/* Nodes that can interupt a paragraph: | ||
* | ||
* ```markdown | ||
* A paragraph, followed by a thematic break. | ||
* ___ | ||
* ``` | ||
* | ||
* In the above example, the thematic break “interupts” | ||
* the paragraph. */ | ||
// Nodes that can interupt a paragraph: | ||
// | ||
// ```markdown | ||
// A paragraph, followed by a thematic break. | ||
// ___ | ||
// ``` | ||
// | ||
// In the above example, the thematic break “interupts” the paragraph. | ||
proto.interruptParagraph = [ | ||
@@ -61,13 +60,12 @@ ['thematicBreak'], | ||
['footnote', {commonmark: false}] | ||
]; | ||
] | ||
/* Nodes that can interupt a list: | ||
* | ||
* ```markdown | ||
* - One | ||
* ___ | ||
* ``` | ||
* | ||
* In the above example, the thematic break “interupts” | ||
* the list. */ | ||
// Nodes that can interupt a list: | ||
// | ||
// ```markdown | ||
// - One | ||
// ___ | ||
// ``` | ||
// | ||
// In the above example, the thematic break “interupts” the list. | ||
proto.interruptList = [ | ||
@@ -79,13 +77,12 @@ ['atxHeading', {pedantic: false}], | ||
['footnote', {commonmark: false}] | ||
]; | ||
] | ||
/* Nodes that can interupt a blockquote: | ||
* | ||
* ```markdown | ||
* > A paragraph. | ||
* ___ | ||
* ``` | ||
* | ||
* In the above example, the thematic break “interupts” | ||
* the blockquote. */ | ||
// Nodes that can interupt a blockquote: | ||
// | ||
// ```markdown | ||
// > A paragraph. | ||
// ___ | ||
// ``` | ||
// | ||
// In the above example, the thematic break “interupts” the blockquote. | ||
proto.interruptBlockquote = [ | ||
@@ -101,5 +98,5 @@ ['indentedCode', {commonmark: true}], | ||
['footnote', {commonmark: false}] | ||
]; | ||
] | ||
/* Handlers. */ | ||
// Handlers. | ||
proto.blockTokenizers = { | ||
@@ -119,3 +116,3 @@ newline: require('./tokenize/newline'), | ||
paragraph: require('./tokenize/paragraph') | ||
}; | ||
} | ||
@@ -135,23 +132,23 @@ proto.inlineTokenizers = { | ||
text: require('./tokenize/text') | ||
}; | ||
} | ||
/* Expose precedence. */ | ||
proto.blockMethods = keys(proto.blockTokenizers); | ||
proto.inlineMethods = keys(proto.inlineTokenizers); | ||
// Expose precedence. | ||
proto.blockMethods = keys(proto.blockTokenizers) | ||
proto.inlineMethods = keys(proto.inlineTokenizers) | ||
/* Tokenizers. */ | ||
proto.tokenizeBlock = tokenizer('block'); | ||
proto.tokenizeInline = tokenizer('inline'); | ||
proto.tokenizeFactory = tokenizer; | ||
// Tokenizers. | ||
proto.tokenizeBlock = tokenizer('block') | ||
proto.tokenizeInline = tokenizer('inline') | ||
proto.tokenizeFactory = tokenizer | ||
/* Get all keys in `value`. */ | ||
// Get all keys in `value`. | ||
function keys(value) { | ||
var result = []; | ||
var key; | ||
var result = [] | ||
var key | ||
for (key in value) { | ||
result.push(key); | ||
result.push(key) | ||
} | ||
return result; | ||
return result | ||
} |
@@ -1,31 +0,28 @@ | ||
'use strict'; | ||
'use strict' | ||
var xtend = require('xtend'); | ||
var escapes = require('markdown-escapes'); | ||
var defaults = require('./defaults'); | ||
var xtend = require('xtend') | ||
var escapes = require('markdown-escapes') | ||
var defaults = require('./defaults') | ||
module.exports = setOptions; | ||
module.exports = setOptions | ||
function setOptions(options) { | ||
var self = this; | ||
var current = self.options; | ||
var key; | ||
var value; | ||
var self = this | ||
var current = self.options | ||
var key | ||
var value | ||
if (options == null) { | ||
options = {}; | ||
options = {} | ||
} else if (typeof options === 'object') { | ||
options = xtend(options); | ||
options = xtend(options) | ||
} else { | ||
throw new Error( | ||
'Invalid value `' + options + '` ' + | ||
'for setting `options`' | ||
); | ||
throw new Error('Invalid value `' + options + '` for setting `options`') | ||
} | ||
for (key in defaults) { | ||
value = options[key]; | ||
value = options[key] | ||
if (value == null) { | ||
value = current[key]; | ||
value = current[key] | ||
} | ||
@@ -37,12 +34,14 @@ | ||
) { | ||
throw new Error('Invalid value `' + value + '` for setting `options.' + key + '`'); | ||
throw new Error( | ||
'Invalid value `' + value + '` for setting `options.' + key + '`' | ||
) | ||
} | ||
options[key] = value; | ||
options[key] = value | ||
} | ||
self.options = options; | ||
self.escape = escapes(options); | ||
self.options = options | ||
self.escape = escapes(options) | ||
return self; | ||
return self | ||
} |
@@ -1,104 +0,92 @@ | ||
'use strict'; | ||
'use strict' | ||
var whitespace = require('is-whitespace-character'); | ||
var decode = require('parse-entities'); | ||
var locate = require('../locate/tag'); | ||
var whitespace = require('is-whitespace-character') | ||
var decode = require('parse-entities') | ||
var locate = require('../locate/tag') | ||
module.exports = autoLink; | ||
autoLink.locator = locate; | ||
autoLink.notInLink = true; | ||
module.exports = autoLink | ||
autoLink.locator = locate | ||
autoLink.notInLink = true | ||
var C_LT = '<'; | ||
var C_GT = '>'; | ||
var C_AT_SIGN = '@'; | ||
var C_SLASH = '/'; | ||
var MAILTO = 'mailto:'; | ||
var MAILTO_LENGTH = MAILTO.length; | ||
var lessThan = '<' | ||
var greaterThan = '>' | ||
var atSign = '@' | ||
var slash = '/' | ||
var mailto = 'mailto:' | ||
var mailtoLength = mailto.length | ||
/* Tokenise a link. */ | ||
function autoLink(eat, value, silent) { | ||
var self; | ||
var subvalue; | ||
var length; | ||
var index; | ||
var queue; | ||
var character; | ||
var hasAtCharacter; | ||
var link; | ||
var now; | ||
var content; | ||
var tokenizers; | ||
var exit; | ||
var self = this | ||
var subvalue = '' | ||
var length = value.length | ||
var index = 0 | ||
var queue = '' | ||
var hasAtCharacter = false | ||
var link = '' | ||
var character | ||
var now | ||
var content | ||
var tokenizers | ||
var exit | ||
if (value.charAt(0) !== C_LT) { | ||
return; | ||
if (value.charAt(0) !== lessThan) { | ||
return | ||
} | ||
self = this; | ||
subvalue = ''; | ||
length = value.length; | ||
index = 0; | ||
queue = ''; | ||
hasAtCharacter = false; | ||
link = ''; | ||
index++ | ||
subvalue = lessThan | ||
index++; | ||
subvalue = C_LT; | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if ( | ||
whitespace(character) || | ||
character === C_GT || | ||
character === C_AT_SIGN || | ||
(character === ':' && value.charAt(index + 1) === C_SLASH) | ||
character === greaterThan || | ||
character === atSign || | ||
(character === ':' && value.charAt(index + 1) === slash) | ||
) { | ||
break; | ||
break | ||
} | ||
queue += character; | ||
index++; | ||
queue += character | ||
index++ | ||
} | ||
if (!queue) { | ||
return; | ||
return | ||
} | ||
link += queue; | ||
queue = ''; | ||
link += queue | ||
queue = '' | ||
character = value.charAt(index); | ||
link += character; | ||
index++; | ||
character = value.charAt(index) | ||
link += character | ||
index++ | ||
if (character === C_AT_SIGN) { | ||
hasAtCharacter = true; | ||
if (character === atSign) { | ||
hasAtCharacter = true | ||
} else { | ||
if ( | ||
character !== ':' || | ||
value.charAt(index + 1) !== C_SLASH | ||
) { | ||
return; | ||
if (character !== ':' || value.charAt(index + 1) !== slash) { | ||
return | ||
} | ||
link += C_SLASH; | ||
index++; | ||
link += slash | ||
index++ | ||
} | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (whitespace(character) || character === C_GT) { | ||
break; | ||
if (whitespace(character) || character === greaterThan) { | ||
break | ||
} | ||
queue += character; | ||
index++; | ||
queue += character | ||
index++ | ||
} | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (!queue || character !== C_GT) { | ||
return; | ||
if (!queue || character !== greaterThan) { | ||
return | ||
} | ||
@@ -108,32 +96,32 @@ | ||
if (silent) { | ||
return true; | ||
return true | ||
} | ||
link += queue; | ||
content = link; | ||
subvalue += link + character; | ||
now = eat.now(); | ||
now.column++; | ||
now.offset++; | ||
link += queue | ||
content = link | ||
subvalue += link + character | ||
now = eat.now() | ||
now.column++ | ||
now.offset++ | ||
if (hasAtCharacter) { | ||
if (link.slice(0, MAILTO_LENGTH).toLowerCase() === MAILTO) { | ||
content = content.substr(MAILTO_LENGTH); | ||
now.column += MAILTO_LENGTH; | ||
now.offset += MAILTO_LENGTH; | ||
if (link.slice(0, mailtoLength).toLowerCase() === mailto) { | ||
content = content.substr(mailtoLength) | ||
now.column += mailtoLength | ||
now.offset += mailtoLength | ||
} else { | ||
link = MAILTO + link; | ||
link = mailto + link | ||
} | ||
} | ||
/* Temporarily remove all tokenizers except text in autolinks. */ | ||
tokenizers = self.inlineTokenizers; | ||
self.inlineTokenizers = {text: tokenizers.text}; | ||
// Temporarily remove all tokenizers except text in autolinks. | ||
tokenizers = self.inlineTokenizers | ||
self.inlineTokenizers = {text: tokenizers.text} | ||
exit = self.enterLink(); | ||
exit = self.enterLink() | ||
content = self.tokenizeInline(content, now); | ||
content = self.tokenizeInline(content, now) | ||
self.inlineTokenizers = tokenizers; | ||
exit(); | ||
self.inlineTokenizers = tokenizers | ||
exit() | ||
@@ -145,3 +133,3 @@ return eat(subvalue)({ | ||
children: content | ||
}); | ||
}) | ||
} |
@@ -1,129 +0,124 @@ | ||
'use strict'; | ||
'use strict' | ||
var trim = require('trim'); | ||
var interrupt = require('../util/interrupt'); | ||
var trim = require('trim') | ||
var interrupt = require('../util/interrupt') | ||
module.exports = blockquote; | ||
module.exports = blockquote | ||
var C_NEWLINE = '\n'; | ||
var C_TAB = '\t'; | ||
var C_SPACE = ' '; | ||
var C_GT = '>'; | ||
var lineFeed = '\n' | ||
var tab = '\t' | ||
var space = ' ' | ||
var greaterThan = '>' | ||
/* Tokenise a blockquote. */ | ||
function blockquote(eat, value, silent) { | ||
var self = this; | ||
var offsets = self.offset; | ||
var tokenizers = self.blockTokenizers; | ||
var interruptors = self.interruptBlockquote; | ||
var now = eat.now(); | ||
var currentLine = now.line; | ||
var length = value.length; | ||
var values = []; | ||
var contents = []; | ||
var indents = []; | ||
var add; | ||
var index = 0; | ||
var character; | ||
var rest; | ||
var nextIndex; | ||
var content; | ||
var line; | ||
var startIndex; | ||
var prefixed; | ||
var exit; | ||
var self = this | ||
var offsets = self.offset | ||
var tokenizers = self.blockTokenizers | ||
var interruptors = self.interruptBlockquote | ||
var now = eat.now() | ||
var currentLine = now.line | ||
var length = value.length | ||
var values = [] | ||
var contents = [] | ||
var indents = [] | ||
var add | ||
var index = 0 | ||
var character | ||
var rest | ||
var nextIndex | ||
var content | ||
var line | ||
var startIndex | ||
var prefixed | ||
var exit | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character !== C_SPACE && character !== C_TAB) { | ||
break; | ||
if (character !== space && character !== tab) { | ||
break | ||
} | ||
index++; | ||
index++ | ||
} | ||
if (value.charAt(index) !== C_GT) { | ||
return; | ||
if (value.charAt(index) !== greaterThan) { | ||
return | ||
} | ||
if (silent) { | ||
return true; | ||
return true | ||
} | ||
index = 0; | ||
index = 0 | ||
while (index < length) { | ||
nextIndex = value.indexOf(C_NEWLINE, index); | ||
startIndex = index; | ||
prefixed = false; | ||
nextIndex = value.indexOf(lineFeed, index) | ||
startIndex = index | ||
prefixed = false | ||
if (nextIndex === -1) { | ||
nextIndex = length; | ||
nextIndex = length | ||
} | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character !== C_SPACE && character !== C_TAB) { | ||
break; | ||
if (character !== space && character !== tab) { | ||
break | ||
} | ||
index++; | ||
index++ | ||
} | ||
if (value.charAt(index) === C_GT) { | ||
index++; | ||
prefixed = true; | ||
if (value.charAt(index) === greaterThan) { | ||
index++ | ||
prefixed = true | ||
if (value.charAt(index) === C_SPACE) { | ||
index++; | ||
if (value.charAt(index) === space) { | ||
index++ | ||
} | ||
} else { | ||
index = startIndex; | ||
index = startIndex | ||
} | ||
content = value.slice(index, nextIndex); | ||
content = value.slice(index, nextIndex) | ||
if (!prefixed && !trim(content)) { | ||
index = startIndex; | ||
break; | ||
index = startIndex | ||
break | ||
} | ||
if (!prefixed) { | ||
rest = value.slice(index); | ||
rest = value.slice(index) | ||
/* Check if the following code contains a possible | ||
* block. */ | ||
// Check if the following code contains a possible block. | ||
if (interrupt(interruptors, tokenizers, self, [eat, rest, true])) { | ||
break; | ||
break | ||
} | ||
} | ||
line = startIndex === index ? content : value.slice(startIndex, nextIndex); | ||
line = startIndex === index ? content : value.slice(startIndex, nextIndex) | ||
indents.push(index - startIndex); | ||
values.push(line); | ||
contents.push(content); | ||
indents.push(index - startIndex) | ||
values.push(line) | ||
contents.push(content) | ||
index = nextIndex + 1; | ||
index = nextIndex + 1 | ||
} | ||
index = -1; | ||
length = indents.length; | ||
add = eat(values.join(C_NEWLINE)); | ||
index = -1 | ||
length = indents.length | ||
add = eat(values.join(lineFeed)) | ||
while (++index < length) { | ||
offsets[currentLine] = (offsets[currentLine] || 0) + indents[index]; | ||
currentLine++; | ||
offsets[currentLine] = (offsets[currentLine] || 0) + indents[index] | ||
currentLine++ | ||
} | ||
exit = self.enterBlock(); | ||
contents = self.tokenizeBlock(contents.join(C_NEWLINE), now); | ||
exit(); | ||
exit = self.enterBlock() | ||
contents = self.tokenizeBlock(contents.join(lineFeed), now) | ||
exit() | ||
return add({ | ||
type: 'blockquote', | ||
children: contents | ||
}); | ||
return add({type: 'blockquote', children: contents}) | ||
} |
@@ -1,22 +0,24 @@ | ||
'use strict'; | ||
'use strict' | ||
var locate = require('../locate/break'); | ||
var locate = require('../locate/break') | ||
module.exports = hardBreak; | ||
hardBreak.locator = locate; | ||
module.exports = hardBreak | ||
hardBreak.locator = locate | ||
var MIN_BREAK_LENGTH = 2; | ||
var space = ' ' | ||
var lineFeed = '\n' | ||
var minBreakLength = 2 | ||
function hardBreak(eat, value, silent) { | ||
var length = value.length; | ||
var index = -1; | ||
var queue = ''; | ||
var character; | ||
var length = value.length | ||
var index = -1 | ||
var queue = '' | ||
var character | ||
while (++index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character === '\n') { | ||
if (index < MIN_BREAK_LENGTH) { | ||
return; | ||
if (character === lineFeed) { | ||
if (index < minBreakLength) { | ||
return | ||
} | ||
@@ -26,16 +28,16 @@ | ||
if (silent) { | ||
return true; | ||
return true | ||
} | ||
queue += character; | ||
queue += character | ||
return eat(queue)({type: 'break'}); | ||
return eat(queue)({type: 'break'}) | ||
} | ||
if (character !== ' ') { | ||
return; | ||
if (character !== space) { | ||
return | ||
} | ||
queue += character; | ||
queue += character | ||
} | ||
} |
@@ -1,236 +0,255 @@ | ||
'use strict'; | ||
'use strict' | ||
var trim = require('trim-trailing-lines'); | ||
var trim = require('trim-trailing-lines') | ||
module.exports = fencedCode; | ||
module.exports = fencedCode | ||
var C_NEWLINE = '\n'; | ||
var C_TAB = '\t'; | ||
var C_SPACE = ' '; | ||
var C_TILDE = '~'; | ||
var C_TICK = '`'; | ||
var lineFeed = '\n' | ||
var tab = '\t' | ||
var space = ' ' | ||
var tilde = '~' | ||
var graveAccent = '`' | ||
var MIN_FENCE_COUNT = 3; | ||
var CODE_INDENT_COUNT = 4; | ||
var minFenceCount = 3 | ||
var tabSize = 4 | ||
function fencedCode(eat, value, silent) { | ||
var self = this; | ||
var settings = self.options; | ||
var length = value.length + 1; | ||
var index = 0; | ||
var subvalue = ''; | ||
var fenceCount; | ||
var marker; | ||
var character; | ||
var flag; | ||
var queue; | ||
var content; | ||
var exdentedContent; | ||
var closing; | ||
var exdentedClosing; | ||
var indent; | ||
var now; | ||
var self = this | ||
var gfm = self.options.gfm | ||
var length = value.length + 1 | ||
var index = 0 | ||
var subvalue = '' | ||
var fenceCount | ||
var marker | ||
var character | ||
var flag | ||
var lang | ||
var meta | ||
var queue | ||
var content | ||
var exdentedContent | ||
var closing | ||
var exdentedClosing | ||
var indent | ||
var now | ||
if (!settings.gfm) { | ||
return; | ||
if (!gfm) { | ||
return | ||
} | ||
/* Eat initial spacing. */ | ||
// Eat initial spacing. | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character !== C_SPACE && character !== C_TAB) { | ||
break; | ||
if (character !== space && character !== tab) { | ||
break | ||
} | ||
subvalue += character; | ||
index++; | ||
subvalue += character | ||
index++ | ||
} | ||
indent = index; | ||
indent = index | ||
/* Eat the fence. */ | ||
character = value.charAt(index); | ||
// Eat the fence. | ||
character = value.charAt(index) | ||
if (character !== C_TILDE && character !== C_TICK) { | ||
return; | ||
if (character !== tilde && character !== graveAccent) { | ||
return | ||
} | ||
index++; | ||
marker = character; | ||
fenceCount = 1; | ||
subvalue += character; | ||
index++ | ||
marker = character | ||
fenceCount = 1 | ||
subvalue += character | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character !== marker) { | ||
break; | ||
break | ||
} | ||
subvalue += character; | ||
fenceCount++; | ||
index++; | ||
subvalue += character | ||
fenceCount++ | ||
index++ | ||
} | ||
if (fenceCount < MIN_FENCE_COUNT) { | ||
return; | ||
if (fenceCount < minFenceCount) { | ||
return | ||
} | ||
/* Eat spacing before flag. */ | ||
// Eat spacing before flag. | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character !== C_SPACE && character !== C_TAB) { | ||
break; | ||
if (character !== space && character !== tab) { | ||
break | ||
} | ||
subvalue += character; | ||
index++; | ||
subvalue += character | ||
index++ | ||
} | ||
/* Eat flag. */ | ||
flag = ''; | ||
queue = ''; | ||
// Eat flag. | ||
flag = '' | ||
queue = '' | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if ( | ||
character === C_NEWLINE || | ||
character === C_TILDE || | ||
character === C_TICK | ||
character === lineFeed || | ||
character === tilde || | ||
character === graveAccent | ||
) { | ||
break; | ||
break | ||
} | ||
if (character === C_SPACE || character === C_TAB) { | ||
queue += character; | ||
if (character === space || character === tab) { | ||
queue += character | ||
} else { | ||
flag += queue + character; | ||
queue = ''; | ||
flag += queue + character | ||
queue = '' | ||
} | ||
index++; | ||
index++ | ||
} | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character && character !== C_NEWLINE) { | ||
return; | ||
if (character && character !== lineFeed) { | ||
return | ||
} | ||
if (silent) { | ||
return true; | ||
return true | ||
} | ||
now = eat.now(); | ||
now.column += subvalue.length; | ||
now.offset += subvalue.length; | ||
now = eat.now() | ||
now.column += subvalue.length | ||
now.offset += subvalue.length | ||
subvalue += flag; | ||
flag = self.decode.raw(self.unescape(flag), now); | ||
subvalue += flag | ||
flag = self.decode.raw(self.unescape(flag), now) | ||
if (queue) { | ||
subvalue += queue; | ||
subvalue += queue | ||
} | ||
queue = ''; | ||
closing = ''; | ||
exdentedClosing = ''; | ||
content = ''; | ||
exdentedContent = ''; | ||
queue = '' | ||
closing = '' | ||
exdentedClosing = '' | ||
content = '' | ||
exdentedContent = '' | ||
/* Eat content. */ | ||
// Eat content. | ||
while (index < length) { | ||
character = value.charAt(index); | ||
content += closing; | ||
exdentedContent += exdentedClosing; | ||
closing = ''; | ||
exdentedClosing = ''; | ||
character = value.charAt(index) | ||
content += closing | ||
exdentedContent += exdentedClosing | ||
closing = '' | ||
exdentedClosing = '' | ||
if (character !== C_NEWLINE) { | ||
content += character; | ||
exdentedClosing += character; | ||
index++; | ||
continue; | ||
if (character !== lineFeed) { | ||
content += character | ||
exdentedClosing += character | ||
index++ | ||
continue | ||
} | ||
/* Add the newline to `subvalue` if its the first | ||
* character. Otherwise, add it to the `closing` | ||
* queue. */ | ||
// Add the newline to `subvalue` if its the first character. Otherwise, | ||
// add it to the `closing` queue. | ||
if (content) { | ||
closing += character; | ||
exdentedClosing += character; | ||
closing += character | ||
exdentedClosing += character | ||
} else { | ||
subvalue += character; | ||
subvalue += character | ||
} | ||
queue = ''; | ||
index++; | ||
queue = '' | ||
index++ | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character !== C_SPACE) { | ||
break; | ||
if (character !== space) { | ||
break | ||
} | ||
queue += character; | ||
index++; | ||
queue += character | ||
index++ | ||
} | ||
closing += queue; | ||
exdentedClosing += queue.slice(indent); | ||
closing += queue | ||
exdentedClosing += queue.slice(indent) | ||
if (queue.length >= CODE_INDENT_COUNT) { | ||
continue; | ||
if (queue.length >= tabSize) { | ||
continue | ||
} | ||
queue = ''; | ||
queue = '' | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character !== marker) { | ||
break; | ||
break | ||
} | ||
queue += character; | ||
index++; | ||
queue += character | ||
index++ | ||
} | ||
closing += queue; | ||
exdentedClosing += queue; | ||
closing += queue | ||
exdentedClosing += queue | ||
if (queue.length < fenceCount) { | ||
continue; | ||
continue | ||
} | ||
queue = ''; | ||
queue = '' | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character !== C_SPACE && character !== C_TAB) { | ||
break; | ||
if (character !== space && character !== tab) { | ||
break | ||
} | ||
closing += character; | ||
exdentedClosing += character; | ||
index++; | ||
closing += character | ||
exdentedClosing += character | ||
index++ | ||
} | ||
if (!character || character === C_NEWLINE) { | ||
break; | ||
if (!character || character === lineFeed) { | ||
break | ||
} | ||
} | ||
subvalue += content + closing; | ||
subvalue += content + closing | ||
// Get lang and meta from the flag. | ||
index = -1 | ||
length = flag.length | ||
while (++index < length) { | ||
character = flag.charAt(index) | ||
if (character === space || character === tab) { | ||
if (!lang) { | ||
lang = flag.slice(0, index) | ||
} | ||
} else if (lang) { | ||
meta = flag.slice(index) | ||
break | ||
} | ||
} | ||
return eat(subvalue)({ | ||
type: 'code', | ||
lang: flag || null, | ||
lang: lang || flag || null, | ||
meta: meta || null, | ||
value: trim(exdentedContent) | ||
}); | ||
}) | ||
} |
@@ -1,60 +0,59 @@ | ||
'use strict'; | ||
'use strict' | ||
var repeat = require('repeat-string'); | ||
var trim = require('trim-trailing-lines'); | ||
var repeat = require('repeat-string') | ||
var trim = require('trim-trailing-lines') | ||
module.exports = indentedCode; | ||
module.exports = indentedCode | ||
var C_NEWLINE = '\n'; | ||
var C_TAB = '\t'; | ||
var C_SPACE = ' '; | ||
var lineFeed = '\n' | ||
var tab = '\t' | ||
var space = ' ' | ||
var CODE_INDENT_COUNT = 4; | ||
var CODE_INDENT = repeat(C_SPACE, CODE_INDENT_COUNT); | ||
var tabSize = 4 | ||
var codeIndent = repeat(space, tabSize) | ||
/* Tokenise indented code. */ | ||
function indentedCode(eat, value, silent) { | ||
var index = -1; | ||
var length = value.length; | ||
var subvalue = ''; | ||
var content = ''; | ||
var subvalueQueue = ''; | ||
var contentQueue = ''; | ||
var character; | ||
var blankQueue; | ||
var indent; | ||
var index = -1 | ||
var length = value.length | ||
var subvalue = '' | ||
var content = '' | ||
var subvalueQueue = '' | ||
var contentQueue = '' | ||
var character | ||
var blankQueue | ||
var indent | ||
while (++index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (indent) { | ||
indent = false; | ||
indent = false | ||
subvalue += subvalueQueue; | ||
content += contentQueue; | ||
subvalueQueue = ''; | ||
contentQueue = ''; | ||
subvalue += subvalueQueue | ||
content += contentQueue | ||
subvalueQueue = '' | ||
contentQueue = '' | ||
if (character === C_NEWLINE) { | ||
subvalueQueue = character; | ||
contentQueue = character; | ||
if (character === lineFeed) { | ||
subvalueQueue = character | ||
contentQueue = character | ||
} else { | ||
subvalue += character; | ||
content += character; | ||
subvalue += character | ||
content += character | ||
while (++index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (!character || character === C_NEWLINE) { | ||
contentQueue = character; | ||
subvalueQueue = character; | ||
break; | ||
if (!character || character === lineFeed) { | ||
contentQueue = character | ||
subvalueQueue = character | ||
break | ||
} | ||
subvalue += character; | ||
content += character; | ||
subvalue += character | ||
content += character | ||
} | ||
} | ||
} else if ( | ||
character === C_SPACE && | ||
character === space && | ||
value.charAt(index + 1) === character && | ||
@@ -64,22 +63,22 @@ value.charAt(index + 2) === character && | ||
) { | ||
subvalueQueue += CODE_INDENT; | ||
index += 3; | ||
indent = true; | ||
} else if (character === C_TAB) { | ||
subvalueQueue += character; | ||
indent = true; | ||
subvalueQueue += codeIndent | ||
index += 3 | ||
indent = true | ||
} else if (character === tab) { | ||
subvalueQueue += character | ||
indent = true | ||
} else { | ||
blankQueue = ''; | ||
blankQueue = '' | ||
while (character === C_TAB || character === C_SPACE) { | ||
blankQueue += character; | ||
character = value.charAt(++index); | ||
while (character === tab || character === space) { | ||
blankQueue += character | ||
character = value.charAt(++index) | ||
} | ||
if (character !== C_NEWLINE) { | ||
break; | ||
if (character !== lineFeed) { | ||
break | ||
} | ||
subvalueQueue += blankQueue + character; | ||
contentQueue += character; | ||
subvalueQueue += blankQueue + character | ||
contentQueue += character | ||
} | ||
@@ -90,3 +89,3 @@ } | ||
if (silent) { | ||
return true; | ||
return true | ||
} | ||
@@ -97,5 +96,6 @@ | ||
lang: null, | ||
meta: null, | ||
value: trim(content) | ||
}); | ||
}) | ||
} | ||
} |
@@ -1,69 +0,68 @@ | ||
'use strict'; | ||
'use strict' | ||
var whitespace = require('is-whitespace-character'); | ||
var locate = require('../locate/code-inline'); | ||
var whitespace = require('is-whitespace-character') | ||
var locate = require('../locate/code-inline') | ||
module.exports = inlineCode; | ||
inlineCode.locator = locate; | ||
module.exports = inlineCode | ||
inlineCode.locator = locate | ||
var C_TICK = '`'; | ||
var graveAccent = '`' | ||
/* Tokenise inline code. */ | ||
function inlineCode(eat, value, silent) { | ||
var length = value.length; | ||
var index = 0; | ||
var queue = ''; | ||
var tickQueue = ''; | ||
var contentQueue; | ||
var subqueue; | ||
var count; | ||
var openingCount; | ||
var subvalue; | ||
var character; | ||
var found; | ||
var next; | ||
var length = value.length | ||
var index = 0 | ||
var queue = '' | ||
var tickQueue = '' | ||
var contentQueue | ||
var subqueue | ||
var count | ||
var openingCount | ||
var subvalue | ||
var character | ||
var found | ||
var next | ||
while (index < length) { | ||
if (value.charAt(index) !== C_TICK) { | ||
break; | ||
if (value.charAt(index) !== graveAccent) { | ||
break | ||
} | ||
queue += C_TICK; | ||
index++; | ||
queue += graveAccent | ||
index++ | ||
} | ||
if (!queue) { | ||
return; | ||
return | ||
} | ||
subvalue = queue; | ||
openingCount = index; | ||
queue = ''; | ||
next = value.charAt(index); | ||
count = 0; | ||
subvalue = queue | ||
openingCount = index | ||
queue = '' | ||
next = value.charAt(index) | ||
count = 0 | ||
while (index < length) { | ||
character = next; | ||
next = value.charAt(index + 1); | ||
character = next | ||
next = value.charAt(index + 1) | ||
if (character === C_TICK) { | ||
count++; | ||
tickQueue += character; | ||
if (character === graveAccent) { | ||
count++ | ||
tickQueue += character | ||
} else { | ||
count = 0; | ||
queue += character; | ||
count = 0 | ||
queue += character | ||
} | ||
if (count && next !== C_TICK) { | ||
if (count && next !== graveAccent) { | ||
if (count === openingCount) { | ||
subvalue += queue + tickQueue; | ||
found = true; | ||
break; | ||
subvalue += queue + tickQueue | ||
found = true | ||
break | ||
} | ||
queue += tickQueue; | ||
tickQueue = ''; | ||
queue += tickQueue | ||
tickQueue = '' | ||
} | ||
index++; | ||
index++ | ||
} | ||
@@ -73,6 +72,6 @@ | ||
if (openingCount % 2 !== 0) { | ||
return; | ||
return | ||
} | ||
queue = ''; | ||
queue = '' | ||
} | ||
@@ -82,16 +81,16 @@ | ||
if (silent) { | ||
return true; | ||
return true | ||
} | ||
contentQueue = ''; | ||
subqueue = ''; | ||
length = queue.length; | ||
index = -1; | ||
contentQueue = '' | ||
subqueue = '' | ||
length = queue.length | ||
index = -1 | ||
while (++index < length) { | ||
character = queue.charAt(index); | ||
character = queue.charAt(index) | ||
if (whitespace(character)) { | ||
subqueue += character; | ||
continue; | ||
subqueue += character | ||
continue | ||
} | ||
@@ -101,15 +100,12 @@ | ||
if (contentQueue) { | ||
contentQueue += subqueue; | ||
contentQueue += subqueue | ||
} | ||
subqueue = ''; | ||
subqueue = '' | ||
} | ||
contentQueue += character; | ||
contentQueue += character | ||
} | ||
return eat(subvalue)({ | ||
type: 'inlineCode', | ||
value: contentQueue | ||
}); | ||
return eat(subvalue)({type: 'inlineCode', value: contentQueue}) | ||
} |
@@ -1,73 +0,73 @@ | ||
'use strict'; | ||
'use strict' | ||
var whitespace = require('is-whitespace-character'); | ||
var normalize = require('../util/normalize'); | ||
var whitespace = require('is-whitespace-character') | ||
var normalize = require('../util/normalize') | ||
module.exports = definition; | ||
definition.notInList = true; | ||
definition.notInBlock = true; | ||
module.exports = definition | ||
definition.notInList = true | ||
definition.notInBlock = true | ||
var C_DOUBLE_QUOTE = '"'; | ||
var C_SINGLE_QUOTE = '\''; | ||
var C_BACKSLASH = '\\'; | ||
var C_NEWLINE = '\n'; | ||
var C_TAB = '\t'; | ||
var C_SPACE = ' '; | ||
var C_BRACKET_OPEN = '['; | ||
var C_BRACKET_CLOSE = ']'; | ||
var C_PAREN_OPEN = '('; | ||
var C_PAREN_CLOSE = ')'; | ||
var C_COLON = ':'; | ||
var C_LT = '<'; | ||
var C_GT = '>'; | ||
var quotationMark = '"' | ||
var apostrophe = "'" | ||
var backslash = '\\' | ||
var lineFeed = '\n' | ||
var tab = '\t' | ||
var space = ' ' | ||
var leftSquareBracket = '[' | ||
var rightSquareBracket = ']' | ||
var leftParenthesis = '(' | ||
var rightParenthesis = ')' | ||
var colon = ':' | ||
var lessThan = '<' | ||
var greaterThan = '>' | ||
function definition(eat, value, silent) { | ||
var self = this; | ||
var commonmark = self.options.commonmark; | ||
var index = 0; | ||
var length = value.length; | ||
var subvalue = ''; | ||
var beforeURL; | ||
var beforeTitle; | ||
var queue; | ||
var character; | ||
var test; | ||
var identifier; | ||
var url; | ||
var title; | ||
var self = this | ||
var commonmark = self.options.commonmark | ||
var index = 0 | ||
var length = value.length | ||
var subvalue = '' | ||
var beforeURL | ||
var beforeTitle | ||
var queue | ||
var character | ||
var test | ||
var identifier | ||
var url | ||
var title | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character !== C_SPACE && character !== C_TAB) { | ||
break; | ||
if (character !== space && character !== tab) { | ||
break | ||
} | ||
subvalue += character; | ||
index++; | ||
subvalue += character | ||
index++ | ||
} | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character !== C_BRACKET_OPEN) { | ||
return; | ||
if (character !== leftSquareBracket) { | ||
return | ||
} | ||
index++; | ||
subvalue += character; | ||
queue = ''; | ||
index++ | ||
subvalue += character | ||
queue = '' | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character === C_BRACKET_CLOSE) { | ||
break; | ||
} else if (character === C_BACKSLASH) { | ||
queue += character; | ||
index++; | ||
character = value.charAt(index); | ||
if (character === rightSquareBracket) { | ||
break | ||
} else if (character === backslash) { | ||
queue += character | ||
index++ | ||
character = value.charAt(index) | ||
} | ||
queue += character; | ||
index++; | ||
queue += character | ||
index++ | ||
} | ||
@@ -77,58 +77,54 @@ | ||
!queue || | ||
value.charAt(index) !== C_BRACKET_CLOSE || | ||
value.charAt(index + 1) !== C_COLON | ||
value.charAt(index) !== rightSquareBracket || | ||
value.charAt(index + 1) !== colon | ||
) { | ||
return; | ||
return | ||
} | ||
identifier = queue; | ||
subvalue += queue + C_BRACKET_CLOSE + C_COLON; | ||
index = subvalue.length; | ||
queue = ''; | ||
identifier = queue | ||
subvalue += queue + rightSquareBracket + colon | ||
index = subvalue.length | ||
queue = '' | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if ( | ||
character !== C_TAB && | ||
character !== C_SPACE && | ||
character !== C_NEWLINE | ||
) { | ||
break; | ||
if (character !== tab && character !== space && character !== lineFeed) { | ||
break | ||
} | ||
subvalue += character; | ||
index++; | ||
subvalue += character | ||
index++ | ||
} | ||
character = value.charAt(index); | ||
queue = ''; | ||
beforeURL = subvalue; | ||
character = value.charAt(index) | ||
queue = '' | ||
beforeURL = subvalue | ||
if (character === C_LT) { | ||
index++; | ||
if (character === lessThan) { | ||
index++ | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (!isEnclosedURLCharacter(character)) { | ||
break; | ||
break | ||
} | ||
queue += character; | ||
index++; | ||
queue += character | ||
index++ | ||
} | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character === isEnclosedURLCharacter.delimiter) { | ||
subvalue += C_LT + queue + character; | ||
index++; | ||
subvalue += lessThan + queue + character | ||
index++ | ||
} else { | ||
if (commonmark) { | ||
return; | ||
return | ||
} | ||
index -= queue.length + 1; | ||
queue = ''; | ||
index -= queue.length + 1 | ||
queue = '' | ||
} | ||
@@ -139,117 +135,113 @@ } | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (!isUnclosedURLCharacter(character)) { | ||
break; | ||
break | ||
} | ||
queue += character; | ||
index++; | ||
queue += character | ||
index++ | ||
} | ||
subvalue += queue; | ||
subvalue += queue | ||
} | ||
if (!queue) { | ||
return; | ||
return | ||
} | ||
url = queue; | ||
queue = ''; | ||
url = queue | ||
queue = '' | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if ( | ||
character !== C_TAB && | ||
character !== C_SPACE && | ||
character !== C_NEWLINE | ||
) { | ||
break; | ||
if (character !== tab && character !== space && character !== lineFeed) { | ||
break | ||
} | ||
queue += character; | ||
index++; | ||
queue += character | ||
index++ | ||
} | ||
character = value.charAt(index); | ||
test = null; | ||
character = value.charAt(index) | ||
test = null | ||
if (character === C_DOUBLE_QUOTE) { | ||
test = C_DOUBLE_QUOTE; | ||
} else if (character === C_SINGLE_QUOTE) { | ||
test = C_SINGLE_QUOTE; | ||
} else if (character === C_PAREN_OPEN) { | ||
test = C_PAREN_CLOSE; | ||
if (character === quotationMark) { | ||
test = quotationMark | ||
} else if (character === apostrophe) { | ||
test = apostrophe | ||
} else if (character === leftParenthesis) { | ||
test = rightParenthesis | ||
} | ||
if (!test) { | ||
queue = ''; | ||
index = subvalue.length; | ||
queue = '' | ||
index = subvalue.length | ||
} else if (queue) { | ||
subvalue += queue + character; | ||
index = subvalue.length; | ||
queue = ''; | ||
subvalue += queue + character | ||
index = subvalue.length | ||
queue = '' | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character === test) { | ||
break; | ||
break | ||
} | ||
if (character === C_NEWLINE) { | ||
index++; | ||
character = value.charAt(index); | ||
if (character === lineFeed) { | ||
index++ | ||
character = value.charAt(index) | ||
if (character === C_NEWLINE || character === test) { | ||
return; | ||
if (character === lineFeed || character === test) { | ||
return | ||
} | ||
queue += C_NEWLINE; | ||
queue += lineFeed | ||
} | ||
queue += character; | ||
index++; | ||
queue += character | ||
index++ | ||
} | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character !== test) { | ||
return; | ||
return | ||
} | ||
beforeTitle = subvalue; | ||
subvalue += queue + character; | ||
index++; | ||
title = queue; | ||
queue = ''; | ||
beforeTitle = subvalue | ||
subvalue += queue + character | ||
index++ | ||
title = queue | ||
queue = '' | ||
} else { | ||
return; | ||
return | ||
} | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character !== C_TAB && character !== C_SPACE) { | ||
break; | ||
if (character !== tab && character !== space) { | ||
break | ||
} | ||
subvalue += character; | ||
index++; | ||
subvalue += character | ||
index++ | ||
} | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (!character || character === C_NEWLINE) { | ||
if (!character || character === lineFeed) { | ||
if (silent) { | ||
return true; | ||
return true | ||
} | ||
beforeURL = eat(beforeURL).test().end; | ||
url = self.decode.raw(self.unescape(url), beforeURL, {nonTerminated: false}); | ||
beforeURL = eat(beforeURL).test().end | ||
url = self.decode.raw(self.unescape(url), beforeURL, {nonTerminated: false}) | ||
if (title) { | ||
beforeTitle = eat(beforeTitle).test().end; | ||
title = self.decode.raw(self.unescape(title), beforeTitle); | ||
beforeTitle = eat(beforeTitle).test().end | ||
title = self.decode.raw(self.unescape(title), beforeTitle) | ||
} | ||
@@ -260,22 +252,27 @@ | ||
identifier: normalize(identifier), | ||
label: identifier, | ||
title: title || null, | ||
url: url | ||
}); | ||
}) | ||
} | ||
} | ||
/* Check if `character` can be inside an enclosed URI. */ | ||
// Check if `character` can be inside an enclosed URI. | ||
function isEnclosedURLCharacter(character) { | ||
return character !== C_GT && | ||
character !== C_BRACKET_OPEN && | ||
character !== C_BRACKET_CLOSE; | ||
return ( | ||
character !== greaterThan && | ||
character !== leftSquareBracket && | ||
character !== rightSquareBracket | ||
) | ||
} | ||
isEnclosedURLCharacter.delimiter = C_GT; | ||
isEnclosedURLCharacter.delimiter = greaterThan | ||
/* Check if `character` can be inside an unclosed URI. */ | ||
// Check if `character` can be inside an unclosed URI. | ||
function isUnclosedURLCharacter(character) { | ||
return character !== C_BRACKET_OPEN && | ||
character !== C_BRACKET_CLOSE && | ||
!whitespace(character); | ||
return ( | ||
character !== leftSquareBracket && | ||
character !== rightSquareBracket && | ||
!whitespace(character) | ||
) | ||
} |
@@ -1,43 +0,43 @@ | ||
'use strict'; | ||
'use strict' | ||
var whitespace = require('is-whitespace-character'); | ||
var locate = require('../locate/delete'); | ||
var whitespace = require('is-whitespace-character') | ||
var locate = require('../locate/delete') | ||
module.exports = strikethrough; | ||
strikethrough.locator = locate; | ||
module.exports = strikethrough | ||
strikethrough.locator = locate | ||
var C_TILDE = '~'; | ||
var DOUBLE = '~~'; | ||
var tilde = '~' | ||
var fence = '~~' | ||
function strikethrough(eat, value, silent) { | ||
var self = this; | ||
var character = ''; | ||
var previous = ''; | ||
var preceding = ''; | ||
var subvalue = ''; | ||
var index; | ||
var length; | ||
var now; | ||
var self = this | ||
var character = '' | ||
var previous = '' | ||
var preceding = '' | ||
var subvalue = '' | ||
var index | ||
var length | ||
var now | ||
if ( | ||
!self.options.gfm || | ||
value.charAt(0) !== C_TILDE || | ||
value.charAt(1) !== C_TILDE || | ||
value.charAt(0) !== tilde || | ||
value.charAt(1) !== tilde || | ||
whitespace(value.charAt(2)) | ||
) { | ||
return; | ||
return | ||
} | ||
index = 1; | ||
length = value.length; | ||
now = eat.now(); | ||
now.column += 2; | ||
now.offset += 2; | ||
index = 1 | ||
length = value.length | ||
now = eat.now() | ||
now.column += 2 | ||
now.offset += 2 | ||
while (++index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if ( | ||
character === C_TILDE && | ||
previous === C_TILDE && | ||
character === tilde && | ||
previous === tilde && | ||
(!preceding || !whitespace(preceding)) | ||
@@ -47,15 +47,15 @@ ) { | ||
if (silent) { | ||
return true; | ||
return true | ||
} | ||
return eat(DOUBLE + subvalue + DOUBLE)({ | ||
return eat(fence + subvalue + fence)({ | ||
type: 'delete', | ||
children: self.tokenizeInline(subvalue, now) | ||
}); | ||
}) | ||
} | ||
subvalue += previous; | ||
preceding = previous; | ||
previous = character; | ||
subvalue += previous | ||
preceding = previous | ||
previous = character | ||
} | ||
} |
@@ -1,57 +0,58 @@ | ||
'use strict'; | ||
'use strict' | ||
var trim = require('trim'); | ||
var word = require('is-word-character'); | ||
var whitespace = require('is-whitespace-character'); | ||
var locate = require('../locate/emphasis'); | ||
var trim = require('trim') | ||
var word = require('is-word-character') | ||
var whitespace = require('is-whitespace-character') | ||
var locate = require('../locate/emphasis') | ||
module.exports = emphasis; | ||
emphasis.locator = locate; | ||
module.exports = emphasis | ||
emphasis.locator = locate | ||
var C_ASTERISK = '*'; | ||
var C_UNDERSCORE = '_'; | ||
var asterisk = '*' | ||
var underscore = '_' | ||
var backslash = '\\' | ||
function emphasis(eat, value, silent) { | ||
var self = this; | ||
var index = 0; | ||
var character = value.charAt(index); | ||
var now; | ||
var pedantic; | ||
var marker; | ||
var queue; | ||
var subvalue; | ||
var length; | ||
var prev; | ||
var self = this | ||
var index = 0 | ||
var character = value.charAt(index) | ||
var now | ||
var pedantic | ||
var marker | ||
var queue | ||
var subvalue | ||
var length | ||
var prev | ||
if (character !== C_ASTERISK && character !== C_UNDERSCORE) { | ||
return; | ||
if (character !== asterisk && character !== underscore) { | ||
return | ||
} | ||
pedantic = self.options.pedantic; | ||
subvalue = character; | ||
marker = character; | ||
length = value.length; | ||
index++; | ||
queue = ''; | ||
character = ''; | ||
pedantic = self.options.pedantic | ||
subvalue = character | ||
marker = character | ||
length = value.length | ||
index++ | ||
queue = '' | ||
character = '' | ||
if (pedantic && whitespace(value.charAt(index))) { | ||
return; | ||
return | ||
} | ||
while (index < length) { | ||
prev = character; | ||
character = value.charAt(index); | ||
prev = character | ||
character = value.charAt(index) | ||
if (character === marker && (!pedantic || !whitespace(prev))) { | ||
character = value.charAt(++index); | ||
character = value.charAt(++index) | ||
if (character !== marker) { | ||
if (!trim(queue) || prev === marker) { | ||
return; | ||
return | ||
} | ||
if (!pedantic && marker === C_UNDERSCORE && word(character)) { | ||
queue += marker; | ||
continue; | ||
if (!pedantic && marker === underscore && word(character)) { | ||
queue += marker | ||
continue | ||
} | ||
@@ -61,8 +62,8 @@ | ||
if (silent) { | ||
return true; | ||
return true | ||
} | ||
now = eat.now(); | ||
now.column++; | ||
now.offset++; | ||
now = eat.now() | ||
now.column++ | ||
now.offset++ | ||
@@ -72,16 +73,16 @@ return eat(subvalue + queue + marker)({ | ||
children: self.tokenizeInline(queue, now) | ||
}); | ||
}) | ||
} | ||
queue += marker; | ||
queue += marker | ||
} | ||
if (!pedantic && character === '\\') { | ||
queue += character; | ||
character = value.charAt(++index); | ||
if (!pedantic && character === backslash) { | ||
queue += character | ||
character = value.charAt(++index) | ||
} | ||
queue += character; | ||
index++; | ||
queue += character | ||
index++ | ||
} | ||
} |
@@ -1,15 +0,18 @@ | ||
'use strict'; | ||
'use strict' | ||
var locate = require('../locate/escape'); | ||
var locate = require('../locate/escape') | ||
module.exports = escape; | ||
escape.locator = locate; | ||
module.exports = escape | ||
escape.locator = locate | ||
var lineFeed = '\n' | ||
var backslash = '\\' | ||
function escape(eat, value, silent) { | ||
var self = this; | ||
var character; | ||
var node; | ||
var self = this | ||
var character | ||
var node | ||
if (value.charAt(0) === '\\') { | ||
character = value.charAt(1); | ||
if (value.charAt(0) === backslash) { | ||
character = value.charAt(1) | ||
@@ -19,17 +22,14 @@ if (self.escape.indexOf(character) !== -1) { | ||
if (silent) { | ||
return true; | ||
return true | ||
} | ||
if (character === '\n') { | ||
node = {type: 'break'}; | ||
if (character === lineFeed) { | ||
node = {type: 'break'} | ||
} else { | ||
node = { | ||
type: 'text', | ||
value: character | ||
}; | ||
node = {type: 'text', value: character} | ||
} | ||
return eat('\\' + character)(node); | ||
return eat(backslash + character)(node) | ||
} | ||
} | ||
} |
@@ -1,82 +0,82 @@ | ||
'use strict'; | ||
'use strict' | ||
var whitespace = require('is-whitespace-character'); | ||
var normalize = require('../util/normalize'); | ||
var whitespace = require('is-whitespace-character') | ||
var normalize = require('../util/normalize') | ||
module.exports = footnoteDefinition; | ||
footnoteDefinition.notInList = true; | ||
footnoteDefinition.notInBlock = true; | ||
module.exports = footnoteDefinition | ||
footnoteDefinition.notInList = true | ||
footnoteDefinition.notInBlock = true | ||
var C_BACKSLASH = '\\'; | ||
var C_NEWLINE = '\n'; | ||
var C_TAB = '\t'; | ||
var C_SPACE = ' '; | ||
var C_BRACKET_OPEN = '['; | ||
var C_BRACKET_CLOSE = ']'; | ||
var C_CARET = '^'; | ||
var C_COLON = ':'; | ||
var backslash = '\\' | ||
var lineFeed = '\n' | ||
var tab = '\t' | ||
var space = ' ' | ||
var leftSquareBracket = '[' | ||
var rightSquareBracket = ']' | ||
var caret = '^' | ||
var colon = ':' | ||
var EXPRESSION_INITIAL_TAB = /^( {4}|\t)?/gm; | ||
var EXPRESSION_INITIAL_TAB = /^( {4}|\t)?/gm | ||
function footnoteDefinition(eat, value, silent) { | ||
var self = this; | ||
var offsets = self.offset; | ||
var index; | ||
var length; | ||
var subvalue; | ||
var now; | ||
var currentLine; | ||
var content; | ||
var queue; | ||
var subqueue; | ||
var character; | ||
var identifier; | ||
var add; | ||
var exit; | ||
var self = this | ||
var offsets = self.offset | ||
var index | ||
var length | ||
var subvalue | ||
var now | ||
var currentLine | ||
var content | ||
var queue | ||
var subqueue | ||
var character | ||
var identifier | ||
var add | ||
var exit | ||
if (!self.options.footnotes) { | ||
return; | ||
return | ||
} | ||
index = 0; | ||
length = value.length; | ||
subvalue = ''; | ||
now = eat.now(); | ||
currentLine = now.line; | ||
index = 0 | ||
length = value.length | ||
subvalue = '' | ||
now = eat.now() | ||
currentLine = now.line | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (!whitespace(character)) { | ||
break; | ||
break | ||
} | ||
subvalue += character; | ||
index++; | ||
subvalue += character | ||
index++ | ||
} | ||
if ( | ||
value.charAt(index) !== C_BRACKET_OPEN || | ||
value.charAt(index + 1) !== C_CARET | ||
value.charAt(index) !== leftSquareBracket || | ||
value.charAt(index + 1) !== caret | ||
) { | ||
return; | ||
return | ||
} | ||
subvalue += C_BRACKET_OPEN + C_CARET; | ||
index = subvalue.length; | ||
queue = ''; | ||
subvalue += leftSquareBracket + caret | ||
index = subvalue.length | ||
queue = '' | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character === C_BRACKET_CLOSE) { | ||
break; | ||
} else if (character === C_BACKSLASH) { | ||
queue += character; | ||
index++; | ||
character = value.charAt(index); | ||
if (character === rightSquareBracket) { | ||
break | ||
} else if (character === backslash) { | ||
queue += character | ||
index++ | ||
character = value.charAt(index) | ||
} | ||
queue += character; | ||
index++; | ||
queue += character | ||
index++ | ||
} | ||
@@ -86,101 +86,102 @@ | ||
!queue || | ||
value.charAt(index) !== C_BRACKET_CLOSE || | ||
value.charAt(index + 1) !== C_COLON | ||
value.charAt(index) !== rightSquareBracket || | ||
value.charAt(index + 1) !== colon | ||
) { | ||
return; | ||
return | ||
} | ||
if (silent) { | ||
return true; | ||
return true | ||
} | ||
identifier = normalize(queue); | ||
subvalue += queue + C_BRACKET_CLOSE + C_COLON; | ||
index = subvalue.length; | ||
identifier = queue | ||
subvalue += queue + rightSquareBracket + colon | ||
index = subvalue.length | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character !== C_TAB && character !== C_SPACE) { | ||
break; | ||
if (character !== tab && character !== space) { | ||
break | ||
} | ||
subvalue += character; | ||
index++; | ||
subvalue += character | ||
index++ | ||
} | ||
now.column += subvalue.length; | ||
now.offset += subvalue.length; | ||
queue = ''; | ||
content = ''; | ||
subqueue = ''; | ||
now.column += subvalue.length | ||
now.offset += subvalue.length | ||
queue = '' | ||
content = '' | ||
subqueue = '' | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character === C_NEWLINE) { | ||
subqueue = character; | ||
index++; | ||
if (character === lineFeed) { | ||
subqueue = character | ||
index++ | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character !== C_NEWLINE) { | ||
break; | ||
if (character !== lineFeed) { | ||
break | ||
} | ||
subqueue += character; | ||
index++; | ||
subqueue += character | ||
index++ | ||
} | ||
queue += subqueue; | ||
subqueue = ''; | ||
queue += subqueue | ||
subqueue = '' | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character !== C_SPACE) { | ||
break; | ||
if (character !== space) { | ||
break | ||
} | ||
subqueue += character; | ||
index++; | ||
subqueue += character | ||
index++ | ||
} | ||
if (subqueue.length === 0) { | ||
break; | ||
break | ||
} | ||
queue += subqueue; | ||
queue += subqueue | ||
} | ||
if (queue) { | ||
content += queue; | ||
queue = ''; | ||
content += queue | ||
queue = '' | ||
} | ||
content += character; | ||
index++; | ||
content += character | ||
index++ | ||
} | ||
subvalue += content; | ||
subvalue += content | ||
content = content.replace(EXPRESSION_INITIAL_TAB, function (line) { | ||
offsets[currentLine] = (offsets[currentLine] || 0) + line.length; | ||
currentLine++; | ||
content = content.replace(EXPRESSION_INITIAL_TAB, function(line) { | ||
offsets[currentLine] = (offsets[currentLine] || 0) + line.length | ||
currentLine++ | ||
return ''; | ||
}); | ||
return '' | ||
}) | ||
add = eat(subvalue); | ||
add = eat(subvalue) | ||
exit = self.enterBlock(); | ||
content = self.tokenizeBlock(content, now); | ||
exit(); | ||
exit = self.enterBlock() | ||
content = self.tokenizeBlock(content, now) | ||
exit() | ||
return add({ | ||
type: 'footnoteDefinition', | ||
identifier: identifier, | ||
identifier: normalize(identifier), | ||
label: identifier, | ||
children: content | ||
}); | ||
}) | ||
} |
@@ -1,135 +0,123 @@ | ||
'use strict'; | ||
'use strict' | ||
module.exports = atxHeading; | ||
module.exports = atxHeading | ||
var C_NEWLINE = '\n'; | ||
var C_TAB = '\t'; | ||
var C_SPACE = ' '; | ||
var C_HASH = '#'; | ||
var lineFeed = '\n' | ||
var tab = '\t' | ||
var space = ' ' | ||
var numberSign = '#' | ||
var MAX_ATX_COUNT = 6; | ||
var maxFenceCount = 6 | ||
function atxHeading(eat, value, silent) { | ||
var self = this; | ||
var settings = self.options; | ||
var length = value.length + 1; | ||
var index = -1; | ||
var now = eat.now(); | ||
var subvalue = ''; | ||
var content = ''; | ||
var character; | ||
var queue; | ||
var depth; | ||
var self = this | ||
var pedantic = self.options.pedantic | ||
var length = value.length + 1 | ||
var index = -1 | ||
var now = eat.now() | ||
var subvalue = '' | ||
var content = '' | ||
var character | ||
var queue | ||
var depth | ||
/* Eat initial spacing. */ | ||
// Eat initial spacing. | ||
while (++index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character !== C_SPACE && character !== C_TAB) { | ||
index--; | ||
break; | ||
if (character !== space && character !== tab) { | ||
index-- | ||
break | ||
} | ||
subvalue += character; | ||
subvalue += character | ||
} | ||
/* Eat hashes. */ | ||
depth = 0; | ||
// Eat hashes. | ||
depth = 0 | ||
while (++index <= length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character !== C_HASH) { | ||
index--; | ||
break; | ||
if (character !== numberSign) { | ||
index-- | ||
break | ||
} | ||
subvalue += character; | ||
depth++; | ||
subvalue += character | ||
depth++ | ||
} | ||
if (depth > MAX_ATX_COUNT) { | ||
return; | ||
if (depth > maxFenceCount) { | ||
return | ||
} | ||
if ( | ||
!depth || | ||
(!settings.pedantic && value.charAt(index + 1) === C_HASH) | ||
) { | ||
return; | ||
if (!depth || (!pedantic && value.charAt(index + 1) === numberSign)) { | ||
return | ||
} | ||
length = value.length + 1; | ||
length = value.length + 1 | ||
/* Eat intermediate white-space. */ | ||
queue = ''; | ||
// Eat intermediate white-space. | ||
queue = '' | ||
while (++index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character !== C_SPACE && character !== C_TAB) { | ||
index--; | ||
break; | ||
if (character !== space && character !== tab) { | ||
index-- | ||
break | ||
} | ||
queue += character; | ||
queue += character | ||
} | ||
/* Exit when not in pedantic mode without spacing. */ | ||
if ( | ||
!settings.pedantic && | ||
queue.length === 0 && | ||
character && | ||
character !== C_NEWLINE | ||
) { | ||
return; | ||
// Exit when not in pedantic mode without spacing. | ||
if (!pedantic && queue.length === 0 && character && character !== lineFeed) { | ||
return | ||
} | ||
if (silent) { | ||
return true; | ||
return true | ||
} | ||
/* Eat content. */ | ||
subvalue += queue; | ||
queue = ''; | ||
content = ''; | ||
// Eat content. | ||
subvalue += queue | ||
queue = '' | ||
content = '' | ||
while (++index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (!character || character === C_NEWLINE) { | ||
break; | ||
if (!character || character === lineFeed) { | ||
break | ||
} | ||
if ( | ||
character !== C_SPACE && | ||
character !== C_TAB && | ||
character !== C_HASH | ||
) { | ||
content += queue + character; | ||
queue = ''; | ||
continue; | ||
if (character !== space && character !== tab && character !== numberSign) { | ||
content += queue + character | ||
queue = '' | ||
continue | ||
} | ||
while (character === C_SPACE || character === C_TAB) { | ||
queue += character; | ||
character = value.charAt(++index); | ||
while (character === space || character === tab) { | ||
queue += character | ||
character = value.charAt(++index) | ||
} | ||
while (character === C_HASH) { | ||
queue += character; | ||
character = value.charAt(++index); | ||
while (character === numberSign) { | ||
queue += character | ||
character = value.charAt(++index) | ||
} | ||
while (character === C_SPACE || character === C_TAB) { | ||
queue += character; | ||
character = value.charAt(++index); | ||
while (character === space || character === tab) { | ||
queue += character | ||
character = value.charAt(++index) | ||
} | ||
index--; | ||
index-- | ||
} | ||
now.column += subvalue.length; | ||
now.offset += subvalue.length; | ||
subvalue += content + queue; | ||
now.column += subvalue.length | ||
now.offset += subvalue.length | ||
subvalue += content + queue | ||
@@ -140,3 +128,3 @@ return eat(subvalue)({ | ||
children: self.tokenizeInline(content, now) | ||
}); | ||
}) | ||
} |
@@ -1,100 +0,95 @@ | ||
'use strict'; | ||
'use strict' | ||
module.exports = setextHeading; | ||
module.exports = setextHeading | ||
var C_NEWLINE = '\n'; | ||
var C_TAB = '\t'; | ||
var C_SPACE = ' '; | ||
var C_EQUALS = '='; | ||
var C_DASH = '-'; | ||
var lineFeed = '\n' | ||
var tab = '\t' | ||
var space = ' ' | ||
var equalsTo = '=' | ||
var dash = '-' | ||
var MAX_HEADING_INDENT = 3; | ||
var maxIndent = 3 | ||
/* Map of characters which can be used to mark setext | ||
* headers, mapping to their corresponding depth. */ | ||
var SETEXT_MARKERS = {}; | ||
var equalsToDepth = 1 | ||
var dashDepth = 2 | ||
SETEXT_MARKERS[C_EQUALS] = 1; | ||
SETEXT_MARKERS[C_DASH] = 2; | ||
function setextHeading(eat, value, silent) { | ||
var self = this; | ||
var now = eat.now(); | ||
var length = value.length; | ||
var index = -1; | ||
var subvalue = ''; | ||
var content; | ||
var queue; | ||
var character; | ||
var marker; | ||
var depth; | ||
var self = this | ||
var now = eat.now() | ||
var length = value.length | ||
var index = -1 | ||
var subvalue = '' | ||
var content | ||
var queue | ||
var character | ||
var marker | ||
var depth | ||
/* Eat initial indentation. */ | ||
// Eat initial indentation. | ||
while (++index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character !== C_SPACE || index >= MAX_HEADING_INDENT) { | ||
index--; | ||
break; | ||
if (character !== space || index >= maxIndent) { | ||
index-- | ||
break | ||
} | ||
subvalue += character; | ||
subvalue += character | ||
} | ||
/* Eat content. */ | ||
content = ''; | ||
queue = ''; | ||
// Eat content. | ||
content = '' | ||
queue = '' | ||
while (++index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character === C_NEWLINE) { | ||
index--; | ||
break; | ||
if (character === lineFeed) { | ||
index-- | ||
break | ||
} | ||
if (character === C_SPACE || character === C_TAB) { | ||
queue += character; | ||
if (character === space || character === tab) { | ||
queue += character | ||
} else { | ||
content += queue + character; | ||
queue = ''; | ||
content += queue + character | ||
queue = '' | ||
} | ||
} | ||
now.column += subvalue.length; | ||
now.offset += subvalue.length; | ||
subvalue += content + queue; | ||
now.column += subvalue.length | ||
now.offset += subvalue.length | ||
subvalue += content + queue | ||
/* Ensure the content is followed by a newline and a | ||
* valid marker. */ | ||
character = value.charAt(++index); | ||
marker = value.charAt(++index); | ||
// Ensure the content is followed by a newline and a valid marker. | ||
character = value.charAt(++index) | ||
marker = value.charAt(++index) | ||
if (character !== C_NEWLINE || !SETEXT_MARKERS[marker]) { | ||
return; | ||
if (character !== lineFeed || (marker !== equalsTo && marker !== dash)) { | ||
return | ||
} | ||
subvalue += character; | ||
subvalue += character | ||
/* Eat Setext-line. */ | ||
queue = marker; | ||
depth = SETEXT_MARKERS[marker]; | ||
// Eat Setext-line. | ||
queue = marker | ||
depth = marker === equalsTo ? equalsToDepth : dashDepth | ||
while (++index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character !== marker) { | ||
if (character !== C_NEWLINE) { | ||
return; | ||
if (character !== lineFeed) { | ||
return | ||
} | ||
index--; | ||
break; | ||
index-- | ||
break | ||
} | ||
queue += character; | ||
queue += character | ||
} | ||
if (silent) { | ||
return true; | ||
return true | ||
} | ||
@@ -106,3 +101,3 @@ | ||
children: self.tokenizeInline(content, now) | ||
}); | ||
}) | ||
} |
@@ -1,60 +0,77 @@ | ||
'use strict'; | ||
'use strict' | ||
var openCloseTag = require('../util/html').openCloseTag; | ||
var openCloseTag = require('../util/html').openCloseTag | ||
module.exports = blockHTML; | ||
module.exports = blockHtml | ||
var C_TAB = '\t'; | ||
var C_SPACE = ' '; | ||
var C_NEWLINE = '\n'; | ||
var C_LT = '<'; | ||
var tab = '\t' | ||
var space = ' ' | ||
var lineFeed = '\n' | ||
var lessThan = '<' | ||
function blockHTML(eat, value, silent) { | ||
var self = this; | ||
var blocks = self.options.blocks; | ||
var length = value.length; | ||
var index = 0; | ||
var next; | ||
var line; | ||
var offset; | ||
var character; | ||
var count; | ||
var sequence; | ||
var subvalue; | ||
var rawOpenExpression = /^<(script|pre|style)(?=(\s|>|$))/i | ||
var rawCloseExpression = /<\/(script|pre|style)>/i | ||
var commentOpenExpression = /^<!--/ | ||
var commentCloseExpression = /-->/ | ||
var instructionOpenExpression = /^<\?/ | ||
var instructionCloseExpression = /\?>/ | ||
var directiveOpenExpression = /^<![A-Za-z]/ | ||
var directiveCloseExpression = />/ | ||
var cdataOpenExpression = /^<!\[CDATA\[/ | ||
var cdataCloseExpression = /\]\]>/ | ||
var elementCloseExpression = /^$/ | ||
var otherElementOpenExpression = new RegExp(openCloseTag.source + '\\s*$') | ||
function blockHtml(eat, value, silent) { | ||
var self = this | ||
var blocks = self.options.blocks.join('|') | ||
var elementOpenExpression = new RegExp( | ||
'^</?(' + blocks + ')(?=(\\s|/?>|$))', | ||
'i' | ||
) | ||
var length = value.length | ||
var index = 0 | ||
var next | ||
var line | ||
var offset | ||
var character | ||
var count | ||
var sequence | ||
var subvalue | ||
var sequences = [ | ||
[/^<(script|pre|style)(?=(\s|>|$))/i, /<\/(script|pre|style)>/i, true], | ||
[/^<!--/, /-->/, true], | ||
[/^<\?/, /\?>/, true], | ||
[/^<![A-Za-z]/, />/, true], | ||
[/^<!\[CDATA\[/, /\]\]>/, true], | ||
[new RegExp('^</?(' + blocks.join('|') + ')(?=(\\s|/?>|$))', 'i'), /^$/, true], | ||
[new RegExp(openCloseTag.source + '\\s*$'), /^$/, false] | ||
]; | ||
[rawOpenExpression, rawCloseExpression, true], | ||
[commentOpenExpression, commentCloseExpression, true], | ||
[instructionOpenExpression, instructionCloseExpression, true], | ||
[directiveOpenExpression, directiveCloseExpression, true], | ||
[cdataOpenExpression, cdataCloseExpression, true], | ||
[elementOpenExpression, elementCloseExpression, true], | ||
[otherElementOpenExpression, elementCloseExpression, false] | ||
] | ||
/* Eat initial spacing. */ | ||
// Eat initial spacing. | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character !== C_TAB && character !== C_SPACE) { | ||
break; | ||
if (character !== tab && character !== space) { | ||
break | ||
} | ||
index++; | ||
index++ | ||
} | ||
if (value.charAt(index) !== C_LT) { | ||
return; | ||
if (value.charAt(index) !== lessThan) { | ||
return | ||
} | ||
next = value.indexOf(C_NEWLINE, index + 1); | ||
next = next === -1 ? length : next; | ||
line = value.slice(index, next); | ||
offset = -1; | ||
count = sequences.length; | ||
next = value.indexOf(lineFeed, index + 1) | ||
next = next === -1 ? length : next | ||
line = value.slice(index, next) | ||
offset = -1 | ||
count = sequences.length | ||
while (++offset < count) { | ||
if (sequences[offset][0].test(line)) { | ||
sequence = sequences[offset]; | ||
break; | ||
sequence = sequences[offset] | ||
break | ||
} | ||
@@ -64,32 +81,32 @@ } | ||
if (!sequence) { | ||
return; | ||
return | ||
} | ||
if (silent) { | ||
return sequence[2]; | ||
return sequence[2] | ||
} | ||
index = next; | ||
index = next | ||
if (!sequence[1].test(line)) { | ||
while (index < length) { | ||
next = value.indexOf(C_NEWLINE, index + 1); | ||
next = next === -1 ? length : next; | ||
line = value.slice(index + 1, next); | ||
next = value.indexOf(lineFeed, index + 1) | ||
next = next === -1 ? length : next | ||
line = value.slice(index + 1, next) | ||
if (sequence[1].test(line)) { | ||
if (line) { | ||
index = next; | ||
index = next | ||
} | ||
break; | ||
break | ||
} | ||
index = next; | ||
index = next | ||
} | ||
} | ||
subvalue = value.slice(0, index); | ||
subvalue = value.slice(0, index) | ||
return eat(subvalue)({type: 'html', value: subvalue}); | ||
return eat(subvalue)({type: 'html', value: subvalue}) | ||
} |
@@ -1,38 +0,43 @@ | ||
'use strict'; | ||
'use strict' | ||
var alphabetical = require('is-alphabetical'); | ||
var locate = require('../locate/tag'); | ||
var tag = require('../util/html').tag; | ||
var alphabetical = require('is-alphabetical') | ||
var locate = require('../locate/tag') | ||
var tag = require('../util/html').tag | ||
module.exports = inlineHTML; | ||
inlineHTML.locator = locate; | ||
module.exports = inlineHTML | ||
inlineHTML.locator = locate | ||
var EXPRESSION_HTML_LINK_OPEN = /^<a /i; | ||
var EXPRESSION_HTML_LINK_CLOSE = /^<\/a>/i; | ||
var lessThan = '<' | ||
var questionMark = '?' | ||
var exclamationMark = '!' | ||
var slash = '/' | ||
var htmlLinkOpenExpression = /^<a /i | ||
var htmlLinkCloseExpression = /^<\/a>/i | ||
function inlineHTML(eat, value, silent) { | ||
var self = this; | ||
var length = value.length; | ||
var character; | ||
var subvalue; | ||
var self = this | ||
var length = value.length | ||
var character | ||
var subvalue | ||
if (value.charAt(0) !== '<' || length < 3) { | ||
return; | ||
if (value.charAt(0) !== lessThan || length < 3) { | ||
return | ||
} | ||
character = value.charAt(1); | ||
character = value.charAt(1) | ||
if ( | ||
!alphabetical(character) && | ||
character !== '?' && | ||
character !== '!' && | ||
character !== '/' | ||
character !== questionMark && | ||
character !== exclamationMark && | ||
character !== slash | ||
) { | ||
return; | ||
return | ||
} | ||
subvalue = value.match(tag); | ||
subvalue = value.match(tag) | ||
if (!subvalue) { | ||
return; | ||
return | ||
} | ||
@@ -42,14 +47,14 @@ | ||
if (silent) { | ||
return true; | ||
return true | ||
} | ||
subvalue = subvalue[0]; | ||
subvalue = subvalue[0] | ||
if (!self.inLink && EXPRESSION_HTML_LINK_OPEN.test(subvalue)) { | ||
self.inLink = true; | ||
} else if (self.inLink && EXPRESSION_HTML_LINK_CLOSE.test(subvalue)) { | ||
self.inLink = false; | ||
if (!self.inLink && htmlLinkOpenExpression.test(subvalue)) { | ||
self.inLink = true | ||
} else if (self.inLink && htmlLinkCloseExpression.test(subvalue)) { | ||
self.inLink = false | ||
} | ||
return eat(subvalue)({type: 'html', value: subvalue}); | ||
return eat(subvalue)({type: 'html', value: subvalue}) | ||
} |
@@ -1,222 +0,206 @@ | ||
'use strict'; | ||
'use strict' | ||
var whitespace = require('is-whitespace-character'); | ||
var locate = require('../locate/link'); | ||
var whitespace = require('is-whitespace-character') | ||
var locate = require('../locate/link') | ||
module.exports = link; | ||
link.locator = locate; | ||
module.exports = link | ||
link.locator = locate | ||
var own = {}.hasOwnProperty; | ||
var lineFeed = '\n' | ||
var exclamationMark = '!' | ||
var quotationMark = '"' | ||
var apostrophe = "'" | ||
var leftParenthesis = '(' | ||
var rightParenthesis = ')' | ||
var lessThan = '<' | ||
var greaterThan = '>' | ||
var leftSquareBracket = '[' | ||
var backslash = '\\' | ||
var rightSquareBracket = ']' | ||
var graveAccent = '`' | ||
var C_BACKSLASH = '\\'; | ||
var C_BRACKET_OPEN = '['; | ||
var C_BRACKET_CLOSE = ']'; | ||
var C_PAREN_OPEN = '('; | ||
var C_PAREN_CLOSE = ')'; | ||
var C_LT = '<'; | ||
var C_GT = '>'; | ||
var C_TICK = '`'; | ||
var C_DOUBLE_QUOTE = '"'; | ||
var C_SINGLE_QUOTE = '\''; | ||
/* Map of characters, which can be used to mark link | ||
* and image titles. */ | ||
var LINK_MARKERS = {}; | ||
LINK_MARKERS[C_DOUBLE_QUOTE] = C_DOUBLE_QUOTE; | ||
LINK_MARKERS[C_SINGLE_QUOTE] = C_SINGLE_QUOTE; | ||
/* Map of characters, which can be used to mark link | ||
* and image titles in commonmark-mode. */ | ||
var COMMONMARK_LINK_MARKERS = {}; | ||
COMMONMARK_LINK_MARKERS[C_DOUBLE_QUOTE] = C_DOUBLE_QUOTE; | ||
COMMONMARK_LINK_MARKERS[C_SINGLE_QUOTE] = C_SINGLE_QUOTE; | ||
COMMONMARK_LINK_MARKERS[C_PAREN_OPEN] = C_PAREN_CLOSE; | ||
function link(eat, value, silent) { | ||
var self = this; | ||
var subvalue = ''; | ||
var index = 0; | ||
var character = value.charAt(0); | ||
var pedantic = self.options.pedantic; | ||
var commonmark = self.options.commonmark; | ||
var gfm = self.options.gfm; | ||
var closed; | ||
var count; | ||
var opening; | ||
var beforeURL; | ||
var beforeTitle; | ||
var subqueue; | ||
var hasMarker; | ||
var markers; | ||
var isImage; | ||
var content; | ||
var marker; | ||
var length; | ||
var title; | ||
var depth; | ||
var queue; | ||
var url; | ||
var now; | ||
var exit; | ||
var node; | ||
var self = this | ||
var subvalue = '' | ||
var index = 0 | ||
var character = value.charAt(0) | ||
var pedantic = self.options.pedantic | ||
var commonmark = self.options.commonmark | ||
var gfm = self.options.gfm | ||
var closed | ||
var count | ||
var opening | ||
var beforeURL | ||
var beforeTitle | ||
var subqueue | ||
var hasMarker | ||
var isImage | ||
var content | ||
var marker | ||
var length | ||
var title | ||
var depth | ||
var queue | ||
var url | ||
var now | ||
var exit | ||
var node | ||
/* Detect whether this is an image. */ | ||
if (character === '!') { | ||
isImage = true; | ||
subvalue = character; | ||
character = value.charAt(++index); | ||
// Detect whether this is an image. | ||
if (character === exclamationMark) { | ||
isImage = true | ||
subvalue = character | ||
character = value.charAt(++index) | ||
} | ||
/* Eat the opening. */ | ||
if (character !== C_BRACKET_OPEN) { | ||
return; | ||
// Eat the opening. | ||
if (character !== leftSquareBracket) { | ||
return | ||
} | ||
/* Exit when this is a link and we’re already inside | ||
* a link. */ | ||
// Exit when this is a link and we’re already inside a link. | ||
if (!isImage && self.inLink) { | ||
return; | ||
return | ||
} | ||
subvalue += character; | ||
queue = ''; | ||
index++; | ||
subvalue += character | ||
queue = '' | ||
index++ | ||
/* Eat the content. */ | ||
length = value.length; | ||
now = eat.now(); | ||
depth = 0; | ||
// Eat the content. | ||
length = value.length | ||
now = eat.now() | ||
depth = 0 | ||
now.column += index; | ||
now.offset += index; | ||
now.column += index | ||
now.offset += index | ||
while (index < length) { | ||
character = value.charAt(index); | ||
subqueue = character; | ||
character = value.charAt(index) | ||
subqueue = character | ||
if (character === C_TICK) { | ||
/* Inline-code in link content. */ | ||
count = 1; | ||
if (character === graveAccent) { | ||
// Inline-code in link content. | ||
count = 1 | ||
while (value.charAt(index + 1) === C_TICK) { | ||
subqueue += character; | ||
index++; | ||
count++; | ||
while (value.charAt(index + 1) === graveAccent) { | ||
subqueue += character | ||
index++ | ||
count++ | ||
} | ||
if (!opening) { | ||
opening = count; | ||
opening = count | ||
} else if (count >= opening) { | ||
opening = 0; | ||
opening = 0 | ||
} | ||
} else if (character === C_BACKSLASH) { | ||
/* Allow brackets to be escaped. */ | ||
index++; | ||
subqueue += value.charAt(index); | ||
/* In GFM mode, brackets in code still count. | ||
* In all other modes, they don’t. This empty | ||
* block prevents the next statements are | ||
* entered. */ | ||
} else if ((!opening || gfm) && character === C_BRACKET_OPEN) { | ||
depth++; | ||
} else if ((!opening || gfm) && character === C_BRACKET_CLOSE) { | ||
} else if (character === backslash) { | ||
// Allow brackets to be escaped. | ||
index++ | ||
subqueue += value.charAt(index) | ||
} else if ((!opening || gfm) && character === leftSquareBracket) { | ||
// In GFM mode, brackets in code still count. In all other modes, | ||
// they don’t. | ||
depth++ | ||
} else if ((!opening || gfm) && character === rightSquareBracket) { | ||
if (depth) { | ||
depth--; | ||
depth-- | ||
} else { | ||
/* Allow white-space between content and | ||
* url in GFM mode. */ | ||
// Allow white-space between content and url in GFM mode. | ||
if (!pedantic) { | ||
while (index < length) { | ||
character = value.charAt(index + 1); | ||
character = value.charAt(index + 1) | ||
if (!whitespace(character)) { | ||
break; | ||
break | ||
} | ||
subqueue += character; | ||
index++; | ||
subqueue += character | ||
index++ | ||
} | ||
} | ||
if (value.charAt(index + 1) !== C_PAREN_OPEN) { | ||
return; | ||
if (value.charAt(index + 1) !== leftParenthesis) { | ||
return | ||
} | ||
subqueue += C_PAREN_OPEN; | ||
closed = true; | ||
index++; | ||
subqueue += leftParenthesis | ||
closed = true | ||
index++ | ||
break; | ||
break | ||
} | ||
} | ||
queue += subqueue; | ||
subqueue = ''; | ||
index++; | ||
queue += subqueue | ||
subqueue = '' | ||
index++ | ||
} | ||
/* Eat the content closing. */ | ||
// Eat the content closing. | ||
if (!closed) { | ||
return; | ||
return | ||
} | ||
content = queue; | ||
subvalue += queue + subqueue; | ||
index++; | ||
content = queue | ||
subvalue += queue + subqueue | ||
index++ | ||
/* Eat white-space. */ | ||
// Eat white-space. | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (!whitespace(character)) { | ||
break; | ||
break | ||
} | ||
subvalue += character; | ||
index++; | ||
subvalue += character | ||
index++ | ||
} | ||
/* Eat the URL. */ | ||
character = value.charAt(index); | ||
markers = commonmark ? COMMONMARK_LINK_MARKERS : LINK_MARKERS; | ||
queue = ''; | ||
beforeURL = subvalue; | ||
// Eat the URL. | ||
character = value.charAt(index) | ||
queue = '' | ||
beforeURL = subvalue | ||
if (character === C_LT) { | ||
index++; | ||
beforeURL += C_LT; | ||
if (character === lessThan) { | ||
index++ | ||
beforeURL += lessThan | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character === C_GT) { | ||
break; | ||
if (character === greaterThan) { | ||
break | ||
} | ||
if (commonmark && character === '\n') { | ||
return; | ||
if (commonmark && character === lineFeed) { | ||
return | ||
} | ||
queue += character; | ||
index++; | ||
queue += character | ||
index++ | ||
} | ||
if (value.charAt(index) !== C_GT) { | ||
return; | ||
if (value.charAt(index) !== greaterThan) { | ||
return | ||
} | ||
subvalue += C_LT + queue + C_GT; | ||
url = queue; | ||
index++; | ||
subvalue += lessThan + queue + greaterThan | ||
url = queue | ||
index++ | ||
} else { | ||
character = null; | ||
subqueue = ''; | ||
character = null | ||
subqueue = '' | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (subqueue && own.call(markers, character)) { | ||
break; | ||
if ( | ||
subqueue && | ||
(character === quotationMark || | ||
character === apostrophe || | ||
(commonmark && character === leftParenthesis)) | ||
) { | ||
break | ||
} | ||
@@ -226,131 +210,134 @@ | ||
if (!pedantic) { | ||
break; | ||
break | ||
} | ||
subqueue += character; | ||
subqueue += character | ||
} else { | ||
if (character === C_PAREN_OPEN) { | ||
depth++; | ||
} else if (character === C_PAREN_CLOSE) { | ||
if (character === leftParenthesis) { | ||
depth++ | ||
} else if (character === rightParenthesis) { | ||
if (depth === 0) { | ||
break; | ||
break | ||
} | ||
depth--; | ||
depth-- | ||
} | ||
queue += subqueue; | ||
subqueue = ''; | ||
queue += subqueue | ||
subqueue = '' | ||
if (character === C_BACKSLASH) { | ||
queue += C_BACKSLASH; | ||
character = value.charAt(++index); | ||
if (character === backslash) { | ||
queue += backslash | ||
character = value.charAt(++index) | ||
} | ||
queue += character; | ||
queue += character | ||
} | ||
index++; | ||
index++ | ||
} | ||
subvalue += queue; | ||
url = queue; | ||
index = subvalue.length; | ||
subvalue += queue | ||
url = queue | ||
index = subvalue.length | ||
} | ||
/* Eat white-space. */ | ||
queue = ''; | ||
// Eat white-space. | ||
queue = '' | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (!whitespace(character)) { | ||
break; | ||
break | ||
} | ||
queue += character; | ||
index++; | ||
queue += character | ||
index++ | ||
} | ||
character = value.charAt(index); | ||
subvalue += queue; | ||
character = value.charAt(index) | ||
subvalue += queue | ||
/* Eat the title. */ | ||
if (queue && own.call(markers, character)) { | ||
index++; | ||
subvalue += character; | ||
queue = ''; | ||
marker = markers[character]; | ||
beforeTitle = subvalue; | ||
// Eat the title. | ||
if ( | ||
queue && | ||
(character === quotationMark || | ||
character === apostrophe || | ||
(commonmark && character === leftParenthesis)) | ||
) { | ||
index++ | ||
subvalue += character | ||
queue = '' | ||
marker = character === leftParenthesis ? rightParenthesis : character | ||
beforeTitle = subvalue | ||
/* In commonmark-mode, things are pretty easy: the | ||
* marker cannot occur inside the title. | ||
* | ||
* Non-commonmark does, however, support nested | ||
* delimiters. */ | ||
// In commonmark-mode, things are pretty easy: the marker cannot occur | ||
// inside the title. Non-commonmark does, however, support nested | ||
// delimiters. | ||
if (commonmark) { | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character === marker) { | ||
break; | ||
break | ||
} | ||
if (character === C_BACKSLASH) { | ||
queue += C_BACKSLASH; | ||
character = value.charAt(++index); | ||
if (character === backslash) { | ||
queue += backslash | ||
character = value.charAt(++index) | ||
} | ||
index++; | ||
queue += character; | ||
index++ | ||
queue += character | ||
} | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character !== marker) { | ||
return; | ||
return | ||
} | ||
title = queue; | ||
subvalue += queue + character; | ||
index++; | ||
title = queue | ||
subvalue += queue + character | ||
index++ | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (!whitespace(character)) { | ||
break; | ||
break | ||
} | ||
subvalue += character; | ||
index++; | ||
subvalue += character | ||
index++ | ||
} | ||
} else { | ||
subqueue = ''; | ||
subqueue = '' | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character === marker) { | ||
if (hasMarker) { | ||
queue += marker + subqueue; | ||
subqueue = ''; | ||
queue += marker + subqueue | ||
subqueue = '' | ||
} | ||
hasMarker = true; | ||
hasMarker = true | ||
} else if (!hasMarker) { | ||
queue += character; | ||
} else if (character === C_PAREN_CLOSE) { | ||
subvalue += queue + marker + subqueue; | ||
title = queue; | ||
break; | ||
queue += character | ||
} else if (character === rightParenthesis) { | ||
subvalue += queue + marker + subqueue | ||
title = queue | ||
break | ||
} else if (whitespace(character)) { | ||
subqueue += character; | ||
subqueue += character | ||
} else { | ||
queue += marker + subqueue + character; | ||
subqueue = ''; | ||
hasMarker = false; | ||
queue += marker + subqueue + character | ||
subqueue = '' | ||
hasMarker = false | ||
} | ||
index++; | ||
index++ | ||
} | ||
@@ -360,4 +347,4 @@ } | ||
if (value.charAt(index) !== C_PAREN_CLOSE) { | ||
return; | ||
if (value.charAt(index) !== rightParenthesis) { | ||
return | ||
} | ||
@@ -367,12 +354,14 @@ | ||
if (silent) { | ||
return true; | ||
return true | ||
} | ||
subvalue += C_PAREN_CLOSE; | ||
subvalue += rightParenthesis | ||
url = self.decode.raw(self.unescape(url), eat(beforeURL).test().end, {nonTerminated: false}); | ||
url = self.decode.raw(self.unescape(url), eat(beforeURL).test().end, { | ||
nonTerminated: false | ||
}) | ||
if (title) { | ||
beforeTitle = eat(beforeTitle).test().end; | ||
title = self.decode.raw(self.unescape(title), beforeTitle); | ||
beforeTitle = eat(beforeTitle).test().end | ||
title = self.decode.raw(self.unescape(title), beforeTitle) | ||
} | ||
@@ -384,13 +373,13 @@ | ||
url: url | ||
}; | ||
} | ||
if (isImage) { | ||
node.alt = self.decode.raw(self.unescape(content), now) || null; | ||
node.alt = self.decode.raw(self.unescape(content), now) || null | ||
} else { | ||
exit = self.enterLink(); | ||
node.children = self.tokenizeInline(content, now); | ||
exit(); | ||
exit = self.enterLink() | ||
node.children = self.tokenizeInline(content, now) | ||
exit() | ||
} | ||
return eat(subvalue)(node); | ||
return eat(subvalue)(node) | ||
} |
@@ -1,218 +0,206 @@ | ||
'use strict'; | ||
'use strict' | ||
/* eslint-disable max-params */ | ||
var trim = require('trim'); | ||
var repeat = require('repeat-string'); | ||
var decimal = require('is-decimal'); | ||
var getIndent = require('../util/get-indentation'); | ||
var removeIndent = require('../util/remove-indentation'); | ||
var interrupt = require('../util/interrupt'); | ||
var trim = require('trim') | ||
var repeat = require('repeat-string') | ||
var decimal = require('is-decimal') | ||
var getIndent = require('../util/get-indentation') | ||
var removeIndent = require('../util/remove-indentation') | ||
var interrupt = require('../util/interrupt') | ||
module.exports = list; | ||
module.exports = list | ||
var C_ASTERISK = '*'; | ||
var C_UNDERSCORE = '_'; | ||
var C_PLUS = '+'; | ||
var C_DASH = '-'; | ||
var C_DOT = '.'; | ||
var C_SPACE = ' '; | ||
var C_NEWLINE = '\n'; | ||
var C_TAB = '\t'; | ||
var C_PAREN_CLOSE = ')'; | ||
var C_X_LOWER = 'x'; | ||
var asterisk = '*' | ||
var underscore = '_' | ||
var plusSign = '+' | ||
var dash = '-' | ||
var dot = '.' | ||
var space = ' ' | ||
var lineFeed = '\n' | ||
var tab = '\t' | ||
var rightParenthesis = ')' | ||
var lowercaseX = 'x' | ||
var TAB_SIZE = 4; | ||
var EXPRESSION_LOOSE_LIST_ITEM = /\n\n(?!\s*$)/; | ||
var EXPRESSION_TASK_ITEM = /^\[([ \t]|x|X)][ \t]/; | ||
var EXPRESSION_BULLET = /^([ \t]*)([*+-]|\d+[.)])( {1,4}(?! )| |\t|$|(?=\n))([^\n]*)/; | ||
var EXPRESSION_PEDANTIC_BULLET = /^([ \t]*)([*+-]|\d+[.)])([ \t]+)/; | ||
var EXPRESSION_INITIAL_INDENT = /^( {1,4}|\t)?/gm; | ||
var tabSize = 4 | ||
var looseListItemExpression = /\n\n(?!\s*$)/ | ||
var taskItemExpression = /^\[([ \t]|x|X)][ \t]/ | ||
var bulletExpression = /^([ \t]*)([*+-]|\d+[.)])( {1,4}(?! )| |\t|$|(?=\n))([^\n]*)/ | ||
var pedanticBulletExpression = /^([ \t]*)([*+-]|\d+[.)])([ \t]+)/ | ||
var initialIndentExpression = /^( {1,4}|\t)?/gm | ||
/* Map of characters which can be used to mark | ||
* list-items. */ | ||
var LIST_UNORDERED_MARKERS = {}; | ||
LIST_UNORDERED_MARKERS[C_ASTERISK] = true; | ||
LIST_UNORDERED_MARKERS[C_PLUS] = true; | ||
LIST_UNORDERED_MARKERS[C_DASH] = true; | ||
/* Map of characters which can be used to mark | ||
* list-items after a digit. */ | ||
var LIST_ORDERED_MARKERS = {}; | ||
LIST_ORDERED_MARKERS[C_DOT] = true; | ||
/* Map of characters which can be used to mark | ||
* list-items after a digit. */ | ||
var LIST_ORDERED_COMMONMARK_MARKERS = {}; | ||
LIST_ORDERED_COMMONMARK_MARKERS[C_DOT] = true; | ||
LIST_ORDERED_COMMONMARK_MARKERS[C_PAREN_CLOSE] = true; | ||
function list(eat, value, silent) { | ||
var self = this; | ||
var commonmark = self.options.commonmark; | ||
var pedantic = self.options.pedantic; | ||
var tokenizers = self.blockTokenizers; | ||
var interuptors = self.interruptList; | ||
var markers; | ||
var index = 0; | ||
var length = value.length; | ||
var start = null; | ||
var size = 0; | ||
var queue; | ||
var ordered; | ||
var character; | ||
var marker; | ||
var nextIndex; | ||
var startIndex; | ||
var prefixed; | ||
var currentMarker; | ||
var content; | ||
var line; | ||
var prevEmpty; | ||
var empty; | ||
var items; | ||
var allLines; | ||
var emptyLines; | ||
var item; | ||
var enterTop; | ||
var exitBlockquote; | ||
var isLoose; | ||
var node; | ||
var now; | ||
var end; | ||
var indented; | ||
var self = this | ||
var commonmark = self.options.commonmark | ||
var pedantic = self.options.pedantic | ||
var tokenizers = self.blockTokenizers | ||
var interuptors = self.interruptList | ||
var index = 0 | ||
var length = value.length | ||
var start = null | ||
var size = 0 | ||
var queue | ||
var ordered | ||
var character | ||
var marker | ||
var nextIndex | ||
var startIndex | ||
var prefixed | ||
var currentMarker | ||
var content | ||
var line | ||
var prevEmpty | ||
var empty | ||
var items | ||
var allLines | ||
var emptyLines | ||
var item | ||
var enterTop | ||
var exitBlockquote | ||
var spread = false | ||
var node | ||
var now | ||
var end | ||
var indented | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character === C_TAB) { | ||
size += TAB_SIZE - (size % TAB_SIZE); | ||
} else if (character === C_SPACE) { | ||
size++; | ||
if (character === tab) { | ||
size += tabSize - (size % tabSize) | ||
} else if (character === space) { | ||
size++ | ||
} else { | ||
break; | ||
break | ||
} | ||
index++; | ||
index++ | ||
} | ||
if (size >= TAB_SIZE) { | ||
return; | ||
if (size >= tabSize) { | ||
return | ||
} | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
markers = commonmark ? | ||
LIST_ORDERED_COMMONMARK_MARKERS : | ||
LIST_ORDERED_MARKERS; | ||
if (LIST_UNORDERED_MARKERS[character] === true) { | ||
marker = character; | ||
ordered = false; | ||
if (character === asterisk || character === plusSign || character === dash) { | ||
marker = character | ||
ordered = false | ||
} else { | ||
ordered = true; | ||
queue = ''; | ||
ordered = true | ||
queue = '' | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (!decimal(character)) { | ||
break; | ||
break | ||
} | ||
queue += character; | ||
index++; | ||
queue += character | ||
index++ | ||
} | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (!queue || markers[character] !== true) { | ||
return; | ||
if ( | ||
!queue || | ||
!(character === dot || (commonmark && character === rightParenthesis)) | ||
) { | ||
return | ||
} | ||
start = parseInt(queue, 10); | ||
marker = character; | ||
start = parseInt(queue, 10) | ||
marker = character | ||
} | ||
character = value.charAt(++index); | ||
character = value.charAt(++index) | ||
if (character !== C_SPACE && character !== C_TAB) { | ||
return; | ||
if ( | ||
character !== space && | ||
character !== tab && | ||
(pedantic || (character !== lineFeed && character !== '')) | ||
) { | ||
return | ||
} | ||
if (silent) { | ||
return true; | ||
return true | ||
} | ||
index = 0; | ||
items = []; | ||
allLines = []; | ||
emptyLines = []; | ||
index = 0 | ||
items = [] | ||
allLines = [] | ||
emptyLines = [] | ||
while (index < length) { | ||
nextIndex = value.indexOf(C_NEWLINE, index); | ||
startIndex = index; | ||
prefixed = false; | ||
indented = false; | ||
nextIndex = value.indexOf(lineFeed, index) | ||
startIndex = index | ||
prefixed = false | ||
indented = false | ||
if (nextIndex === -1) { | ||
nextIndex = length; | ||
nextIndex = length | ||
} | ||
end = index + TAB_SIZE; | ||
size = 0; | ||
end = index + tabSize | ||
size = 0 | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character === C_TAB) { | ||
size += TAB_SIZE - (size % TAB_SIZE); | ||
} else if (character === C_SPACE) { | ||
size++; | ||
if (character === tab) { | ||
size += tabSize - (size % tabSize) | ||
} else if (character === space) { | ||
size++ | ||
} else { | ||
break; | ||
break | ||
} | ||
index++; | ||
index++ | ||
} | ||
if (size >= TAB_SIZE) { | ||
indented = true; | ||
if (size >= tabSize) { | ||
indented = true | ||
} | ||
if (item && size >= item.indent) { | ||
indented = true; | ||
indented = true | ||
} | ||
character = value.charAt(index); | ||
currentMarker = null; | ||
character = value.charAt(index) | ||
currentMarker = null | ||
if (!indented) { | ||
if (LIST_UNORDERED_MARKERS[character] === true) { | ||
currentMarker = character; | ||
index++; | ||
size++; | ||
if ( | ||
character === asterisk || | ||
character === plusSign || | ||
character === dash | ||
) { | ||
currentMarker = character | ||
index++ | ||
size++ | ||
} else { | ||
queue = ''; | ||
queue = '' | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (!decimal(character)) { | ||
break; | ||
break | ||
} | ||
queue += character; | ||
index++; | ||
queue += character | ||
index++ | ||
} | ||
character = value.charAt(index); | ||
index++; | ||
character = value.charAt(index) | ||
index++ | ||
if (queue && markers[character] === true) { | ||
currentMarker = character; | ||
size += queue.length + 1; | ||
if ( | ||
queue && | ||
(character === dot || (commonmark && character === rightParenthesis)) | ||
) { | ||
currentMarker = character | ||
size += queue.length + 1 | ||
} | ||
@@ -222,25 +210,25 @@ } | ||
if (currentMarker) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character === C_TAB) { | ||
size += TAB_SIZE - (size % TAB_SIZE); | ||
index++; | ||
} else if (character === C_SPACE) { | ||
end = index + TAB_SIZE; | ||
if (character === tab) { | ||
size += tabSize - (size % tabSize) | ||
index++ | ||
} else if (character === space) { | ||
end = index + tabSize | ||
while (index < end) { | ||
if (value.charAt(index) !== C_SPACE) { | ||
break; | ||
if (value.charAt(index) !== space) { | ||
break | ||
} | ||
index++; | ||
size++; | ||
index++ | ||
size++ | ||
} | ||
if (index === end && value.charAt(index) === C_SPACE) { | ||
index -= TAB_SIZE - 1; | ||
size -= TAB_SIZE - 1; | ||
if (index === end && value.charAt(index) === space) { | ||
index -= tabSize - 1 | ||
size -= tabSize - 1 | ||
} | ||
} else if (character !== C_NEWLINE && character !== '') { | ||
currentMarker = null; | ||
} else if (character !== lineFeed && character !== '') { | ||
currentMarker = null | ||
} | ||
@@ -252,41 +240,42 @@ } | ||
if (!pedantic && marker !== currentMarker) { | ||
break; | ||
break | ||
} | ||
prefixed = true; | ||
prefixed = true | ||
} else { | ||
if (!commonmark && !indented && value.charAt(startIndex) === C_SPACE) { | ||
indented = true; | ||
if (!commonmark && !indented && value.charAt(startIndex) === space) { | ||
indented = true | ||
} else if (commonmark && item) { | ||
indented = size >= item.indent || size > TAB_SIZE; | ||
indented = size >= item.indent || size > tabSize | ||
} | ||
prefixed = false; | ||
index = startIndex; | ||
prefixed = false | ||
index = startIndex | ||
} | ||
line = value.slice(startIndex, nextIndex); | ||
content = startIndex === index ? line : value.slice(index, nextIndex); | ||
line = value.slice(startIndex, nextIndex) | ||
content = startIndex === index ? line : value.slice(index, nextIndex) | ||
if ( | ||
currentMarker === C_ASTERISK || | ||
currentMarker === C_UNDERSCORE || | ||
currentMarker === C_DASH | ||
currentMarker === asterisk || | ||
currentMarker === underscore || | ||
currentMarker === dash | ||
) { | ||
if (tokenizers.thematicBreak.call(self, eat, line, true)) { | ||
break; | ||
break | ||
} | ||
} | ||
prevEmpty = empty; | ||
empty = !trim(content).length; | ||
prevEmpty = empty | ||
empty = !prefixed && !trim(content).length | ||
if (indented && item) { | ||
item.value = item.value.concat(emptyLines, line); | ||
allLines = allLines.concat(emptyLines, line); | ||
emptyLines = []; | ||
item.value = item.value.concat(emptyLines, line) | ||
allLines = allLines.concat(emptyLines, line) | ||
emptyLines = [] | ||
} else if (prefixed) { | ||
if (emptyLines.length !== 0) { | ||
item.value.push(''); | ||
item.trail = emptyLines.concat(); | ||
spread = true | ||
item.value.push('') | ||
item.trail = emptyLines.concat() | ||
} | ||
@@ -298,88 +287,81 @@ | ||
trail: [] | ||
}; | ||
} | ||
items.push(item); | ||
allLines = allLines.concat(emptyLines, line); | ||
emptyLines = []; | ||
items.push(item) | ||
allLines = allLines.concat(emptyLines, line) | ||
emptyLines = [] | ||
} else if (empty) { | ||
if (prevEmpty) { | ||
break; | ||
if (prevEmpty && !commonmark) { | ||
break | ||
} | ||
emptyLines.push(line); | ||
emptyLines.push(line) | ||
} else { | ||
if (prevEmpty) { | ||
break; | ||
break | ||
} | ||
if (interrupt(interuptors, tokenizers, self, [eat, line, true])) { | ||
break; | ||
break | ||
} | ||
item.value = item.value.concat(emptyLines, line); | ||
allLines = allLines.concat(emptyLines, line); | ||
emptyLines = []; | ||
item.value = item.value.concat(emptyLines, line) | ||
allLines = allLines.concat(emptyLines, line) | ||
emptyLines = [] | ||
} | ||
index = nextIndex + 1; | ||
index = nextIndex + 1 | ||
} | ||
node = eat(allLines.join(C_NEWLINE)).reset({ | ||
node = eat(allLines.join(lineFeed)).reset({ | ||
type: 'list', | ||
ordered: ordered, | ||
start: start, | ||
loose: null, | ||
spread: spread, | ||
children: [] | ||
}); | ||
}) | ||
enterTop = self.enterList(); | ||
exitBlockquote = self.enterBlock(); | ||
isLoose = false; | ||
index = -1; | ||
length = items.length; | ||
enterTop = self.enterList() | ||
exitBlockquote = self.enterBlock() | ||
index = -1 | ||
length = items.length | ||
while (++index < length) { | ||
item = items[index].value.join(C_NEWLINE); | ||
now = eat.now(); | ||
item = items[index].value.join(lineFeed) | ||
now = eat.now() | ||
item = eat(item)(listItem(self, item, now), node); | ||
eat(item)(listItem(self, item, now), node) | ||
if (item.loose) { | ||
isLoose = true; | ||
} | ||
item = items[index].trail.join(lineFeed) | ||
item = items[index].trail.join(C_NEWLINE); | ||
if (index !== length - 1) { | ||
item += C_NEWLINE; | ||
item += lineFeed | ||
} | ||
eat(item); | ||
eat(item) | ||
} | ||
enterTop(); | ||
exitBlockquote(); | ||
enterTop() | ||
exitBlockquote() | ||
node.loose = isLoose; | ||
return node; | ||
return node | ||
} | ||
function listItem(ctx, value, position) { | ||
var offsets = ctx.offset; | ||
var fn = ctx.options.pedantic ? pedanticListItem : normalListItem; | ||
var checked = null; | ||
var task; | ||
var indent; | ||
var offsets = ctx.offset | ||
var fn = ctx.options.pedantic ? pedanticListItem : normalListItem | ||
var checked = null | ||
var task | ||
var indent | ||
value = fn.apply(null, arguments); | ||
value = fn.apply(null, arguments) | ||
if (ctx.options.gfm) { | ||
task = value.match(EXPRESSION_TASK_ITEM); | ||
task = value.match(taskItemExpression) | ||
if (task) { | ||
indent = task[0].length; | ||
checked = task[1].toLowerCase() === C_X_LOWER; | ||
offsets[position.line] += indent; | ||
value = value.slice(indent); | ||
indent = task[0].length | ||
checked = task[1].toLowerCase() === lowercaseX | ||
offsets[position.line] += indent | ||
value = value.slice(indent) | ||
} | ||
@@ -390,89 +372,85 @@ } | ||
type: 'listItem', | ||
loose: EXPRESSION_LOOSE_LIST_ITEM.test(value) || | ||
value.charAt(value.length - 1) === C_NEWLINE, | ||
spread: looseListItemExpression.test(value), | ||
checked: checked, | ||
children: ctx.tokenizeBlock(value, position) | ||
}; | ||
} | ||
} | ||
/* Create a list-item using overly simple mechanics. */ | ||
// Create a list-item using overly simple mechanics. | ||
function pedanticListItem(ctx, value, position) { | ||
var offsets = ctx.offset; | ||
var line = position.line; | ||
var offsets = ctx.offset | ||
var line = position.line | ||
/* Remove the list-item’s bullet. */ | ||
value = value.replace(EXPRESSION_PEDANTIC_BULLET, replacer); | ||
// Remove the list-item’s bullet. | ||
value = value.replace(pedanticBulletExpression, replacer) | ||
/* The initial line was also matched by the below, so | ||
* we reset the `line`. */ | ||
line = position.line; | ||
// The initial line was also matched by the below, so we reset the `line`. | ||
line = position.line | ||
return value.replace(EXPRESSION_INITIAL_INDENT, replacer); | ||
return value.replace(initialIndentExpression, replacer) | ||
/* A simple replacer which removed all matches, | ||
* and adds their length to `offset`. */ | ||
// A simple replacer which removed all matches, and adds their length to | ||
// `offset`. | ||
function replacer($0) { | ||
offsets[line] = (offsets[line] || 0) + $0.length; | ||
line++; | ||
offsets[line] = (offsets[line] || 0) + $0.length | ||
line++ | ||
return ''; | ||
return '' | ||
} | ||
} | ||
/* Create a list-item using sane mechanics. */ | ||
// Create a list-item using sane mechanics. | ||
function normalListItem(ctx, value, position) { | ||
var offsets = ctx.offset; | ||
var line = position.line; | ||
var max; | ||
var bullet; | ||
var rest; | ||
var lines; | ||
var trimmedLines; | ||
var index; | ||
var length; | ||
var offsets = ctx.offset | ||
var line = position.line | ||
var max | ||
var bullet | ||
var rest | ||
var lines | ||
var trimmedLines | ||
var index | ||
var length | ||
/* Remove the list-item’s bullet. */ | ||
value = value.replace(EXPRESSION_BULLET, replacer); | ||
// Remove the list-item’s bullet. | ||
value = value.replace(bulletExpression, replacer) | ||
lines = value.split(C_NEWLINE); | ||
lines = value.split(lineFeed) | ||
trimmedLines = removeIndent(value, getIndent(max).indent).split(C_NEWLINE); | ||
trimmedLines = removeIndent(value, getIndent(max).indent).split(lineFeed) | ||
/* We replaced the initial bullet with something | ||
* else above, which was used to trick | ||
* `removeIndentation` into removing some more | ||
* characters when possible. However, that could | ||
* result in the initial line to be stripped more | ||
* than it should be. */ | ||
trimmedLines[0] = rest; | ||
// We replaced the initial bullet with something else above, which was used | ||
// to trick `removeIndentation` into removing some more characters when | ||
// possible. However, that could result in the initial line to be stripped | ||
// more than it should be. | ||
trimmedLines[0] = rest | ||
offsets[line] = (offsets[line] || 0) + bullet.length; | ||
line++; | ||
offsets[line] = (offsets[line] || 0) + bullet.length | ||
line++ | ||
index = 0; | ||
length = lines.length; | ||
index = 0 | ||
length = lines.length | ||
while (++index < length) { | ||
offsets[line] = (offsets[line] || 0) + | ||
lines[index].length - trimmedLines[index].length; | ||
line++; | ||
offsets[line] = | ||
(offsets[line] || 0) + lines[index].length - trimmedLines[index].length | ||
line++ | ||
} | ||
return trimmedLines.join(C_NEWLINE); | ||
return trimmedLines.join(lineFeed) | ||
function replacer($0, $1, $2, $3, $4) { | ||
bullet = $1 + $2 + $3; | ||
rest = $4; | ||
bullet = $1 + $2 + $3 | ||
rest = $4 | ||
/* Make sure that the first nine numbered list items | ||
* can indent with an extra space. That is, when | ||
* the bullet did not receive an extra final space. */ | ||
// Make sure that the first nine numbered list items can indent with an | ||
// extra space. That is, when the bullet did not receive an extra final | ||
// space. | ||
if (Number($2) < 10 && bullet.length % 2 === 1) { | ||
$2 = C_SPACE + $2; | ||
$2 = space + $2 | ||
} | ||
max = $1 + repeat(C_SPACE, $2.length) + $3; | ||
max = $1 + repeat(space, $2.length) + $3 | ||
return max + rest; | ||
return max + rest | ||
} | ||
} |
@@ -1,17 +0,18 @@ | ||
'use strict'; | ||
'use strict' | ||
var whitespace = require('is-whitespace-character'); | ||
var whitespace = require('is-whitespace-character') | ||
module.exports = newline; | ||
module.exports = newline | ||
/* Tokenise newline. */ | ||
var lineFeed = '\n' | ||
function newline(eat, value, silent) { | ||
var character = value.charAt(0); | ||
var length; | ||
var subvalue; | ||
var queue; | ||
var index; | ||
var character = value.charAt(0) | ||
var length | ||
var subvalue | ||
var queue | ||
var index | ||
if (character !== '\n') { | ||
return; | ||
if (character !== lineFeed) { | ||
return | ||
} | ||
@@ -21,28 +22,28 @@ | ||
if (silent) { | ||
return true; | ||
return true | ||
} | ||
index = 1; | ||
length = value.length; | ||
subvalue = character; | ||
queue = ''; | ||
index = 1 | ||
length = value.length | ||
subvalue = character | ||
queue = '' | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (!whitespace(character)) { | ||
break; | ||
break | ||
} | ||
queue += character; | ||
queue += character | ||
if (character === '\n') { | ||
subvalue += queue; | ||
queue = ''; | ||
if (character === lineFeed) { | ||
subvalue += queue | ||
queue = '' | ||
} | ||
index++; | ||
index++ | ||
} | ||
eat(subvalue); | ||
eat(subvalue) | ||
} |
@@ -1,108 +0,103 @@ | ||
'use strict'; | ||
'use strict' | ||
var trim = require('trim'); | ||
var decimal = require('is-decimal'); | ||
var trimTrailingLines = require('trim-trailing-lines'); | ||
var interrupt = require('../util/interrupt'); | ||
var trim = require('trim') | ||
var decimal = require('is-decimal') | ||
var trimTrailingLines = require('trim-trailing-lines') | ||
var interrupt = require('../util/interrupt') | ||
module.exports = paragraph; | ||
module.exports = paragraph | ||
var C_NEWLINE = '\n'; | ||
var C_TAB = '\t'; | ||
var C_SPACE = ' '; | ||
var tab = '\t' | ||
var lineFeed = '\n' | ||
var space = ' ' | ||
var TAB_SIZE = 4; | ||
var tabSize = 4 | ||
/* Tokenise paragraph. */ | ||
// Tokenise paragraph. | ||
function paragraph(eat, value, silent) { | ||
var self = this; | ||
var settings = self.options; | ||
var commonmark = settings.commonmark; | ||
var gfm = settings.gfm; | ||
var tokenizers = self.blockTokenizers; | ||
var interruptors = self.interruptParagraph; | ||
var index = value.indexOf(C_NEWLINE); | ||
var length = value.length; | ||
var position; | ||
var subvalue; | ||
var character; | ||
var size; | ||
var now; | ||
var self = this | ||
var settings = self.options | ||
var commonmark = settings.commonmark | ||
var gfm = settings.gfm | ||
var tokenizers = self.blockTokenizers | ||
var interruptors = self.interruptParagraph | ||
var index = value.indexOf(lineFeed) | ||
var length = value.length | ||
var position | ||
var subvalue | ||
var character | ||
var size | ||
var now | ||
while (index < length) { | ||
/* Eat everything if there’s no following newline. */ | ||
// Eat everything if there’s no following newline. | ||
if (index === -1) { | ||
index = length; | ||
break; | ||
index = length | ||
break | ||
} | ||
/* Stop if the next character is NEWLINE. */ | ||
if (value.charAt(index + 1) === C_NEWLINE) { | ||
break; | ||
// Stop if the next character is NEWLINE. | ||
if (value.charAt(index + 1) === lineFeed) { | ||
break | ||
} | ||
/* In commonmark-mode, following indented lines | ||
* are part of the paragraph. */ | ||
// In commonmark-mode, following indented lines are part of the paragraph. | ||
if (commonmark) { | ||
size = 0; | ||
position = index + 1; | ||
size = 0 | ||
position = index + 1 | ||
while (position < length) { | ||
character = value.charAt(position); | ||
character = value.charAt(position) | ||
if (character === C_TAB) { | ||
size = TAB_SIZE; | ||
break; | ||
} else if (character === C_SPACE) { | ||
size++; | ||
if (character === tab) { | ||
size = tabSize | ||
break | ||
} else if (character === space) { | ||
size++ | ||
} else { | ||
break; | ||
break | ||
} | ||
position++; | ||
position++ | ||
} | ||
if (size >= TAB_SIZE) { | ||
index = value.indexOf(C_NEWLINE, index + 1); | ||
continue; | ||
if (size >= tabSize && character !== lineFeed) { | ||
index = value.indexOf(lineFeed, index + 1) | ||
continue | ||
} | ||
} | ||
subvalue = value.slice(index + 1); | ||
subvalue = value.slice(index + 1) | ||
/* Check if the following code contains a possible | ||
* block. */ | ||
// Check if the following code contains a possible block. | ||
if (interrupt(interruptors, tokenizers, self, [eat, subvalue, true])) { | ||
break; | ||
break | ||
} | ||
/* Break if the following line starts a list, when | ||
* already in a list, or when in commonmark, or when | ||
* in gfm mode and the bullet is *not* numeric. */ | ||
// Break if the following line starts a list, when already in a list, or | ||
// when in commonmark, or when in gfm mode and the bullet is *not* numeric. | ||
if ( | ||
tokenizers.list.call(self, eat, subvalue, true) && | ||
( | ||
self.inList || | ||
(self.inList || | ||
commonmark || | ||
(gfm && !decimal(trim.left(subvalue).charAt(0))) | ||
) | ||
(gfm && !decimal(trim.left(subvalue).charAt(0)))) | ||
) { | ||
break; | ||
break | ||
} | ||
position = index; | ||
index = value.indexOf(C_NEWLINE, index + 1); | ||
position = index | ||
index = value.indexOf(lineFeed, index + 1) | ||
if (index !== -1 && trim(value.slice(position, index)) === '') { | ||
index = position; | ||
break; | ||
index = position | ||
break | ||
} | ||
} | ||
subvalue = value.slice(0, index); | ||
subvalue = value.slice(0, index) | ||
if (trim(subvalue) === '') { | ||
eat(subvalue); | ||
eat(subvalue) | ||
return null; | ||
return null | ||
} | ||
@@ -112,7 +107,7 @@ | ||
if (silent) { | ||
return true; | ||
return true | ||
} | ||
now = eat.now(); | ||
subvalue = trimTrailingLines(subvalue); | ||
now = eat.now() | ||
subvalue = trimTrailingLines(subvalue) | ||
@@ -122,3 +117,3 @@ return eat(subvalue)({ | ||
children: self.tokenizeInline(subvalue, now) | ||
}); | ||
}) | ||
} |
@@ -1,169 +0,177 @@ | ||
'use strict'; | ||
'use strict' | ||
var whitespace = require('is-whitespace-character'); | ||
var locate = require('../locate/link'); | ||
var normalize = require('../util/normalize'); | ||
var whitespace = require('is-whitespace-character') | ||
var locate = require('../locate/link') | ||
var normalize = require('../util/normalize') | ||
module.exports = reference; | ||
reference.locator = locate; | ||
module.exports = reference | ||
reference.locator = locate | ||
var T_LINK = 'link'; | ||
var T_IMAGE = 'image'; | ||
var T_FOOTNOTE = 'footnote'; | ||
var REFERENCE_TYPE_SHORTCUT = 'shortcut'; | ||
var REFERENCE_TYPE_COLLAPSED = 'collapsed'; | ||
var REFERENCE_TYPE_FULL = 'full'; | ||
var C_CARET = '^'; | ||
var C_BACKSLASH = '\\'; | ||
var C_BRACKET_OPEN = '['; | ||
var C_BRACKET_CLOSE = ']'; | ||
var link = 'link' | ||
var image = 'image' | ||
var footnote = 'footnote' | ||
var shortcut = 'shortcut' | ||
var collapsed = 'collapsed' | ||
var full = 'full' | ||
var space = ' ' | ||
var exclamationMark = '!' | ||
var leftSquareBracket = '[' | ||
var backslash = '\\' | ||
var rightSquareBracket = ']' | ||
var caret = '^' | ||
function reference(eat, value, silent) { | ||
var self = this; | ||
var character = value.charAt(0); | ||
var index = 0; | ||
var length = value.length; | ||
var subvalue = ''; | ||
var intro = ''; | ||
var type = T_LINK; | ||
var referenceType = REFERENCE_TYPE_SHORTCUT; | ||
var content; | ||
var identifier; | ||
var now; | ||
var node; | ||
var exit; | ||
var queue; | ||
var bracketed; | ||
var depth; | ||
var self = this | ||
var commonmark = self.options.commonmark | ||
var character = value.charAt(0) | ||
var index = 0 | ||
var length = value.length | ||
var subvalue = '' | ||
var intro = '' | ||
var type = link | ||
var referenceType = shortcut | ||
var content | ||
var identifier | ||
var now | ||
var node | ||
var exit | ||
var queue | ||
var bracketed | ||
var depth | ||
/* Check whether we’re eating an image. */ | ||
if (character === '!') { | ||
type = T_IMAGE; | ||
intro = character; | ||
character = value.charAt(++index); | ||
// Check whether we’re eating an image. | ||
if (character === exclamationMark) { | ||
type = image | ||
intro = character | ||
character = value.charAt(++index) | ||
} | ||
if (character !== C_BRACKET_OPEN) { | ||
return; | ||
if (character !== leftSquareBracket) { | ||
return | ||
} | ||
index++; | ||
intro += character; | ||
queue = ''; | ||
index++ | ||
intro += character | ||
queue = '' | ||
/* Check whether we’re eating a footnote. */ | ||
if (self.options.footnotes && value.charAt(index) === C_CARET) { | ||
/* Exit if `![^` is found, so the `!` will be seen as text after this, | ||
* and we’ll enter this function again when `[^` is found. */ | ||
if (type === T_IMAGE) { | ||
return; | ||
// Check whether we’re eating a footnote. | ||
if (self.options.footnotes && value.charAt(index) === caret) { | ||
// Exit if `![^` is found, so the `!` will be seen as text after this, | ||
// and we’ll enter this function again when `[^` is found. | ||
if (type === image) { | ||
return | ||
} | ||
intro += C_CARET; | ||
index++; | ||
type = T_FOOTNOTE; | ||
intro += caret | ||
index++ | ||
type = footnote | ||
} | ||
/* Eat the text. */ | ||
depth = 0; | ||
// Eat the text. | ||
depth = 0 | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character === C_BRACKET_OPEN) { | ||
bracketed = true; | ||
depth++; | ||
} else if (character === C_BRACKET_CLOSE) { | ||
if (character === leftSquareBracket) { | ||
bracketed = true | ||
depth++ | ||
} else if (character === rightSquareBracket) { | ||
if (!depth) { | ||
break; | ||
break | ||
} | ||
depth--; | ||
depth-- | ||
} | ||
if (character === C_BACKSLASH) { | ||
queue += C_BACKSLASH; | ||
character = value.charAt(++index); | ||
if (character === backslash) { | ||
queue += backslash | ||
character = value.charAt(++index) | ||
} | ||
queue += character; | ||
index++; | ||
queue += character | ||
index++ | ||
} | ||
subvalue = queue; | ||
content = queue; | ||
character = value.charAt(index); | ||
subvalue = queue | ||
content = queue | ||
character = value.charAt(index) | ||
if (character !== C_BRACKET_CLOSE) { | ||
return; | ||
if (character !== rightSquareBracket) { | ||
return | ||
} | ||
index++; | ||
subvalue += character; | ||
queue = ''; | ||
index++ | ||
subvalue += character | ||
queue = '' | ||
while (index < length) { | ||
character = value.charAt(index); | ||
if (!commonmark) { | ||
// The original markdown syntax definition explicitly allows for whitespace | ||
// between the link text and link label; commonmark departs from this, in | ||
// part to improve support for shortcut reference links | ||
while (index < length) { | ||
character = value.charAt(index) | ||
if (!whitespace(character)) { | ||
break; | ||
if (!whitespace(character)) { | ||
break | ||
} | ||
queue += character | ||
index++ | ||
} | ||
queue += character; | ||
index++; | ||
} | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
/* Inline footnotes cannot have an identifier. */ | ||
if (type !== T_FOOTNOTE && character === C_BRACKET_OPEN) { | ||
identifier = ''; | ||
queue += character; | ||
index++; | ||
// Inline footnotes cannot have an identifier. | ||
if (type !== footnote && character === leftSquareBracket) { | ||
identifier = '' | ||
queue += character | ||
index++ | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character === C_BRACKET_OPEN || character === C_BRACKET_CLOSE) { | ||
break; | ||
if (character === leftSquareBracket || character === rightSquareBracket) { | ||
break | ||
} | ||
if (character === C_BACKSLASH) { | ||
identifier += C_BACKSLASH; | ||
character = value.charAt(++index); | ||
if (character === backslash) { | ||
identifier += backslash | ||
character = value.charAt(++index) | ||
} | ||
identifier += character; | ||
index++; | ||
identifier += character | ||
index++ | ||
} | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character === C_BRACKET_CLOSE) { | ||
referenceType = identifier ? REFERENCE_TYPE_FULL : REFERENCE_TYPE_COLLAPSED; | ||
queue += identifier + character; | ||
index++; | ||
if (character === rightSquareBracket) { | ||
referenceType = identifier ? full : collapsed | ||
queue += identifier + character | ||
index++ | ||
} else { | ||
identifier = ''; | ||
identifier = '' | ||
} | ||
subvalue += queue; | ||
queue = ''; | ||
subvalue += queue | ||
queue = '' | ||
} else { | ||
if (!content) { | ||
return; | ||
return | ||
} | ||
identifier = content; | ||
identifier = content | ||
} | ||
/* Brackets cannot be inside the identifier. */ | ||
if (referenceType !== REFERENCE_TYPE_FULL && bracketed) { | ||
return; | ||
// Brackets cannot be inside the identifier. | ||
if (referenceType !== full && bracketed) { | ||
return | ||
} | ||
subvalue = intro + subvalue; | ||
subvalue = intro + subvalue | ||
if (type === T_LINK && self.inLink) { | ||
return null; | ||
if (type === link && self.inLink) { | ||
return null | ||
} | ||
@@ -173,35 +181,36 @@ | ||
if (silent) { | ||
return true; | ||
return true | ||
} | ||
if (type === T_FOOTNOTE && content.indexOf(' ') !== -1) { | ||
if (type === footnote && content.indexOf(space) !== -1) { | ||
return eat(subvalue)({ | ||
type: 'footnote', | ||
type: footnote, | ||
children: this.tokenizeInline(content, eat.now()) | ||
}); | ||
}) | ||
} | ||
now = eat.now(); | ||
now.column += intro.length; | ||
now.offset += intro.length; | ||
identifier = referenceType === REFERENCE_TYPE_FULL ? identifier : content; | ||
now = eat.now() | ||
now.column += intro.length | ||
now.offset += intro.length | ||
identifier = referenceType === full ? identifier : content | ||
node = { | ||
type: type + 'Reference', | ||
identifier: normalize(identifier) | ||
}; | ||
identifier: normalize(identifier), | ||
label: identifier | ||
} | ||
if (type === T_LINK || type === T_IMAGE) { | ||
node.referenceType = referenceType; | ||
if (type === link || type === image) { | ||
node.referenceType = referenceType | ||
} | ||
if (type === T_LINK) { | ||
exit = self.enterLink(); | ||
node.children = self.tokenizeInline(content, now); | ||
exit(); | ||
} else if (type === T_IMAGE) { | ||
node.alt = self.decode.raw(self.unescape(content), now) || null; | ||
if (type === link) { | ||
exit = self.enterLink() | ||
node.children = self.tokenizeInline(content, now) | ||
exit() | ||
} else if (type === image) { | ||
node.alt = self.decode.raw(self.unescape(content), now) || null | ||
} | ||
return eat(subvalue)(node); | ||
return eat(subvalue)(node) | ||
} |
@@ -1,47 +0,48 @@ | ||
'use strict'; | ||
'use strict' | ||
var trim = require('trim'); | ||
var whitespace = require('is-whitespace-character'); | ||
var locate = require('../locate/strong'); | ||
var trim = require('trim') | ||
var whitespace = require('is-whitespace-character') | ||
var locate = require('../locate/strong') | ||
module.exports = strong; | ||
strong.locator = locate; | ||
module.exports = strong | ||
strong.locator = locate | ||
var C_ASTERISK = '*'; | ||
var C_UNDERSCORE = '_'; | ||
var backslash = '\\' | ||
var asterisk = '*' | ||
var underscore = '_' | ||
function strong(eat, value, silent) { | ||
var self = this; | ||
var index = 0; | ||
var character = value.charAt(index); | ||
var now; | ||
var pedantic; | ||
var marker; | ||
var queue; | ||
var subvalue; | ||
var length; | ||
var prev; | ||
var self = this | ||
var index = 0 | ||
var character = value.charAt(index) | ||
var now | ||
var pedantic | ||
var marker | ||
var queue | ||
var subvalue | ||
var length | ||
var prev | ||
if ( | ||
(character !== C_ASTERISK && character !== C_UNDERSCORE) || | ||
(character !== asterisk && character !== underscore) || | ||
value.charAt(++index) !== character | ||
) { | ||
return; | ||
return | ||
} | ||
pedantic = self.options.pedantic; | ||
marker = character; | ||
subvalue = marker + marker; | ||
length = value.length; | ||
index++; | ||
queue = ''; | ||
character = ''; | ||
pedantic = self.options.pedantic | ||
marker = character | ||
subvalue = marker + marker | ||
length = value.length | ||
index++ | ||
queue = '' | ||
character = '' | ||
if (pedantic && whitespace(value.charAt(index))) { | ||
return; | ||
return | ||
} | ||
while (index < length) { | ||
prev = character; | ||
character = value.charAt(index); | ||
prev = character | ||
character = value.charAt(index) | ||
@@ -53,7 +54,7 @@ if ( | ||
) { | ||
character = value.charAt(index + 2); | ||
character = value.charAt(index + 2) | ||
if (character !== marker) { | ||
if (!trim(queue)) { | ||
return; | ||
return | ||
} | ||
@@ -63,8 +64,8 @@ | ||
if (silent) { | ||
return true; | ||
return true | ||
} | ||
now = eat.now(); | ||
now.column += 2; | ||
now.offset += 2; | ||
now = eat.now() | ||
now.column += 2 | ||
now.offset += 2 | ||
@@ -74,14 +75,14 @@ return eat(subvalue + queue + subvalue)({ | ||
children: self.tokenizeInline(queue, now) | ||
}); | ||
}) | ||
} | ||
} | ||
if (!pedantic && character === '\\') { | ||
queue += character; | ||
character = value.charAt(++index); | ||
if (!pedantic && character === backslash) { | ||
queue += character | ||
character = value.charAt(++index) | ||
} | ||
queue += character; | ||
index++; | ||
queue += character | ||
index++ | ||
} | ||
} |
@@ -1,137 +0,135 @@ | ||
'use strict'; | ||
'use strict' | ||
var whitespace = require('is-whitespace-character'); | ||
var whitespace = require('is-whitespace-character') | ||
module.exports = table; | ||
module.exports = table | ||
var C_BACKSLASH = '\\'; | ||
var C_TICK = '`'; | ||
var C_DASH = '-'; | ||
var C_PIPE = '|'; | ||
var C_COLON = ':'; | ||
var C_SPACE = ' '; | ||
var C_NEWLINE = '\n'; | ||
var C_TAB = '\t'; | ||
var tab = '\t' | ||
var lineFeed = '\n' | ||
var space = ' ' | ||
var dash = '-' | ||
var colon = ':' | ||
var backslash = '\\' | ||
var graveAccent = '`' | ||
var verticalBar = '|' | ||
var MIN_TABLE_COLUMNS = 1; | ||
var MIN_TABLE_ROWS = 2; | ||
var minColumns = 1 | ||
var minRows = 2 | ||
var TABLE_ALIGN_LEFT = 'left'; | ||
var TABLE_ALIGN_CENTER = 'center'; | ||
var TABLE_ALIGN_RIGHT = 'right'; | ||
var TABLE_ALIGN_NONE = null; | ||
var left = 'left' | ||
var center = 'center' | ||
var right = 'right' | ||
function table(eat, value, silent) { | ||
var self = this; | ||
var index; | ||
var alignments; | ||
var alignment; | ||
var subvalue; | ||
var row; | ||
var length; | ||
var lines; | ||
var queue; | ||
var character; | ||
var hasDash; | ||
var align; | ||
var cell; | ||
var preamble; | ||
var count; | ||
var opening; | ||
var now; | ||
var position; | ||
var lineCount; | ||
var line; | ||
var rows; | ||
var table; | ||
var lineIndex; | ||
var pipeIndex; | ||
var first; | ||
var self = this | ||
var index | ||
var alignments | ||
var alignment | ||
var subvalue | ||
var row | ||
var length | ||
var lines | ||
var queue | ||
var character | ||
var hasDash | ||
var align | ||
var cell | ||
var preamble | ||
var count | ||
var opening | ||
var now | ||
var position | ||
var lineCount | ||
var line | ||
var rows | ||
var table | ||
var lineIndex | ||
var pipeIndex | ||
var first | ||
/* Exit when not in gfm-mode. */ | ||
// Exit when not in gfm-mode. | ||
if (!self.options.gfm) { | ||
return; | ||
return | ||
} | ||
/* Get the rows. | ||
* Detecting tables soon is hard, so there are some | ||
* checks for performance here, such as the minimum | ||
* number of rows, and allowed characters in the | ||
* alignment row. */ | ||
index = 0; | ||
lineCount = 0; | ||
length = value.length + 1; | ||
lines = []; | ||
// Get the rows. | ||
// Detecting tables soon is hard, so there are some checks for performance | ||
// here, such as the minimum number of rows, and allowed characters in the | ||
// alignment row. | ||
index = 0 | ||
lineCount = 0 | ||
length = value.length + 1 | ||
lines = [] | ||
while (index < length) { | ||
lineIndex = value.indexOf(C_NEWLINE, index); | ||
pipeIndex = value.indexOf(C_PIPE, index + 1); | ||
lineIndex = value.indexOf(lineFeed, index) | ||
pipeIndex = value.indexOf(verticalBar, index + 1) | ||
if (lineIndex === -1) { | ||
lineIndex = value.length; | ||
lineIndex = value.length | ||
} | ||
if (pipeIndex === -1 || pipeIndex > lineIndex) { | ||
if (lineCount < MIN_TABLE_ROWS) { | ||
return; | ||
if (lineCount < minRows) { | ||
return | ||
} | ||
break; | ||
break | ||
} | ||
lines.push(value.slice(index, lineIndex)); | ||
lineCount++; | ||
index = lineIndex + 1; | ||
lines.push(value.slice(index, lineIndex)) | ||
lineCount++ | ||
index = lineIndex + 1 | ||
} | ||
/* Parse the alignment row. */ | ||
subvalue = lines.join(C_NEWLINE); | ||
alignments = lines.splice(1, 1)[0] || []; | ||
index = 0; | ||
length = alignments.length; | ||
lineCount--; | ||
alignment = false; | ||
align = []; | ||
// Parse the alignment row. | ||
subvalue = lines.join(lineFeed) | ||
alignments = lines.splice(1, 1)[0] || [] | ||
index = 0 | ||
length = alignments.length | ||
lineCount-- | ||
alignment = false | ||
align = [] | ||
while (index < length) { | ||
character = alignments.charAt(index); | ||
character = alignments.charAt(index) | ||
if (character === C_PIPE) { | ||
hasDash = null; | ||
if (character === verticalBar) { | ||
hasDash = null | ||
if (alignment === false) { | ||
if (first === false) { | ||
return; | ||
return | ||
} | ||
} else { | ||
align.push(alignment); | ||
alignment = false; | ||
align.push(alignment) | ||
alignment = false | ||
} | ||
first = false; | ||
} else if (character === C_DASH) { | ||
hasDash = true; | ||
alignment = alignment || TABLE_ALIGN_NONE; | ||
} else if (character === C_COLON) { | ||
if (alignment === TABLE_ALIGN_LEFT) { | ||
alignment = TABLE_ALIGN_CENTER; | ||
} else if (hasDash && alignment === TABLE_ALIGN_NONE) { | ||
alignment = TABLE_ALIGN_RIGHT; | ||
first = false | ||
} else if (character === dash) { | ||
hasDash = true | ||
alignment = alignment || null | ||
} else if (character === colon) { | ||
if (alignment === left) { | ||
alignment = center | ||
} else if (hasDash && alignment === null) { | ||
alignment = right | ||
} else { | ||
alignment = TABLE_ALIGN_LEFT; | ||
alignment = left | ||
} | ||
} else if (!whitespace(character)) { | ||
return; | ||
return | ||
} | ||
index++; | ||
index++ | ||
} | ||
if (alignment !== false) { | ||
align.push(alignment); | ||
align.push(alignment) | ||
} | ||
/* Exit when without enough columns. */ | ||
if (align.length < MIN_TABLE_COLUMNS) { | ||
return; | ||
// Exit when without enough columns. | ||
if (align.length < minColumns) { | ||
return | ||
} | ||
@@ -141,112 +139,107 @@ | ||
if (silent) { | ||
return true; | ||
return true | ||
} | ||
/* Parse the rows. */ | ||
position = -1; | ||
rows = []; | ||
// Parse the rows. | ||
position = -1 | ||
rows = [] | ||
table = eat(subvalue).reset({ | ||
type: 'table', | ||
align: align, | ||
children: rows | ||
}); | ||
table = eat(subvalue).reset({type: 'table', align: align, children: rows}) | ||
while (++position < lineCount) { | ||
line = lines[position]; | ||
row = {type: 'tableRow', children: []}; | ||
line = lines[position] | ||
row = {type: 'tableRow', children: []} | ||
/* Eat a newline character when this is not the | ||
* first row. */ | ||
// Eat a newline character when this is not the first row. | ||
if (position) { | ||
eat(C_NEWLINE); | ||
eat(lineFeed) | ||
} | ||
/* Eat the row. */ | ||
eat(line).reset(row, table); | ||
// Eat the row. | ||
eat(line).reset(row, table) | ||
length = line.length + 1; | ||
index = 0; | ||
queue = ''; | ||
cell = ''; | ||
preamble = true; | ||
count = null; | ||
opening = null; | ||
length = line.length + 1 | ||
index = 0 | ||
queue = '' | ||
cell = '' | ||
preamble = true | ||
count = null | ||
opening = null | ||
while (index < length) { | ||
character = line.charAt(index); | ||
character = line.charAt(index) | ||
if (character === C_TAB || character === C_SPACE) { | ||
if (character === tab || character === space) { | ||
if (cell) { | ||
queue += character; | ||
queue += character | ||
} else { | ||
eat(character); | ||
eat(character) | ||
} | ||
index++; | ||
continue; | ||
index++ | ||
continue | ||
} | ||
if (character === '' || character === C_PIPE) { | ||
if (character === '' || character === verticalBar) { | ||
if (preamble) { | ||
eat(character); | ||
eat(character) | ||
} else { | ||
if (character && opening) { | ||
queue += character; | ||
index++; | ||
continue; | ||
queue += character | ||
index++ | ||
continue | ||
} | ||
if ((cell || character) && !preamble) { | ||
subvalue = cell; | ||
subvalue = cell | ||
if (queue.length > 1) { | ||
if (character) { | ||
subvalue += queue.slice(0, queue.length - 1); | ||
queue = queue.charAt(queue.length - 1); | ||
subvalue += queue.slice(0, queue.length - 1) | ||
queue = queue.charAt(queue.length - 1) | ||
} else { | ||
subvalue += queue; | ||
queue = ''; | ||
subvalue += queue | ||
queue = '' | ||
} | ||
} | ||
now = eat.now(); | ||
now = eat.now() | ||
eat(subvalue)({ | ||
type: 'tableCell', | ||
children: self.tokenizeInline(cell, now) | ||
}, row); | ||
eat(subvalue)( | ||
{type: 'tableCell', children: self.tokenizeInline(cell, now)}, | ||
row | ||
) | ||
} | ||
eat(queue + character); | ||
eat(queue + character) | ||
queue = ''; | ||
cell = ''; | ||
queue = '' | ||
cell = '' | ||
} | ||
} else { | ||
if (queue) { | ||
cell += queue; | ||
queue = ''; | ||
cell += queue | ||
queue = '' | ||
} | ||
cell += character; | ||
cell += character | ||
if (character === C_BACKSLASH && index !== length - 2) { | ||
cell += line.charAt(index + 1); | ||
index++; | ||
if (character === backslash && index !== length - 2) { | ||
cell += line.charAt(index + 1) | ||
index++ | ||
} | ||
if (character === C_TICK) { | ||
count = 1; | ||
if (character === graveAccent) { | ||
count = 1 | ||
while (line.charAt(index + 1) === character) { | ||
cell += character; | ||
index++; | ||
count++; | ||
cell += character | ||
index++ | ||
count++ | ||
} | ||
if (!opening) { | ||
opening = count; | ||
opening = count | ||
} else if (count >= opening) { | ||
opening = 0; | ||
opening = 0 | ||
} | ||
@@ -256,13 +249,13 @@ } | ||
preamble = false; | ||
index++; | ||
preamble = false | ||
index++ | ||
} | ||
/* Eat the alignment row. */ | ||
// Eat the alignment row. | ||
if (!position) { | ||
eat(C_NEWLINE + alignments); | ||
eat(lineFeed + alignments) | ||
} | ||
} | ||
return table; | ||
return table | ||
} |
@@ -1,58 +0,57 @@ | ||
'use strict'; | ||
'use strict' | ||
module.exports = text; | ||
module.exports = text | ||
function text(eat, value, silent) { | ||
var self = this; | ||
var methods; | ||
var tokenizers; | ||
var index; | ||
var length; | ||
var subvalue; | ||
var position; | ||
var tokenizer; | ||
var name; | ||
var min; | ||
var now; | ||
var self = this | ||
var methods | ||
var tokenizers | ||
var index | ||
var length | ||
var subvalue | ||
var position | ||
var tokenizer | ||
var name | ||
var min | ||
var now | ||
/* istanbul ignore if - never used (yet) */ | ||
if (silent) { | ||
return true; | ||
return true | ||
} | ||
methods = self.inlineMethods; | ||
length = methods.length; | ||
tokenizers = self.inlineTokenizers; | ||
index = -1; | ||
min = value.length; | ||
methods = self.inlineMethods | ||
length = methods.length | ||
tokenizers = self.inlineTokenizers | ||
index = -1 | ||
min = value.length | ||
while (++index < length) { | ||
name = methods[index]; | ||
name = methods[index] | ||
if (name === 'text' || !tokenizers[name]) { | ||
continue; | ||
continue | ||
} | ||
tokenizer = tokenizers[name].locator; | ||
tokenizer = tokenizers[name].locator | ||
if (!tokenizer) { | ||
eat.file.fail('Missing locator: `' + name + '`'); | ||
eat.file.fail('Missing locator: `' + name + '`') | ||
} | ||
position = tokenizer.call(self, value, 1); | ||
position = tokenizer.call(self, value, 1) | ||
if (position !== -1 && position < min) { | ||
min = position; | ||
min = position | ||
} | ||
} | ||
subvalue = value.slice(0, min); | ||
now = eat.now(); | ||
subvalue = value.slice(0, min) | ||
now = eat.now() | ||
self.decode(subvalue, now, function (content, position, source) { | ||
eat(source || content)({ | ||
type: 'text', | ||
value: content | ||
}); | ||
}); | ||
self.decode(subvalue, now, handler) | ||
function handler(content, position, source) { | ||
eat(source || content)({type: 'text', value: content}) | ||
} | ||
} |
@@ -1,70 +0,70 @@ | ||
'use strict'; | ||
'use strict' | ||
module.exports = thematicBreak; | ||
module.exports = thematicBreak | ||
var C_NEWLINE = '\n'; | ||
var C_TAB = '\t'; | ||
var C_SPACE = ' '; | ||
var C_ASTERISK = '*'; | ||
var C_UNDERSCORE = '_'; | ||
var C_DASH = '-'; | ||
var tab = '\t' | ||
var lineFeed = '\n' | ||
var space = ' ' | ||
var asterisk = '*' | ||
var dash = '-' | ||
var underscore = '_' | ||
var THEMATIC_BREAK_MARKER_COUNT = 3; | ||
var maxCount = 3 | ||
function thematicBreak(eat, value, silent) { | ||
var index = -1; | ||
var length = value.length + 1; | ||
var subvalue = ''; | ||
var character; | ||
var marker; | ||
var markerCount; | ||
var queue; | ||
var index = -1 | ||
var length = value.length + 1 | ||
var subvalue = '' | ||
var character | ||
var marker | ||
var markerCount | ||
var queue | ||
while (++index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character !== C_TAB && character !== C_SPACE) { | ||
break; | ||
if (character !== tab && character !== space) { | ||
break | ||
} | ||
subvalue += character; | ||
subvalue += character | ||
} | ||
if ( | ||
character !== C_ASTERISK && | ||
character !== C_DASH && | ||
character !== C_UNDERSCORE | ||
character !== asterisk && | ||
character !== dash && | ||
character !== underscore | ||
) { | ||
return; | ||
return | ||
} | ||
marker = character; | ||
subvalue += character; | ||
markerCount = 1; | ||
queue = ''; | ||
marker = character | ||
subvalue += character | ||
markerCount = 1 | ||
queue = '' | ||
while (++index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (character === marker) { | ||
markerCount++; | ||
subvalue += queue + marker; | ||
queue = ''; | ||
} else if (character === C_SPACE) { | ||
queue += character; | ||
markerCount++ | ||
subvalue += queue + marker | ||
queue = '' | ||
} else if (character === space) { | ||
queue += character | ||
} else if ( | ||
markerCount >= THEMATIC_BREAK_MARKER_COUNT && | ||
(!character || character === C_NEWLINE) | ||
markerCount >= maxCount && | ||
(!character || character === lineFeed) | ||
) { | ||
subvalue += queue; | ||
subvalue += queue | ||
if (silent) { | ||
return true; | ||
return true | ||
} | ||
return eat(subvalue)({type: 'thematicBreak'}); | ||
return eat(subvalue)({type: 'thematicBreak'}) | ||
} else { | ||
return; | ||
return | ||
} | ||
} | ||
} |
@@ -1,60 +0,62 @@ | ||
'use strict'; | ||
'use strict' | ||
var decode = require('parse-entities'); | ||
var whitespace = require('is-whitespace-character'); | ||
var locate = require('../locate/url'); | ||
var decode = require('parse-entities') | ||
var whitespace = require('is-whitespace-character') | ||
var locate = require('../locate/url') | ||
module.exports = url; | ||
url.locator = locate; | ||
url.notInLink = true; | ||
module.exports = url | ||
url.locator = locate | ||
url.notInLink = true | ||
var C_BRACKET_OPEN = '['; | ||
var C_BRACKET_CLOSE = ']'; | ||
var C_PAREN_OPEN = '('; | ||
var C_PAREN_CLOSE = ')'; | ||
var C_LT = '<'; | ||
var C_AT_SIGN = '@'; | ||
var quotationMark = '"' | ||
var apostrophe = "'" | ||
var leftParenthesis = '(' | ||
var rightParenthesis = ')' | ||
var comma = ',' | ||
var dot = '.' | ||
var colon = ':' | ||
var semicolon = ';' | ||
var lessThan = '<' | ||
var atSign = '@' | ||
var leftSquareBracket = '[' | ||
var rightSquareBracket = ']' | ||
var HTTP_PROTOCOL = 'http://'; | ||
var HTTPS_PROTOCOL = 'https://'; | ||
var MAILTO_PROTOCOL = 'mailto:'; | ||
var http = 'http://' | ||
var https = 'https://' | ||
var mailto = 'mailto:' | ||
var PROTOCOLS = [ | ||
HTTP_PROTOCOL, | ||
HTTPS_PROTOCOL, | ||
MAILTO_PROTOCOL | ||
]; | ||
var protocols = [http, https, mailto] | ||
var PROTOCOLS_LENGTH = PROTOCOLS.length; | ||
var protocolsLength = protocols.length | ||
function url(eat, value, silent) { | ||
var self = this; | ||
var subvalue; | ||
var content; | ||
var character; | ||
var index; | ||
var position; | ||
var protocol; | ||
var match; | ||
var length; | ||
var queue; | ||
var parenCount; | ||
var nextCharacter; | ||
var exit; | ||
var self = this | ||
var subvalue | ||
var content | ||
var character | ||
var index | ||
var position | ||
var protocol | ||
var match | ||
var length | ||
var queue | ||
var parenCount | ||
var nextCharacter | ||
var tokenizers | ||
var exit | ||
if (!self.options.gfm) { | ||
return; | ||
return | ||
} | ||
subvalue = ''; | ||
index = -1; | ||
length = PROTOCOLS_LENGTH; | ||
subvalue = '' | ||
index = -1 | ||
while (++index < length) { | ||
protocol = PROTOCOLS[index]; | ||
match = value.slice(0, protocol.length); | ||
while (++index < protocolsLength) { | ||
protocol = protocols[index] | ||
match = value.slice(0, protocol.length) | ||
if (match.toLowerCase() === protocol) { | ||
subvalue = match; | ||
break; | ||
subvalue = match | ||
break | ||
} | ||
@@ -64,65 +66,65 @@ } | ||
if (!subvalue) { | ||
return; | ||
return | ||
} | ||
index = subvalue.length; | ||
length = value.length; | ||
queue = ''; | ||
parenCount = 0; | ||
index = subvalue.length | ||
length = value.length | ||
queue = '' | ||
parenCount = 0 | ||
while (index < length) { | ||
character = value.charAt(index); | ||
character = value.charAt(index) | ||
if (whitespace(character) || character === C_LT) { | ||
break; | ||
if (whitespace(character) || character === lessThan) { | ||
break | ||
} | ||
if ( | ||
character === '.' || | ||
character === ',' || | ||
character === ':' || | ||
character === ';' || | ||
character === '"' || | ||
character === '\'' || | ||
character === ')' || | ||
character === ']' | ||
character === dot || | ||
character === comma || | ||
character === colon || | ||
character === semicolon || | ||
character === quotationMark || | ||
character === apostrophe || | ||
character === rightParenthesis || | ||
character === rightSquareBracket | ||
) { | ||
nextCharacter = value.charAt(index + 1); | ||
nextCharacter = value.charAt(index + 1) | ||
if (!nextCharacter || whitespace(nextCharacter)) { | ||
break; | ||
break | ||
} | ||
} | ||
if (character === C_PAREN_OPEN || character === C_BRACKET_OPEN) { | ||
parenCount++; | ||
if (character === leftParenthesis || character === leftSquareBracket) { | ||
parenCount++ | ||
} | ||
if (character === C_PAREN_CLOSE || character === C_BRACKET_CLOSE) { | ||
parenCount--; | ||
if (character === rightParenthesis || character === rightSquareBracket) { | ||
parenCount-- | ||
if (parenCount < 0) { | ||
break; | ||
break | ||
} | ||
} | ||
queue += character; | ||
index++; | ||
queue += character | ||
index++ | ||
} | ||
if (!queue) { | ||
return; | ||
return | ||
} | ||
subvalue += queue; | ||
content = subvalue; | ||
subvalue += queue | ||
content = subvalue | ||
if (protocol === MAILTO_PROTOCOL) { | ||
position = queue.indexOf(C_AT_SIGN); | ||
if (protocol === mailto) { | ||
position = queue.indexOf(atSign) | ||
if (position === -1 || position === length - 1) { | ||
return; | ||
return | ||
} | ||
content = content.substr(MAILTO_PROTOCOL.length); | ||
content = content.substr(mailto.length) | ||
} | ||
@@ -132,9 +134,16 @@ | ||
if (silent) { | ||
return true; | ||
return true | ||
} | ||
exit = self.enterLink(); | ||
content = self.tokenizeInline(content, eat.now()); | ||
exit(); | ||
exit = self.enterLink() | ||
// Temporarily remove all tokenizers except text in url. | ||
tokenizers = self.inlineTokenizers | ||
self.inlineTokenizers = {text: tokenizers.text} | ||
content = self.tokenizeInline(content, eat.now()) | ||
self.inlineTokenizers = tokenizers | ||
exit() | ||
return eat(subvalue)({ | ||
@@ -145,3 +154,3 @@ type: 'link', | ||
children: content | ||
}); | ||
}) | ||
} |
@@ -1,93 +0,48 @@ | ||
'use strict'; | ||
'use strict' | ||
module.exports = factory; | ||
module.exports = factory | ||
var MERGEABLE_NODES = { | ||
text: mergeText, | ||
blockquote: mergeBlockquote | ||
}; | ||
/* Check whether a node is mergeable with adjacent nodes. */ | ||
function mergeable(node) { | ||
var start; | ||
var end; | ||
if (node.type !== 'text' || !node.position) { | ||
return true; | ||
} | ||
start = node.position.start; | ||
end = node.position.end; | ||
/* Only merge nodes which occupy the same size as their | ||
* `value`. */ | ||
return start.line !== end.line || | ||
end.column - start.column === node.value.length; | ||
} | ||
/* Merge two text nodes: `node` into `prev`. */ | ||
function mergeText(prev, node) { | ||
prev.value += node.value; | ||
return prev; | ||
} | ||
/* Merge two blockquotes: `node` into `prev`, unless in | ||
* CommonMark mode. */ | ||
function mergeBlockquote(prev, node) { | ||
if (this.options.commonmark) { | ||
return node; | ||
} | ||
prev.children = prev.children.concat(node.children); | ||
return prev; | ||
} | ||
/* Construct a tokenizer. This creates both | ||
* `tokenizeInline` and `tokenizeBlock`. */ | ||
// Construct a tokenizer. This creates both `tokenizeInline` and `tokenizeBlock`. | ||
function factory(type) { | ||
return tokenize; | ||
return tokenize | ||
/* Tokenizer for a bound `type`. */ | ||
// Tokenizer for a bound `type`. | ||
function tokenize(value, location) { | ||
var self = this; | ||
var offset = self.offset; | ||
var tokens = []; | ||
var methods = self[type + 'Methods']; | ||
var tokenizers = self[type + 'Tokenizers']; | ||
var line = location.line; | ||
var column = location.column; | ||
var index; | ||
var length; | ||
var method; | ||
var name; | ||
var matched; | ||
var valueLength; | ||
var self = this | ||
var offset = self.offset | ||
var tokens = [] | ||
var methods = self[type + 'Methods'] | ||
var tokenizers = self[type + 'Tokenizers'] | ||
var line = location.line | ||
var column = location.column | ||
var index | ||
var length | ||
var method | ||
var name | ||
var matched | ||
var valueLength | ||
/* Trim white space only lines. */ | ||
// Trim white space only lines. | ||
if (!value) { | ||
return tokens; | ||
return tokens | ||
} | ||
/* Expose on `eat`. */ | ||
eat.now = now; | ||
eat.file = self.file; | ||
// Expose on `eat`. | ||
eat.now = now | ||
eat.file = self.file | ||
/* Sync initial offset. */ | ||
updatePosition(''); | ||
// Sync initial offset. | ||
updatePosition('') | ||
/* Iterate over `value`, and iterate over all | ||
* tokenizers. When one eats something, re-iterate | ||
* with the remaining value. If no tokenizer eats, | ||
* something failed (should not happen) and an | ||
* exception is thrown. */ | ||
// Iterate over `value`, and iterate over all tokenizers. When one eats | ||
// something, re-iterate with the remaining value. If no tokenizer eats, | ||
// something failed (should not happen) and an exception is thrown. | ||
while (value) { | ||
index = -1; | ||
length = methods.length; | ||
matched = false; | ||
index = -1 | ||
length = methods.length | ||
matched = false | ||
while (++index < length) { | ||
name = methods[index]; | ||
method = tokenizers[name]; | ||
name = methods[index] | ||
method = tokenizers[name] | ||
@@ -101,10 +56,10 @@ if ( | ||
) { | ||
valueLength = value.length; | ||
valueLength = value.length | ||
method.apply(self, [eat, value]); | ||
method.apply(self, [eat, value]) | ||
matched = valueLength !== value.length; | ||
matched = valueLength !== value.length | ||
if (matched) { | ||
break; | ||
break | ||
} | ||
@@ -116,26 +71,25 @@ } | ||
if (!matched) { | ||
self.file.fail(new Error('Infinite loop'), eat.now()); | ||
self.file.fail(new Error('Infinite loop'), eat.now()) | ||
} | ||
} | ||
self.eof = now(); | ||
self.eof = now() | ||
return tokens; | ||
return tokens | ||
/* Update line, column, and offset based on | ||
* `value`. */ | ||
// Update line, column, and offset based on `value`. | ||
function updatePosition(subvalue) { | ||
var lastIndex = -1; | ||
var index = subvalue.indexOf('\n'); | ||
var lastIndex = -1 | ||
var index = subvalue.indexOf('\n') | ||
while (index !== -1) { | ||
line++; | ||
lastIndex = index; | ||
index = subvalue.indexOf('\n', index + 1); | ||
line++ | ||
lastIndex = index | ||
index = subvalue.indexOf('\n', index + 1) | ||
} | ||
if (lastIndex === -1) { | ||
column += subvalue.length; | ||
column += subvalue.length | ||
} else { | ||
column = subvalue.length - lastIndex; | ||
column = subvalue.length - lastIndex | ||
} | ||
@@ -145,5 +99,5 @@ | ||
if (lastIndex !== -1) { | ||
column += offset[line]; | ||
column += offset[line] | ||
} else if (column <= offset[line]) { | ||
column = offset[line] + 1; | ||
column = offset[line] + 1 | ||
} | ||
@@ -153,104 +107,100 @@ } | ||
/* Get offset. Called before the first character is | ||
* eaten to retrieve the range's offsets. */ | ||
// Get offset. Called before the first character is eaten to retrieve the | ||
// range’s offsets. | ||
function getOffset() { | ||
var indentation = []; | ||
var pos = line + 1; | ||
var indentation = [] | ||
var pos = line + 1 | ||
/* Done. Called when the last character is | ||
* eaten to retrieve the range’s offsets. */ | ||
return function () { | ||
var last = line + 1; | ||
// Done. Called when the last character is eaten to retrieve the range’s | ||
// offsets. | ||
return function() { | ||
var last = line + 1 | ||
while (pos < last) { | ||
indentation.push((offset[pos] || 0) + 1); | ||
indentation.push((offset[pos] || 0) + 1) | ||
pos++; | ||
pos++ | ||
} | ||
return indentation; | ||
}; | ||
return indentation | ||
} | ||
} | ||
/* Get the current position. */ | ||
// Get the current position. | ||
function now() { | ||
var pos = {line: line, column: column}; | ||
var pos = {line: line, column: column} | ||
pos.offset = self.toOffset(pos); | ||
pos.offset = self.toOffset(pos) | ||
return pos; | ||
return pos | ||
} | ||
/* Store position information for a node. */ | ||
// Store position information for a node. | ||
function Position(start) { | ||
this.start = start; | ||
this.end = now(); | ||
this.start = start | ||
this.end = now() | ||
} | ||
/* Throw when a value is incorrectly eaten. | ||
* This shouldn’t happen but will throw on new, | ||
* incorrect rules. */ | ||
// Throw when a value is incorrectly eaten. This shouldn’t happen but will | ||
// throw on new, incorrect rules. | ||
function validateEat(subvalue) { | ||
/* istanbul ignore if */ | ||
if (value.substring(0, subvalue.length) !== subvalue) { | ||
/* Capture stack-trace. */ | ||
// Capture stack-trace. | ||
self.file.fail( | ||
new Error( | ||
'Incorrectly eaten value: please report this ' + | ||
'warning on http://git.io/vg5Ft' | ||
'Incorrectly eaten value: please report this warning on https://git.io/vg5Ft' | ||
), | ||
now() | ||
); | ||
) | ||
} | ||
} | ||
/* Mark position and patch `node.position`. */ | ||
// Mark position and patch `node.position`. | ||
function position() { | ||
var before = now(); | ||
var before = now() | ||
return update; | ||
return update | ||
/* Add the position to a node. */ | ||
// Add the position to a node. | ||
function update(node, indent) { | ||
var prev = node.position; | ||
var start = prev ? prev.start : before; | ||
var combined = []; | ||
var n = prev && prev.end.line; | ||
var l = before.line; | ||
var prev = node.position | ||
var start = prev ? prev.start : before | ||
var combined = [] | ||
var n = prev && prev.end.line | ||
var l = before.line | ||
node.position = new Position(start); | ||
node.position = new Position(start) | ||
/* If there was already a `position`, this | ||
* node was merged. Fixing `start` wasn’t | ||
* hard, but the indent is different. | ||
* Especially because some information, the | ||
* indent between `n` and `l` wasn’t | ||
* tracked. Luckily, that space is | ||
* (should be?) empty, so we can safely | ||
* check for it now. */ | ||
// If there was already a `position`, this node was merged. Fixing | ||
// `start` wasn’t hard, but the indent is different. Especially | ||
// because some information, the indent between `n` and `l` wasn’t | ||
// tracked. Luckily, that space is (should be?) empty, so we can | ||
// safely check for it now. | ||
if (prev && indent && prev.indent) { | ||
combined = prev.indent; | ||
combined = prev.indent | ||
if (n < l) { | ||
while (++n < l) { | ||
combined.push((offset[n] || 0) + 1); | ||
combined.push((offset[n] || 0) + 1) | ||
} | ||
combined.push(before.column); | ||
combined.push(before.column) | ||
} | ||
indent = combined.concat(indent); | ||
indent = combined.concat(indent) | ||
} | ||
node.position.indent = indent || []; | ||
node.position.indent = indent || [] | ||
return node; | ||
return node | ||
} | ||
} | ||
/* Add `node` to `parent`s children or to `tokens`. | ||
* Performs merges where possible. */ | ||
// Add `node` to `parent`s children or to `tokens`. Performs merges where | ||
// possible. | ||
function add(node, parent) { | ||
var children = parent ? parent.children : tokens; | ||
var prev = children[children.length - 1]; | ||
var children = parent ? parent.children : tokens | ||
var prev = children[children.length - 1] | ||
var fn | ||
@@ -260,74 +210,71 @@ if ( | ||
node.type === prev.type && | ||
node.type in MERGEABLE_NODES && | ||
(node.type === 'text' || node.type === 'blockquote') && | ||
mergeable(prev) && | ||
mergeable(node) | ||
) { | ||
node = MERGEABLE_NODES[node.type].call(self, prev, node); | ||
fn = node.type === 'text' ? mergeText : mergeBlockquote | ||
node = fn.call(self, prev, node) | ||
} | ||
if (node !== prev) { | ||
children.push(node); | ||
children.push(node) | ||
} | ||
if (self.atStart && tokens.length !== 0) { | ||
self.exitStart(); | ||
self.exitStart() | ||
} | ||
return node; | ||
return node | ||
} | ||
/* Remove `subvalue` from `value`. | ||
* `subvalue` must be at the start of `value`. */ | ||
// Remove `subvalue` from `value`. `subvalue` must be at the start of | ||
// `value`. | ||
function eat(subvalue) { | ||
var indent = getOffset(); | ||
var pos = position(); | ||
var current = now(); | ||
var indent = getOffset() | ||
var pos = position() | ||
var current = now() | ||
validateEat(subvalue); | ||
validateEat(subvalue) | ||
apply.reset = reset; | ||
reset.test = test; | ||
apply.test = test; | ||
apply.reset = reset | ||
reset.test = test | ||
apply.test = test | ||
value = value.substring(subvalue.length); | ||
value = value.substring(subvalue.length) | ||
updatePosition(subvalue); | ||
updatePosition(subvalue) | ||
indent = indent(); | ||
indent = indent() | ||
return apply; | ||
return apply | ||
/* Add the given arguments, add `position` to | ||
* the returned node, and return the node. */ | ||
// Add the given arguments, add `position` to the returned node, and | ||
// return the node. | ||
function apply(node, parent) { | ||
return pos(add(pos(node), parent), indent); | ||
return pos(add(pos(node), parent), indent) | ||
} | ||
/* Functions just like apply, but resets the | ||
* content: the line and column are reversed, | ||
* and the eaten value is re-added. | ||
* This is useful for nodes with a single | ||
* type of content, such as lists and tables. | ||
* See `apply` above for what parameters are | ||
* expected. */ | ||
// Functions just like apply, but resets the content: the line and | ||
// column are reversed, and the eaten value is re-added. This is | ||
// useful for nodes with a single type of content, such as lists and | ||
// tables. See `apply` above for what parameters are expected. | ||
function reset() { | ||
var node = apply.apply(null, arguments); | ||
var node = apply.apply(null, arguments) | ||
line = current.line; | ||
column = current.column; | ||
value = subvalue + value; | ||
line = current.line | ||
column = current.column | ||
value = subvalue + value | ||
return node; | ||
return node | ||
} | ||
/* Test the position, after eating, and reverse | ||
* to a not-eaten state. */ | ||
// Test the position, after eating, and reverse to a not-eaten state. | ||
function test() { | ||
var result = pos({}); | ||
var result = pos({}) | ||
line = current.line; | ||
column = current.column; | ||
value = subvalue + value; | ||
line = current.line | ||
column = current.column | ||
value = subvalue + value | ||
return result.position; | ||
return result.position | ||
} | ||
@@ -337,1 +284,37 @@ } | ||
} | ||
// Check whether a node is mergeable with adjacent nodes. | ||
function mergeable(node) { | ||
var start | ||
var end | ||
if (node.type !== 'text' || !node.position) { | ||
return true | ||
} | ||
start = node.position.start | ||
end = node.position.end | ||
// Only merge nodes which occupy the same size as their `value`. | ||
return ( | ||
start.line !== end.line || end.column - start.column === node.value.length | ||
) | ||
} | ||
// Merge two text nodes: `node` into `prev`. | ||
function mergeText(prev, node) { | ||
prev.value += node.value | ||
return prev | ||
} | ||
// Merge two blockquotes: `node` into `prev`, unless in CommonMark mode. | ||
function mergeBlockquote(prev, node) { | ||
if (this.options.commonmark) { | ||
return node | ||
} | ||
prev.children = prev.children.concat(node.children) | ||
return prev | ||
} |
@@ -1,37 +0,36 @@ | ||
'use strict'; | ||
'use strict' | ||
module.exports = factory; | ||
module.exports = factory | ||
/* Factory to de-escape a value, based on a list at `key` | ||
* in `ctx`. */ | ||
var backslash = '\\' | ||
// Factory to de-escape a value, based on a list at `key` in `ctx`. | ||
function factory(ctx, key) { | ||
return unescape; | ||
return unescape | ||
/* De-escape a string using the expression at `key` | ||
* in `ctx`. */ | ||
// De-escape a string using the expression at `key` in `ctx`. | ||
function unescape(value) { | ||
var prev = 0; | ||
var index = value.indexOf('\\'); | ||
var escape = ctx[key]; | ||
var queue = []; | ||
var character; | ||
var prev = 0 | ||
var index = value.indexOf(backslash) | ||
var escape = ctx[key] | ||
var queue = [] | ||
var character | ||
while (index !== -1) { | ||
queue.push(value.slice(prev, index)); | ||
prev = index + 1; | ||
character = value.charAt(prev); | ||
queue.push(value.slice(prev, index)) | ||
prev = index + 1 | ||
character = value.charAt(prev) | ||
/* If the following character is not a valid escape, | ||
* add the slash. */ | ||
// If the following character is not a valid escape, add the slash. | ||
if (!character || escape.indexOf(character) === -1) { | ||
queue.push('\\'); | ||
queue.push(backslash) | ||
} | ||
index = value.indexOf('\\', prev); | ||
index = value.indexOf(backslash, prev) | ||
} | ||
queue.push(value.slice(prev)); | ||
queue.push(value.slice(prev)) | ||
return queue.join(''); | ||
return queue.join('') | ||
} | ||
} |
@@ -1,32 +0,33 @@ | ||
'use strict'; | ||
'use strict' | ||
module.exports = indentation; | ||
module.exports = indentation | ||
/* Map of characters, and their column length, | ||
* which can be used as indentation. */ | ||
var characters = {' ': 1, '\t': 4}; | ||
var tab = '\t' | ||
var space = ' ' | ||
/* Gets indentation information for a line. */ | ||
var spaceSize = 1 | ||
var tabSize = 4 | ||
// Gets indentation information for a line. | ||
function indentation(value) { | ||
var index = 0; | ||
var indent = 0; | ||
var character = value.charAt(index); | ||
var stops = {}; | ||
var size; | ||
var index = 0 | ||
var indent = 0 | ||
var character = value.charAt(index) | ||
var stops = {} | ||
var size | ||
while (character in characters) { | ||
size = characters[character]; | ||
while (character === tab || character === space) { | ||
size = character === tab ? tabSize : spaceSize | ||
indent += size; | ||
indent += size | ||
if (size > 1) { | ||
indent = Math.floor(indent / size) * size; | ||
indent = Math.floor(indent / size) * size | ||
} | ||
stops[indent] = index; | ||
character = value.charAt(++index); | ||
stops[indent] = index | ||
character = value.charAt(++index) | ||
} | ||
return {indent: indent, stops: stops}; | ||
return {indent: indent, stops: stops} | ||
} |
@@ -1,25 +0,34 @@ | ||
'use strict'; | ||
'use strict' | ||
var attributeName = '[a-zA-Z_:][a-zA-Z0-9:._-]*'; | ||
var unquoted = '[^"\'=<>`\\u0000-\\u0020]+'; | ||
var singleQuoted = '\'[^\']*\''; | ||
var doubleQuoted = '"[^"]*"'; | ||
var attributeValue = '(?:' + unquoted + '|' + singleQuoted + '|' + doubleQuoted + ')'; | ||
var attribute = '(?:\\s+' + attributeName + '(?:\\s*=\\s*' + attributeValue + ')?)'; | ||
var openTag = '<[A-Za-z][A-Za-z0-9\\-]*' + attribute + '*\\s*\\/?>'; | ||
var closeTag = '<\\/[A-Za-z][A-Za-z0-9\\-]*\\s*>'; | ||
var comment = '<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->'; | ||
var processing = '<[?].*?[?]>'; | ||
var declaration = '<![A-Za-z]+\\s+[^>]*>'; | ||
var cdata = '<!\\[CDATA\\[[\\s\\S]*?\\]\\]>'; | ||
var attributeName = '[a-zA-Z_:][a-zA-Z0-9:._-]*' | ||
var unquoted = '[^"\'=<>`\\u0000-\\u0020]+' | ||
var singleQuoted = "'[^']*'" | ||
var doubleQuoted = '"[^"]*"' | ||
var attributeValue = | ||
'(?:' + unquoted + '|' + singleQuoted + '|' + doubleQuoted + ')' | ||
var attribute = | ||
'(?:\\s+' + attributeName + '(?:\\s*=\\s*' + attributeValue + ')?)' | ||
var openTag = '<[A-Za-z][A-Za-z0-9\\-]*' + attribute + '*\\s*\\/?>' | ||
var closeTag = '<\\/[A-Za-z][A-Za-z0-9\\-]*\\s*>' | ||
var comment = '<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->' | ||
var processing = '<[?].*?[?]>' | ||
var declaration = '<![A-Za-z]+\\s+[^>]*>' | ||
var cdata = '<!\\[CDATA\\[[\\s\\S]*?\\]\\]>' | ||
exports.openCloseTag = new RegExp('^(?:' + openTag + '|' + closeTag + ')'); | ||
exports.openCloseTag = new RegExp('^(?:' + openTag + '|' + closeTag + ')') | ||
exports.tag = new RegExp('^(?:' + | ||
openTag + '|' + | ||
closeTag + '|' + | ||
comment + '|' + | ||
processing + '|' + | ||
declaration + '|' + | ||
cdata + | ||
')'); | ||
exports.tag = new RegExp( | ||
'^(?:' + | ||
openTag + | ||
'|' + | ||
closeTag + | ||
'|' + | ||
comment + | ||
'|' + | ||
processing + | ||
'|' + | ||
declaration + | ||
'|' + | ||
cdata + | ||
')' | ||
) |
@@ -1,43 +0,35 @@ | ||
'use strict'; | ||
'use strict' | ||
module.exports = interrupt; | ||
module.exports = interrupt | ||
function interrupt(interruptors, tokenizers, ctx, params) { | ||
var bools = ['pedantic', 'commonmark']; | ||
var count = bools.length; | ||
var length = interruptors.length; | ||
var index = -1; | ||
var interruptor; | ||
var config; | ||
var fn; | ||
var offset; | ||
var bool; | ||
var ignore; | ||
var length = interruptors.length | ||
var index = -1 | ||
var interruptor | ||
var config | ||
while (++index < length) { | ||
interruptor = interruptors[index]; | ||
config = interruptor[1] || {}; | ||
fn = interruptor[0]; | ||
offset = -1; | ||
ignore = false; | ||
interruptor = interruptors[index] | ||
config = interruptor[1] || {} | ||
while (++offset < count) { | ||
bool = bools[offset]; | ||
if (config[bool] !== undefined && config[bool] !== ctx.options[bool]) { | ||
ignore = true; | ||
break; | ||
} | ||
if ( | ||
config.pedantic !== undefined && | ||
config.pedantic !== ctx.options.pedantic | ||
) { | ||
continue | ||
} | ||
if (ignore) { | ||
continue; | ||
if ( | ||
config.commonmark !== undefined && | ||
config.commonmark !== ctx.options.commonmark | ||
) { | ||
continue | ||
} | ||
if (tokenizers[fn].apply(ctx, params)) { | ||
return true; | ||
if (tokenizers[interruptor[0]].apply(ctx, params)) { | ||
return true | ||
} | ||
} | ||
return false; | ||
return false | ||
} |
@@ -1,11 +0,11 @@ | ||
'use strict'; | ||
'use strict' | ||
var collapseWhiteSpace = require('collapse-white-space'); | ||
var collapseWhiteSpace = require('collapse-white-space') | ||
module.exports = normalize; | ||
module.exports = normalize | ||
/* Normalize an identifier. Collapses multiple white space | ||
* characters into a single space, and removes casing. */ | ||
// Normalize an identifier. Collapses multiple white space characters into a | ||
// single space, and removes casing. | ||
function normalize(value) { | ||
return collapseWhiteSpace(value).toLowerCase(); | ||
return collapseWhiteSpace(value).toLowerCase() | ||
} |
@@ -1,35 +0,35 @@ | ||
'use strict'; | ||
'use strict' | ||
var trim = require('trim'); | ||
var repeat = require('repeat-string'); | ||
var getIndent = require('./get-indentation'); | ||
var trim = require('trim') | ||
var repeat = require('repeat-string') | ||
var getIndent = require('./get-indentation') | ||
module.exports = indentation; | ||
module.exports = indentation | ||
var C_SPACE = ' '; | ||
var C_NEWLINE = '\n'; | ||
var C_TAB = '\t'; | ||
var tab = '\t' | ||
var lineFeed = '\n' | ||
var space = ' ' | ||
var exclamationMark = '!' | ||
/* Remove the minimum indent from every line in `value`. | ||
* Supports both tab, spaced, and mixed indentation (as | ||
* well as possible). */ | ||
// Remove the minimum indent from every line in `value`. Supports both tab, | ||
// spaced, and mixed indentation (as well as possible). | ||
function indentation(value, maximum) { | ||
var values = value.split(C_NEWLINE); | ||
var position = values.length + 1; | ||
var minIndent = Infinity; | ||
var matrix = []; | ||
var index; | ||
var indentation; | ||
var stops; | ||
var padding; | ||
var values = value.split(lineFeed) | ||
var position = values.length + 1 | ||
var minIndent = Infinity | ||
var matrix = [] | ||
var index | ||
var indentation | ||
var stops | ||
var padding | ||
values.unshift(repeat(C_SPACE, maximum) + '!'); | ||
values.unshift(repeat(space, maximum) + exclamationMark) | ||
while (position--) { | ||
indentation = getIndent(values[position]); | ||
indentation = getIndent(values[position]) | ||
matrix[position] = indentation.stops; | ||
matrix[position] = indentation.stops | ||
if (trim(values[position]).length === 0) { | ||
continue; | ||
continue | ||
} | ||
@@ -39,8 +39,8 @@ | ||
if (indentation.indent > 0 && indentation.indent < minIndent) { | ||
minIndent = indentation.indent; | ||
minIndent = indentation.indent | ||
} | ||
} else { | ||
minIndent = Infinity; | ||
minIndent = Infinity | ||
break; | ||
break | ||
} | ||
@@ -50,10 +50,10 @@ } | ||
if (minIndent !== Infinity) { | ||
position = values.length; | ||
position = values.length | ||
while (position--) { | ||
stops = matrix[position]; | ||
index = minIndent; | ||
stops = matrix[position] | ||
index = minIndent | ||
while (index && !(index in stops)) { | ||
index--; | ||
index-- | ||
} | ||
@@ -66,16 +66,15 @@ | ||
) { | ||
padding = C_TAB; | ||
padding = tab | ||
} else { | ||
padding = ''; | ||
padding = '' | ||
} | ||
values[position] = padding + values[position].slice( | ||
index in stops ? stops[index] + 1 : 0 | ||
); | ||
values[position] = | ||
padding + values[position].slice(index in stops ? stops[index] + 1 : 0) | ||
} | ||
} | ||
values.shift(); | ||
values.shift() | ||
return values.join(C_NEWLINE); | ||
return values.join(lineFeed) | ||
} |
{ | ||
"name": "remark-parse", | ||
"version": "5.0.0", | ||
"version": "6.0.0", | ||
"description": "Markdown parser for remark", | ||
@@ -20,3 +20,6 @@ "license": "MIT", | ||
"Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)", | ||
"Eugene Sharygin <eush77@gmail.com>" | ||
"Eugene Sharygin <eush77@gmail.com>", | ||
"Junyoung Choi <fluke8259@gmail.com>", | ||
"Elijah Hamovitz <elijahhamovitz@gmail.com>", | ||
"Ika <ikatyang@gmail.com>" | ||
], | ||
@@ -44,3 +47,11 @@ "files": [ | ||
}, | ||
"devDependencies": { | ||
"tape": "^4.9.1", | ||
"unified": "^7.0.0", | ||
"vfile": "^3.0.0" | ||
}, | ||
"scripts": { | ||
"test": "tape test.js" | ||
}, | ||
"xo": false | ||
} |
@@ -1,2 +0,2 @@ | ||
# remark-parse [![Build Status][build-badge]][build-status] [![Coverage Status][coverage-badge]][coverage-status] [![Chat][chat-badge]][chat] | ||
# remark-parse [![Travis][build-badge]][build-status] [![Coverage][coverage-badge]][coverage-status] [![Downloads][dl-badge]][dl] [![Size][size-badge]][size] [![Chat][chat-badge]][chat] | ||
@@ -19,6 +19,6 @@ [Parser][] for [**unified**][unified]. Parses markdown to an | ||
```js | ||
var unified = require('unified'); | ||
var createStream = require('unified-stream'); | ||
var markdown = require('remark-parse'); | ||
var html = require('remark-html'); | ||
var unified = require('unified') | ||
var createStream = require('unified-stream') | ||
var markdown = require('remark-parse') | ||
var html = require('remark-html') | ||
@@ -29,5 +29,3 @@ var processor = unified() | ||
process.stdin | ||
.pipe(createStream(processor)) | ||
.pipe(process.stdout); | ||
process.stdin.pipe(createStream(processor)).pipe(process.stdout) | ||
``` | ||
@@ -38,5 +36,7 @@ | ||
* [API](#api) | ||
* [processor.use(parse\[, options\])](#processoruseparse-options) | ||
* [parse.Parser](#parseparser) | ||
* [Extending the Parser](#extending-the-parser) | ||
* [Parser#blockTokenizers](#parserblocktokenizers) | ||
@@ -167,14 +167,14 @@ * [Parser#blockMethods](#parserblockmethods) | ||
```js | ||
module.exports = mentions; | ||
module.exports = mentions | ||
function mentions() { | ||
var Parser = this.Parser; | ||
var tokenizers = Parser.prototype.inlineTokenizers; | ||
var methods = Parser.prototype.inlineMethods; | ||
var Parser = this.Parser | ||
var tokenizers = Parser.prototype.inlineTokenizers | ||
var methods = Parser.prototype.inlineMethods | ||
/* Add an inline tokenizer (defined in the following example). */ | ||
tokenizers.mention = tokenizeMention; | ||
// Add an inline tokenizer (defined in the following example). | ||
tokenizers.mention = tokenizeMention | ||
/* Run it just before `text`. */ | ||
methods.splice(methods.indexOf('text'), 0, 'mention'); | ||
// Run it just before `text`. | ||
methods.splice(methods.indexOf('text'), 0, 'mention') | ||
} | ||
@@ -249,11 +249,11 @@ ``` | ||
```js | ||
tokenizeMention.notInLink = true; | ||
tokenizeMention.locator = locateMention; | ||
tokenizeMention.notInLink = true | ||
tokenizeMention.locator = locateMention | ||
function tokenizeMention(eat, value, silent) { | ||
var match = /^@(\w+)/.exec(value); | ||
var match = /^@(\w+)/.exec(value) | ||
if (match) { | ||
if (silent) { | ||
return true; | ||
return true | ||
} | ||
@@ -265,3 +265,3 @@ | ||
children: [{type: 'text', value: match[0]}] | ||
}); | ||
}) | ||
} | ||
@@ -315,3 +315,3 @@ } | ||
function locateMention(value, fromIndex) { | ||
return value.indexOf('@', fromIndex); | ||
return value.indexOf('@', fromIndex) | ||
} | ||
@@ -338,3 +338,3 @@ ``` | ||
```js | ||
var add = eat('foo'); | ||
var add = eat('foo') | ||
``` | ||
@@ -357,4 +357,5 @@ | ||
```js | ||
var add = eat('foo'); | ||
add({type: 'text', value: 'foo'}); | ||
var add = eat('foo') | ||
add({type: 'text', value: 'foo'}) | ||
``` | ||
@@ -402,3 +403,3 @@ | ||
In rare situations, you may want to turn off a tokenizer to avoid parsing | ||
that syntactic feature. This can be done by deleting the tokenizer from | ||
that syntactic feature. This can be done by replacing the tokenizer from | ||
your Parser’s `blockTokenizers` (or `blockMethods`) or `inlineTokenizers` | ||
@@ -410,5 +411,11 @@ (or `inlineMethods`). | ||
```js | ||
delete remarkParse.Parser.prototype.blockTokenizers.indentedCode; | ||
remarkParse.Parser.prototype.blockTokenizers.indentedCode = indentedCode | ||
function indentedCode() { | ||
return true | ||
} | ||
``` | ||
Preferably, just use [this plugin](https://github.com/zestedesavoir/zmarkdown/tree/master/packages/remark-disable-tokenizers). | ||
## License | ||
@@ -428,2 +435,10 @@ | ||
[dl-badge]: https://img.shields.io/npm/dm/remark-parse.svg | ||
[dl]: https://www.npmjs.com/package/remark-parse | ||
[size-badge]: https://img.shields.io/bundlephobia/minzip/remark-parse.svg | ||
[size]: https://bundlephobia.com/result?p=remark-parse | ||
[chat-badge]: https://img.shields.io/gitter/room/remarkjs/Lobby.svg | ||
@@ -433,3 +448,3 @@ | ||
[license]: https://github.com/remarkjs/remark/blob/master/LICENSE | ||
[license]: https://github.com/remarkjs/remark/blob/master/license | ||
@@ -444,3 +459,3 @@ [author]: http://wooorm.com | ||
[processor]: https://github.com/unifiedjs/remark/blob/master/packages/remark | ||
[processor]: https://github.com/remarkjs/remark/blob/master/packages/remark | ||
@@ -447,0 +462,0 @@ [mdast]: https://github.com/syntax-tree/mdast |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
0
469
107004
3
3747
1