Comparing version 1.0.0-beta.4 to 1.0.0-beta.5
@@ -1,2 +0,11 @@ | ||
import { RulesBlockBase, MarkedOptions, Token, Links, LexerReturns, RulesBlockGfm, RulesBlockTables } from './interfaces'; | ||
/** | ||
* @license | ||
* | ||
* Copyright (c) 2011-2014, Christopher Jeffrey. (MIT Licensed) | ||
* https://github.com/chjj/marked | ||
* | ||
* Copyright (c) 2018, Костя Третяк. (MIT Licensed) | ||
* https://github.com/KostyaTretyak/marked-ts | ||
*/ | ||
import { LexerReturns, Links, MarkedOptions, RulesBlockBase, RulesBlockGfm, RulesBlockTables, Token } from './interfaces'; | ||
export declare class BlockLexer<T extends typeof BlockLexer> { | ||
@@ -3,0 +12,0 @@ protected staticThis: typeof BlockLexer; |
@@ -20,5 +20,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var marked_1 = require("./marked"); | ||
var extend_regexp_1 = require("./extend-regexp"); | ||
var interfaces_1 = require("./interfaces"); | ||
var marked_1 = require("./marked"); | ||
var BlockLexer = /** @class */ (function () { | ||
@@ -43,4 +43,5 @@ function BlockLexer(staticThis, options) { | ||
BlockLexer.getRulesBase = function () { | ||
if (this.rulesBase) | ||
if (this.rulesBase) { | ||
return this.rulesBase; | ||
} | ||
var base = { | ||
@@ -61,5 +62,3 @@ newline: /^\n+/, | ||
}; | ||
base.item = new extend_regexp_1.ExtendRegexp(base.item, 'gm') | ||
.setGroup(/bull/g, base.bullet) | ||
.getRegexp(); | ||
base.item = new extend_regexp_1.ExtendRegexp(base.item, 'gm').setGroup(/bull/g, base.bullet).getRegexp(); | ||
base.list = new extend_regexp_1.ExtendRegexp(base.list) | ||
@@ -70,6 +69,6 @@ .setGroup(/bull/g, base.bullet) | ||
.getRegexp(); | ||
var tag = '(?!(?:' | ||
+ 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code' | ||
+ '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo' | ||
+ '|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b'; | ||
var tag = '(?!(?:' + | ||
'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code' + | ||
'|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo' + | ||
'|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b'; | ||
base.html = new extend_regexp_1.ExtendRegexp(base.html) | ||
@@ -89,7 +88,8 @@ .setGroup('comment', /<!--[\s\S]*?-->/) | ||
.getRegexp(); | ||
return this.rulesBase = base; | ||
return (this.rulesBase = base); | ||
}; | ||
BlockLexer.getRulesGfm = function () { | ||
if (this.rulesGfm) | ||
if (this.rulesGfm) { | ||
return this.rulesGfm; | ||
} | ||
var base = this.getRulesBase(); | ||
@@ -103,14 +103,13 @@ var gfm = __assign({}, base, { | ||
var group2 = base.list.source.replace('\\1', '\\3'); | ||
gfm.paragraph = new extend_regexp_1.ExtendRegexp(base.paragraph) | ||
.setGroup('(?!', "(?!" + group1 + "|" + group2 + "|") | ||
.getRegexp(); | ||
return this.rulesGfm = gfm; | ||
gfm.paragraph = new extend_regexp_1.ExtendRegexp(base.paragraph).setGroup('(?!', "(?!" + group1 + "|" + group2 + "|").getRegexp(); | ||
return (this.rulesGfm = gfm); | ||
}; | ||
BlockLexer.getRulesTable = function () { | ||
if (this.rulesTables) | ||
if (this.rulesTables) { | ||
return this.rulesTables; | ||
return this.rulesTables = __assign({}, this.getRulesGfm(), { | ||
} | ||
return (this.rulesTables = __assign({}, this.getRulesGfm(), { | ||
nptable: /^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/, | ||
table: /^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/ | ||
}); | ||
})); | ||
}; | ||
@@ -140,3 +139,3 @@ BlockLexer.prototype.setRules = function () { | ||
// newline | ||
if (execArr = this.rules.newline.exec(nextPart)) { | ||
if ((execArr = this.rules.newline.exec(nextPart))) { | ||
nextPart = nextPart.substring(execArr[0].length); | ||
@@ -148,3 +147,3 @@ if (execArr[0].length > 1) { | ||
// code | ||
if (execArr = this.rules.code.exec(nextPart)) { | ||
if ((execArr = this.rules.code.exec(nextPart))) { | ||
nextPart = nextPart.substring(execArr[0].length); | ||
@@ -159,4 +158,3 @@ var code = execArr[0].replace(/^ {4}/gm, ''); | ||
// fences code (gfm) | ||
if (this.hasRulesGfm | ||
&& (execArr = this.rules.fences.exec(nextPart))) { | ||
if (this.hasRulesGfm && (execArr = this.rules.fences.exec(nextPart))) { | ||
nextPart = nextPart.substring(execArr[0].length); | ||
@@ -171,3 +169,3 @@ this.tokens.push({ | ||
// heading | ||
if (execArr = this.rules.heading.exec(nextPart)) { | ||
if ((execArr = this.rules.heading.exec(nextPart))) { | ||
nextPart = nextPart.substring(execArr[0].length); | ||
@@ -182,5 +180,3 @@ this.tokens.push({ | ||
// table no leading pipe (gfm) | ||
if (top | ||
&& this.hasRulesTables | ||
&& (execArr = this.rules.nptable.exec(nextPart))) { | ||
if (top && this.hasRulesTables && (execArr = this.rules.nptable.exec(nextPart))) { | ||
nextPart = nextPart.substring(execArr[0].length); | ||
@@ -215,3 +211,3 @@ var item = { | ||
// lheading | ||
if (execArr = this.rules.lheading.exec(nextPart)) { | ||
if ((execArr = this.rules.lheading.exec(nextPart))) { | ||
nextPart = nextPart.substring(execArr[0].length); | ||
@@ -226,3 +222,3 @@ this.tokens.push({ | ||
// hr | ||
if (execArr = this.rules.hr.exec(nextPart)) { | ||
if ((execArr = this.rules.hr.exec(nextPart))) { | ||
nextPart = nextPart.substring(execArr[0].length); | ||
@@ -233,3 +229,3 @@ this.tokens.push({ type: interfaces_1.TokenType.hr }); | ||
// blockquote | ||
if (execArr = this.rules.blockquote.exec(nextPart)) { | ||
if ((execArr = this.rules.blockquote.exec(nextPart))) { | ||
nextPart = nextPart.substring(execArr[0].length); | ||
@@ -246,3 +242,3 @@ this.tokens.push({ type: interfaces_1.TokenType.blockquoteStart }); | ||
// list | ||
if (execArr = this.rules.list.exec(nextPart)) { | ||
if ((execArr = this.rules.list.exec(nextPart))) { | ||
nextPart = nextPart.substring(execArr[0].length); | ||
@@ -254,3 +250,6 @@ var bull = execArr[2]; | ||
var length_1 = str.length; | ||
var next = false, space = void 0, blockBullet = void 0, loose = void 0; | ||
var next = false; | ||
var space = void 0; | ||
var blockBullet = void 0; | ||
var loose = void 0; | ||
for (var i = 0; i < length_1; i++) { | ||
@@ -283,4 +282,5 @@ var item = str[i]; | ||
next = item.charAt(item.length - 1) === '\n'; | ||
if (!loose) | ||
if (!loose) { | ||
loose = next; | ||
} | ||
} | ||
@@ -296,6 +296,6 @@ this.tokens.push({ type: loose ? interfaces_1.TokenType.looseItemStart : interfaces_1.TokenType.listItemStart }); | ||
// html | ||
if (execArr = this.rules.html.exec(nextPart)) { | ||
if ((execArr = this.rules.html.exec(nextPart))) { | ||
nextPart = nextPart.substring(execArr[0].length); | ||
var attr = execArr[1]; | ||
var isPre = (attr === 'pre' || attr === 'script' || attr === 'style'); | ||
var isPre = attr === 'pre' || attr === 'script' || attr === 'style'; | ||
this.tokens.push({ | ||
@@ -311,13 +311,10 @@ type: this.options.sanitize ? interfaces_1.TokenType.paragraph : interfaces_1.TokenType.html, | ||
nextPart = nextPart.substring(execArr[0].length); | ||
this.links[execArr[1].toLowerCase()] = | ||
{ | ||
href: execArr[2], | ||
title: execArr[3] | ||
}; | ||
this.links[execArr[1].toLowerCase()] = { | ||
href: execArr[2], | ||
title: execArr[3] | ||
}; | ||
continue; | ||
} | ||
// table (gfm) | ||
if (top | ||
&& this.hasRulesTables | ||
&& (execArr = this.rules.table.exec(nextPart))) { | ||
if (top && this.hasRulesTables && (execArr = this.rules.table.exec(nextPart))) { | ||
nextPart = nextPart.substring(execArr[0].length); | ||
@@ -346,5 +343,3 @@ var item = { | ||
for (var i = 0; i < td.length; i++) { | ||
item.cells[i] = td[i] | ||
.replace(/^ *\| *| *\| *$/g, '') | ||
.split(/ *\| */); | ||
item.cells[i] = td[i].replace(/^ *\| *| *\| *$/g, '').split(/ *\| */); | ||
} | ||
@@ -358,3 +353,3 @@ this.tokens.push(item); | ||
for (var i = 0; i < simpleRules.length; i++) { | ||
if (execArr = simpleRules[i].exec(nextPart)) { | ||
if ((execArr = simpleRules[i].exec(nextPart))) { | ||
nextPart = nextPart.substring(execArr[0].length); | ||
@@ -373,3 +368,3 @@ var type = 'simpleRule' + (i + 1); | ||
type: interfaces_1.TokenType.paragraph, | ||
text: execArr[1].slice(0, -1), | ||
text: execArr[1].slice(0, -1) | ||
}); | ||
@@ -380,3 +375,3 @@ } | ||
type: this.tokens.length > 0 ? interfaces_1.TokenType.paragraph : interfaces_1.TokenType.text, | ||
text: execArr[1], | ||
text: execArr[1] | ||
}); | ||
@@ -388,3 +383,3 @@ } | ||
// Top-level should never reach here. | ||
if (execArr = this.rules.text.exec(nextPart)) { | ||
if ((execArr = this.rules.text.exec(nextPart))) { | ||
nextPart = nextPart.substring(execArr[0].length); | ||
@@ -391,0 +386,0 @@ this.tokens.push({ type: interfaces_1.TokenType.text, text: execArr[0] }); |
"use strict"; | ||
/** | ||
/* | ||
* @license | ||
@@ -4,0 +4,0 @@ * |
@@ -10,5 +10,3 @@ /** | ||
*/ | ||
import { Obj } from './interfaces'; | ||
export declare function merge(obj: Obj, ...args: Obj[]): Obj; | ||
export declare function escape(html: string, encode?: boolean): string; | ||
export declare function unescape(html: string): string; |
@@ -12,16 +12,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function merge(obj) { | ||
var args = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
args[_i - 1] = arguments[_i]; | ||
} | ||
for (var i = 0; i < args.length; i++) { | ||
var target = args[i]; | ||
for (var key in target) { | ||
obj[key] = target[key]; | ||
} | ||
} | ||
return obj; | ||
} | ||
exports.merge = merge; | ||
var escapeTest = /[&<>"']/; | ||
@@ -34,2 +20,3 @@ var escapeReplace = /[&<>"']/g; | ||
'"': '"', | ||
// tslint:disable-next-line:quotemark | ||
"'": ''' | ||
@@ -54,7 +41,8 @@ }; | ||
function unescape(html) { | ||
// Explicitly match decimal, hex, and named HTML entities | ||
// Explicitly match decimal, hex, and named HTML entities | ||
return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi, function (_, n) { | ||
n = n.toLowerCase(); | ||
if (n === 'colon') | ||
if (n === 'colon') { | ||
return ':'; | ||
} | ||
if (n.charAt(0) === '#') { | ||
@@ -61,0 +49,0 @@ return n.charAt(1) === 'x' |
@@ -0,3 +1,12 @@ | ||
/** | ||
* @license | ||
* | ||
* Copyright (c) 2011-2014, Christopher Jeffrey. (MIT Licensed) | ||
* https://github.com/chjj/marked | ||
* | ||
* Copyright (c) 2018, Костя Третяк. (MIT Licensed) | ||
* https://github.com/KostyaTretyak/marked-ts | ||
*/ | ||
import { Link, Links, MarkedOptions, RulesInlineBase, RulesInlineBreaks, RulesInlineCallback, RulesInlineGfm, RulesInlinePedantic } from './interfaces'; | ||
import { Renderer } from './renderer'; | ||
import { RulesInlineBase, MarkedOptions, Links, Link, RulesInlineGfm, RulesInlineBreaks, RulesInlinePedantic, RulesInlineCallback } from './interfaces'; | ||
/** | ||
@@ -4,0 +13,0 @@ * Inline Lexer & Compiler. |
@@ -33,4 +33,5 @@ "use strict"; | ||
this.renderer = renderer || this.options.renderer || new renderer_1.Renderer(this.options); | ||
if (!this.links) | ||
if (!this.links) { | ||
throw new Error("InlineLexer requires 'links' parameter."); | ||
} | ||
this.setRules(); | ||
@@ -46,4 +47,5 @@ } | ||
InlineLexer.getRulesBase = function () { | ||
if (this.rulesBase) | ||
if (this.rulesBase) { | ||
return this.rulesBase; | ||
} | ||
/** | ||
@@ -65,3 +67,3 @@ * Inline-Level Grammar. | ||
_inside: /(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/, | ||
_href: /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/, | ||
_href: /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/ | ||
}; | ||
@@ -72,22 +74,20 @@ base.link = new extend_regexp_1.ExtendRegexp(base.link) | ||
.getRegexp(); | ||
base.reflink = new extend_regexp_1.ExtendRegexp(base.reflink) | ||
.setGroup('inside', base._inside) | ||
.getRegexp(); | ||
return this.rulesBase = base; | ||
base.reflink = new extend_regexp_1.ExtendRegexp(base.reflink).setGroup('inside', base._inside).getRegexp(); | ||
return (this.rulesBase = base); | ||
}; | ||
InlineLexer.getRulesPedantic = function () { | ||
if (this.rulesPedantic) | ||
if (this.rulesPedantic) { | ||
return this.rulesPedantic; | ||
return this.rulesPedantic = __assign({}, this.getRulesBase(), { | ||
} | ||
return (this.rulesPedantic = __assign({}, this.getRulesBase(), { | ||
strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/, | ||
em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/ | ||
}); | ||
})); | ||
}; | ||
InlineLexer.getRulesGfm = function () { | ||
if (this.rulesGfm) | ||
if (this.rulesGfm) { | ||
return this.rulesGfm; | ||
} | ||
var base = this.getRulesBase(); | ||
var escape = new extend_regexp_1.ExtendRegexp(base.escape) | ||
.setGroup('])', '~|])') | ||
.getRegexp(); | ||
var escape = new extend_regexp_1.ExtendRegexp(base.escape).setGroup('])', '~|])').getRegexp(); | ||
var text = new extend_regexp_1.ExtendRegexp(base.text) | ||
@@ -97,3 +97,3 @@ .setGroup(']|', '~]|') | ||
.getRegexp(); | ||
return this.rulesGfm = __assign({}, base, { | ||
return (this.rulesGfm = __assign({}, base, { | ||
escape: escape, | ||
@@ -103,13 +103,14 @@ url: /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/, | ||
text: text | ||
}); | ||
})); | ||
}; | ||
InlineLexer.getRulesBreaks = function () { | ||
if (this.rulesBreaks) | ||
if (this.rulesBreaks) { | ||
return this.rulesBreaks; | ||
} | ||
var inline = this.getRulesGfm(); | ||
var gfm = this.getRulesGfm(); | ||
return this.rulesBreaks = __assign({}, gfm, { | ||
return (this.rulesBreaks = __assign({}, gfm, { | ||
br: new extend_regexp_1.ExtendRegexp(inline.br).setGroup('{2,}', '*').getRegexp(), | ||
text: new extend_regexp_1.ExtendRegexp(gfm.text).setGroup('{2,}', '*').getRegexp() | ||
}); | ||
})); | ||
}; | ||
@@ -142,3 +143,3 @@ InlineLexer.prototype.setRules = function () { | ||
// escape | ||
if (execArr = this.rules.escape.exec(nextPart)) { | ||
if ((execArr = this.rules.escape.exec(nextPart))) { | ||
nextPart = nextPart.substring(execArr[0].length); | ||
@@ -149,9 +150,8 @@ out += execArr[1]; | ||
// autolink | ||
if (execArr = this.rules.autolink.exec(nextPart)) { | ||
var text = void 0, href = void 0; | ||
if ((execArr = this.rules.autolink.exec(nextPart))) { | ||
var text = void 0; | ||
var href = void 0; | ||
nextPart = nextPart.substring(execArr[0].length); | ||
if (execArr[2] === '@') { | ||
text = this.options.escape(execArr[1].charAt(6) === ':' | ||
? this.mangle(execArr[1].substring(7)) | ||
: this.mangle(execArr[1])); | ||
text = this.options.escape(execArr[1].charAt(6) === ':' ? this.mangle(execArr[1].substring(7)) : this.mangle(execArr[1])); | ||
href = this.mangle('mailto:') + text; | ||
@@ -167,6 +167,5 @@ } | ||
// url (gfm) | ||
if (!this.inLink | ||
&& this.hasRulesGfm | ||
&& (execArr = this.rules.url.exec(nextPart))) { | ||
var text = void 0, href = void 0; | ||
if (!this.inLink && this.hasRulesGfm && (execArr = this.rules.url.exec(nextPart))) { | ||
var text = void 0; | ||
var href = void 0; | ||
nextPart = nextPart.substring(execArr[0].length); | ||
@@ -179,3 +178,3 @@ text = this.options.escape(execArr[1]); | ||
// tag | ||
if (execArr = this.rules.tag.exec(nextPart)) { | ||
if ((execArr = this.rules.tag.exec(nextPart))) { | ||
if (!this.inLink && /^<a /i.test(execArr[0])) { | ||
@@ -196,3 +195,3 @@ this.inLink = true; | ||
// link | ||
if (execArr = this.rules.link.exec(nextPart)) { | ||
if ((execArr = this.rules.link.exec(nextPart))) { | ||
nextPart = nextPart.substring(execArr[0].length); | ||
@@ -208,4 +207,3 @@ this.inLink = true; | ||
// reflink, nolink | ||
if ((execArr = this.rules.reflink.exec(nextPart)) | ||
|| (execArr = this.rules.nolink.exec(nextPart))) { | ||
if ((execArr = this.rules.reflink.exec(nextPart)) || (execArr = this.rules.nolink.exec(nextPart))) { | ||
nextPart = nextPart.substring(execArr[0].length); | ||
@@ -225,3 +223,3 @@ var keyLink = (execArr[2] || execArr[1]).replace(/\s+/g, ' '); | ||
// strong | ||
if (execArr = this.rules.strong.exec(nextPart)) { | ||
if ((execArr = this.rules.strong.exec(nextPart))) { | ||
nextPart = nextPart.substring(execArr[0].length); | ||
@@ -232,3 +230,3 @@ out += this.renderer.strong(this.output(execArr[2] || execArr[1])); | ||
// em | ||
if (execArr = this.rules.em.exec(nextPart)) { | ||
if ((execArr = this.rules.em.exec(nextPart))) { | ||
nextPart = nextPart.substring(execArr[0].length); | ||
@@ -239,3 +237,3 @@ out += this.renderer.em(this.output(execArr[2] || execArr[1])); | ||
// code | ||
if (execArr = this.rules.code.exec(nextPart)) { | ||
if ((execArr = this.rules.code.exec(nextPart))) { | ||
nextPart = nextPart.substring(execArr[0].length); | ||
@@ -246,3 +244,3 @@ out += this.renderer.codespan(this.options.escape(execArr[2].trim(), true)); | ||
// br | ||
if (execArr = this.rules.br.exec(nextPart)) { | ||
if ((execArr = this.rules.br.exec(nextPart))) { | ||
nextPart = nextPart.substring(execArr[0].length); | ||
@@ -253,4 +251,3 @@ out += this.renderer.br(); | ||
// del (gfm) | ||
if (this.hasRulesGfm | ||
&& (execArr = this.rules.del.exec(nextPart))) { | ||
if (this.hasRulesGfm && (execArr = this.rules.del.exec(nextPart))) { | ||
nextPart = nextPart.substring(execArr[0].length); | ||
@@ -261,3 +258,3 @@ out += this.renderer.del(this.output(execArr[1])); | ||
// text | ||
if (execArr = this.rules.text.exec(nextPart)) { | ||
if ((execArr = this.rules.text.exec(nextPart))) { | ||
nextPart = nextPart.substring(execArr[0].length); | ||
@@ -267,4 +264,5 @@ out += this.renderer.text(this.options.escape(this.smartypants(execArr[0]))); | ||
} | ||
if (nextPart) | ||
if (nextPart) { | ||
throw new Error('Infinite loop on byte: ' + nextPart.charCodeAt(0)); | ||
} | ||
} | ||
@@ -287,12 +285,20 @@ return out; | ||
InlineLexer.prototype.smartypants = function (text) { | ||
if (!this.options.smartypants) | ||
if (!this.options.smartypants) { | ||
return text; | ||
return text | ||
} | ||
return (text | ||
// em-dashes | ||
.replace(/---/g, '\u2014') | ||
// en-dashes | ||
.replace(/--/g, '\u2013') | ||
// opening singles | ||
.replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018') | ||
// closing singles & apostrophes | ||
.replace(/'/g, '\u2019') | ||
// opening doubles | ||
.replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c') | ||
// closing doubles | ||
.replace(/"/g, '\u201d') | ||
.replace(/\.{3}/g, '\u2026'); | ||
// ellipses | ||
.replace(/\.{3}/g, '\u2026')); | ||
}; | ||
@@ -303,5 +309,7 @@ /** | ||
InlineLexer.prototype.mangle = function (text) { | ||
if (!this.options.mangle) | ||
if (!this.options.mangle) { | ||
return text; | ||
var out = '', length = text.length; | ||
} | ||
var out = ''; | ||
var length = text.length; | ||
for (var i = 0; i < length; i++) { | ||
@@ -308,0 +316,0 @@ var str = void 0; |
@@ -8,5 +8,5 @@ /** | ||
import { Renderer } from './renderer'; | ||
export declare type Obj = { | ||
export interface Obj { | ||
[key: string]: any; | ||
}; | ||
} | ||
export interface RulesBlockBase { | ||
@@ -60,3 +60,3 @@ newline: RegExp; | ||
html = 15, | ||
hr = 16, | ||
hr = 16 | ||
} | ||
@@ -169,6 +169,6 @@ export declare type Align = 'center' | 'left' | 'right'; | ||
export interface RulesInlineCallback { | ||
regexp?: RegExp; | ||
condition(): RegExp; | ||
tokenize(execArr: RegExpExecArray): void; | ||
regexp?: RegExp; | ||
} | ||
export declare type SimpleRenderer = (execArr?: RegExpExecArray) => string; |
@@ -1,2 +0,11 @@ | ||
import { MarkedOptions, Token, Links, LexerReturns, SimpleRenderer, DebugReturns } from './interfaces'; | ||
/** | ||
* @license | ||
* | ||
* Copyright (c) 2011-2014, Christopher Jeffrey. (MIT Licensed) | ||
* https://github.com/chjj/marked | ||
* | ||
* Copyright (c) 2018, Костя Третяк. (MIT Licensed) | ||
* https://github.com/KostyaTretyak/marked-ts | ||
*/ | ||
import { DebugReturns, LexerReturns, Links, MarkedOptions, SimpleRenderer, Token } from './interfaces'; | ||
export declare class Marked { | ||
@@ -3,0 +12,0 @@ static options: MarkedOptions; |
@@ -20,6 +20,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var parser_1 = require("./parser"); | ||
var block_lexer_1 = require("./block-lexer"); | ||
var helpers_1 = require("./helpers"); | ||
var interfaces_1 = require("./interfaces"); | ||
var parser_1 = require("./parser"); | ||
var Marked = /** @class */ (function () { | ||
@@ -34,3 +33,3 @@ function Marked() { | ||
Marked.setOptions = function (options) { | ||
this.options = helpers_1.merge(this.options, options); | ||
Object.assign(this.options, options); | ||
return this; | ||
@@ -87,6 +86,8 @@ }; | ||
delete token.line; | ||
if (line) | ||
if (line) { | ||
return __assign({ line: line }, token); | ||
else | ||
} | ||
else { | ||
return token; | ||
} | ||
}); | ||
@@ -97,2 +98,5 @@ return { tokens: origin, links: links, result: result }; | ||
if (src === void 0) { src = ''; } | ||
if (typeof src != 'string') { | ||
throw new Error("Expected that the 'src' parameter would have a 'string' type, got '" + typeof src + "'"); | ||
} | ||
// Preprocessing. | ||
@@ -124,3 +128,3 @@ src = src | ||
}; | ||
Marked.options = new interfaces_1.MarkedOptions; | ||
Marked.options = new interfaces_1.MarkedOptions(); | ||
Marked.simpleRenderers = []; | ||
@@ -127,0 +131,0 @@ return Marked; |
@@ -0,4 +1,13 @@ | ||
/** | ||
* @license | ||
* | ||
* Copyright (c) 2011-2014, Christopher Jeffrey. (MIT Licensed) | ||
* https://github.com/chjj/marked | ||
* | ||
* Copyright (c) 2018, Костя Третяк. (MIT Licensed) | ||
* https://github.com/KostyaTretyak/marked-ts | ||
*/ | ||
import { InlineLexer } from './inline-lexer'; | ||
import { Links, MarkedOptions, SimpleRenderer, Token } from './interfaces'; | ||
import { Renderer } from './renderer'; | ||
import { InlineLexer } from './inline-lexer'; | ||
import { MarkedOptions, Token, Links, SimpleRenderer } from './interfaces'; | ||
/** | ||
@@ -5,0 +14,0 @@ * Parsing & Compiling. |
@@ -12,6 +12,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var inline_lexer_1 = require("./inline-lexer"); | ||
var interfaces_1 = require("./interfaces"); | ||
var marked_1 = require("./marked"); | ||
var renderer_1 = require("./renderer"); | ||
var inline_lexer_1 = require("./inline-lexer"); | ||
var interfaces_1 = require("./interfaces"); | ||
/** | ||
@@ -54,3 +54,3 @@ * Parsing & Compiling. | ||
Parser.prototype.next = function () { | ||
return this.token = this.tokens.pop(); | ||
return (this.token = this.tokens.pop()); | ||
}; | ||
@@ -70,107 +70,99 @@ Parser.prototype.getNextElement = function () { | ||
switch (this.token.type) { | ||
case interfaces_1.TokenType.space: | ||
{ | ||
return ''; | ||
case interfaces_1.TokenType.space: { | ||
return ''; | ||
} | ||
case interfaces_1.TokenType.paragraph: { | ||
return this.renderer.paragraph(this.inlineLexer.output(this.token.text)); | ||
} | ||
case interfaces_1.TokenType.text: { | ||
if (this.options.isNoP) { | ||
return this.parseText(); | ||
} | ||
case interfaces_1.TokenType.paragraph: | ||
{ | ||
return this.renderer.paragraph(this.inlineLexer.output(this.token.text)); | ||
else { | ||
return this.renderer.paragraph(this.parseText()); | ||
} | ||
case interfaces_1.TokenType.text: | ||
{ | ||
if (this.options.isNoP) | ||
return this.parseText(); | ||
else | ||
return this.renderer.paragraph(this.parseText()); | ||
} | ||
case interfaces_1.TokenType.heading: { | ||
return this.renderer.heading(this.inlineLexer.output(this.token.text), this.token.depth, this.token.text); | ||
} | ||
case interfaces_1.TokenType.listStart: { | ||
var body = ''; | ||
var ordered = this.token.ordered; | ||
while (this.next().type != interfaces_1.TokenType.listEnd) { | ||
body += this.tok(); | ||
} | ||
case interfaces_1.TokenType.heading: | ||
{ | ||
return this.renderer.heading(this.inlineLexer.output(this.token.text), this.token.depth, this.token.text); | ||
return this.renderer.list(body, ordered); | ||
} | ||
case interfaces_1.TokenType.listItemStart: { | ||
var body = ''; | ||
while (this.next().type != interfaces_1.TokenType.listItemEnd) { | ||
body += this.token.type == interfaces_1.TokenType.text ? this.parseText() : this.tok(); | ||
} | ||
case interfaces_1.TokenType.listStart: | ||
{ | ||
var body = '', ordered = this.token.ordered; | ||
while (this.next().type != interfaces_1.TokenType.listEnd) { | ||
body += this.tok(); | ||
} | ||
return this.renderer.list(body, ordered); | ||
return this.renderer.listitem(body); | ||
} | ||
case interfaces_1.TokenType.looseItemStart: { | ||
var body = ''; | ||
while (this.next().type != interfaces_1.TokenType.listItemEnd) { | ||
body += this.tok(); | ||
} | ||
case interfaces_1.TokenType.listItemStart: | ||
{ | ||
var body = ''; | ||
while (this.next().type != interfaces_1.TokenType.listItemEnd) { | ||
body += this.token.type == interfaces_1.TokenType.text | ||
? this.parseText() | ||
: this.tok(); | ||
} | ||
return this.renderer.listitem(body); | ||
return this.renderer.listitem(body); | ||
} | ||
case interfaces_1.TokenType.code: { | ||
return this.renderer.code(this.token.text, this.token.lang, this.token.escaped); | ||
} | ||
case interfaces_1.TokenType.table: { | ||
var header = ''; | ||
var body = ''; | ||
var cell = void 0; | ||
// header | ||
cell = ''; | ||
for (var i = 0; i < this.token.header.length; i++) { | ||
var flags = { header: true, align: this.token.align[i] }; | ||
var out = this.inlineLexer.output(this.token.header[i]); | ||
cell += this.renderer.tablecell(out, flags); | ||
} | ||
case interfaces_1.TokenType.looseItemStart: | ||
{ | ||
var body = ''; | ||
while (this.next().type != interfaces_1.TokenType.listItemEnd) { | ||
body += this.tok(); | ||
header += this.renderer.tablerow(cell); | ||
for (var _i = 0, _a = this.token.cells; _i < _a.length; _i++) { | ||
var row = _a[_i]; | ||
cell = ''; | ||
for (var j = 0; j < row.length; j++) { | ||
cell += this.renderer.tablecell(this.inlineLexer.output(row[j]), { | ||
header: false, | ||
align: this.token.align[j] | ||
}); | ||
} | ||
return this.renderer.listitem(body); | ||
body += this.renderer.tablerow(cell); | ||
} | ||
case interfaces_1.TokenType.code: | ||
{ | ||
return this.renderer.code(this.token.text, this.token.lang, this.token.escaped); | ||
return this.renderer.table(header, body); | ||
} | ||
case interfaces_1.TokenType.blockquoteStart: { | ||
var body = ''; | ||
while (this.next().type != interfaces_1.TokenType.blockquoteEnd) { | ||
body += this.tok(); | ||
} | ||
case interfaces_1.TokenType.table: | ||
{ | ||
var header = '', body = '', row = void 0, cell = void 0; | ||
// header | ||
cell = ''; | ||
for (var i = 0; i < this.token.header.length; i++) { | ||
var flags = { header: true, align: this.token.align[i] }; | ||
var out = this.inlineLexer.output(this.token.header[i]); | ||
cell += this.renderer.tablecell(out, flags); | ||
} | ||
header += this.renderer.tablerow(cell); | ||
for (var i = 0; i < this.token.cells.length; i++) { | ||
row = this.token.cells[i]; | ||
cell = ''; | ||
for (var j = 0; j < row.length; j++) { | ||
cell += this.renderer.tablecell(this.inlineLexer.output(row[j]), { header: false, align: this.token.align[j] }); | ||
return this.renderer.blockquote(body); | ||
} | ||
case interfaces_1.TokenType.hr: { | ||
return this.renderer.hr(); | ||
} | ||
case interfaces_1.TokenType.html: { | ||
var html = !this.token.pre && !this.options.pedantic ? this.inlineLexer.output(this.token.text) : this.token.text; | ||
return this.renderer.html(html); | ||
} | ||
default: { | ||
if (this.simpleRenderers.length) { | ||
for (var i = 0; i < this.simpleRenderers.length; i++) { | ||
if (this.token.type == 'simpleRule' + (i + 1)) { | ||
return this.simpleRenderers[i].call(this.renderer, this.token.execArr); | ||
} | ||
body += this.renderer.tablerow(cell); | ||
} | ||
return this.renderer.table(header, body); | ||
} | ||
case interfaces_1.TokenType.blockquoteStart: | ||
{ | ||
var body = ''; | ||
while (this.next().type != interfaces_1.TokenType.blockquoteEnd) { | ||
body += this.tok(); | ||
} | ||
return this.renderer.blockquote(body); | ||
var errMsg = "Token with \"" + this.token.type + "\" type was not found."; | ||
if (this.options.silent) { | ||
console.log(errMsg); | ||
} | ||
case interfaces_1.TokenType.hr: | ||
{ | ||
return this.renderer.hr(); | ||
else { | ||
throw new Error(errMsg); | ||
} | ||
case interfaces_1.TokenType.html: | ||
{ | ||
var html = !this.token.pre && !this.options.pedantic | ||
? this.inlineLexer.output(this.token.text) | ||
: this.token.text; | ||
return this.renderer.html(html); | ||
} | ||
default: | ||
{ | ||
if (this.simpleRenderers.length) | ||
for (var i = 0; i < this.simpleRenderers.length; i++) { | ||
if (this.token.type == ('simpleRule' + (i + 1))) { | ||
return this.simpleRenderers[i].call(this.renderer, this.token.execArr); | ||
} | ||
} | ||
var errMsg = "Token with \"" + this.token.type + "\" type was not found."; | ||
if (this.options.silent) { | ||
console.log(errMsg); | ||
} | ||
else { | ||
throw new Error(errMsg); | ||
} | ||
} | ||
} | ||
} | ||
@@ -177,0 +169,0 @@ }; |
@@ -10,3 +10,3 @@ /** | ||
*/ | ||
import { MarkedOptions, Align } from './interfaces'; | ||
import { Align, MarkedOptions } from './interfaces'; | ||
export declare class Renderer { | ||
@@ -13,0 +13,0 @@ protected options: MarkedOptions; |
@@ -28,5 +28,8 @@ "use strict"; | ||
} | ||
return '\n<pre><code class="' + this.options.langPrefix + this.options.escape(lang, true) + '">' | ||
+ (escaped ? code : this.options.escape(code, true)) | ||
+ '\n</code></pre>\n'; | ||
return ('\n<pre><code class="' + | ||
this.options.langPrefix + | ||
this.options.escape(lang, true) + | ||
'">' + | ||
(escaped ? code : this.options.escape(code, true)) + | ||
'\n</code></pre>\n'); | ||
}; | ||
@@ -64,8 +67,6 @@ Renderer.prototype.blockquote = function (quote) { | ||
var type = flags.header ? 'th' : 'td'; | ||
var tag = flags.align | ||
? '<' + type + ' style="text-align:' + flags.align + '">' | ||
: '<' + type + '>'; | ||
var tag = flags.align ? '<' + type + ' style="text-align:' + flags.align + '">' : '<' + type + '>'; | ||
return tag + content + '</' + type + '>\n'; | ||
}; | ||
//*** Inline level renderer methods. *** | ||
// *** Inline level renderer methods. *** | ||
Renderer.prototype.strong = function (text) { | ||
@@ -97,5 +98,3 @@ return '<strong>' + text + '</strong>'; | ||
} | ||
if (prot.indexOf('javascript:') === 0 | ||
|| prot.indexOf('vbscript:') === 0 | ||
|| prot.indexOf('data:') === 0) { | ||
if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) { | ||
return text; | ||
@@ -102,0 +101,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"author": "Костя Третяк <ktretiak.in.ua@gmail.com>", | ||
"version": "1.0.0-beta.4", | ||
"version": "1.0.0-beta.5", | ||
"main": "dist/index", | ||
@@ -45,9 +45,15 @@ "typings": "dist/index", | ||
"marked": "^0.3.12", | ||
"prettier": "^1.16.4", | ||
"remarkable": "^1.7.1", | ||
"rimraf": "^2.6.3", | ||
"showdown": "^1.8.6", | ||
"tslint": "^5.12.1", | ||
"tslint-config-prettier": "^1.18.0", | ||
"tslint-plugin-prettier": "^2.0.1", | ||
"typescript": "^2.6.2" | ||
}, | ||
"scripts": { | ||
"test": "node dist-test/index.js && ./node_modules/.bin/jasmine", | ||
"compile": "./node_modules/.bin/tsc && ./node_modules/.bin/tsc --project test && ./node_modules/.bin/tsc --project examples-usage", | ||
"test": "rimraf dist-test && tsc --project test && node dist-test/index.js && jasmine", | ||
"compile": "rimraf dist && tsc", | ||
"compile-example": "rimraf dist && tsc && rimraf dist-example && tsc --project examples-usage", | ||
"bench": "node --expose-gc dist-test/benchmarks.js", | ||
@@ -54,0 +60,0 @@ "watch": "npm run compile && concurrently 'tsc -w' 'tsc -w --project test' 'tsc -w --project examples-usage'" |
@@ -299,2 +299,15 @@ [![Build Status](https://travis-ci.org/KostyaTretyak/marked-ts.svg?branch=master)](https://travis-ci.org/KostyaTretyak/marked-ts) | ||
unescape?: (html: string) => string = unescape; | ||
/** | ||
* If set to `true`, an inline text will not be taken in paragraph. | ||
* | ||
* ```ts | ||
* // isNoP == false | ||
* Marked.parse('some text'); // returns '<p>some text</p>' | ||
* | ||
* Marked.setOptions({isNoP: true}); | ||
* | ||
* Marked.parse('some text'); // returns 'some text' | ||
* ``` | ||
*/ | ||
isNoP?: boolean; | ||
} | ||
@@ -367,3 +380,3 @@ ``` | ||
| ------------------------|--------------|--------------|----------------|-----------|------------------ | ||
| marked-ts v1.0.0-beta.4 | 8 | 5 | 99 | 111 | 8 679 | ||
| marked-ts v1.0.0-beta.4 | 8 | 5 | 98 | 111 | 8 679 | ||
| marked v0.3.12 | 4 | 2 | 106 | 112 | 9 323 | ||
@@ -370,0 +383,0 @@ | remarkable v1.7.1 | 36 | 6 | 174 | 216 | 15 356 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80202
23
1817
428
21