提交 eabec006 编写于 作者: J Johannes Rieken

update to marked 0.5.0, #56749

上级 7fcd81cd
......@@ -9,7 +9,7 @@ import * as DOM from 'vs/base/browser/dom';
import { defaultGenerator } from 'vs/base/common/idGenerator';
import { escape } from 'vs/base/common/strings';
import { removeMarkdownEscapes, IMarkdownString } from 'vs/base/common/htmlContent';
import { marked, MarkedOptions } from 'vs/base/common/marked/marked';
import * as marked from 'vs/base/common/marked/marked';
import { IMouseEvent } from 'vs/base/browser/mouseEvent';
import { IDisposable } from 'vs/base/common/lifecycle';
......@@ -159,7 +159,7 @@ export function renderMarkdown(markdown: IMarkdownString, options: RenderOptions
}));
}
const markedOptions: MarkedOptions = {
const markedOptions: marked.MarkedOptions = {
sanitize: true,
renderer
};
......
// ATTENTION - THIS DIRECTORY CONTAINS THIRD PARTY OPEN SOURCE MATERIALS:
[{
"name": "chjj-marked",
"repositoryURL": "https://github.com/npmcomponent/chjj-marked",
"version": "0.3.18",
"license": "MIT"
}]
[
{
"name": "marked",
"repositoryURL": "https://github.com/markedjs/marked",
"version": "0.5.0",
"license": "MIT"
}
]
......@@ -3,36 +3,41 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
// Type definitions for Marked
// Project:https://github.com/chjj/marked
// Definitions by:William Orr <https://github.com/worr>
// Definitions:https://github.com/borisyankov/DefinitelyTyped
// Type definitions for Marked 0.4
// Project: https://github.com/markedjs/marked
// Definitions by: William Orr <https://github.com/worr>
// BendingBender <https://github.com/BendingBender>
// CrossR <https://github.com/CrossR>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export interface MarkedStatic {
/**
* Compiles markdown to HTML.
*
* @param src String of markdown source to be compiled
* @param callback Function called when the markdownString has been fully parsed when using async highlighting
* @return String of compiled HTML
*/
(src: string, callback: Function): string;
export as namespace marked;
/**
* Compiles markdown to HTML.
*
* @param src String of markdown source to be compiled
* @param options Hash of options
* @param callback Function called when the markdownString has been fully parsed when using async highlighting
* @return String of compiled HTML
*/
(src: string, options?: MarkedOptions, callback?: Function): string;
export = marked;
/**
* Compiles markdown to HTML.
*
* @param src String of markdown source to be compiled
* @param callback Function called when the markdownString has been fully parsed when using async highlighting
* @return String of compiled HTML
*/
declare function marked(src: string, callback: (error: any | undefined, parseResult: string) => void): string;
/**
* Compiles markdown to HTML.
*
* @param src String of markdown source to be compiled
* @param options Hash of options
* @param callback Function called when the markdownString has been fully parsed when using async highlighting
* @return String of compiled HTML
*/
declare function marked(src: string, options?: marked.MarkedOptions, callback?: (error: any | undefined, parseResult: string) => void): string;
declare namespace marked {
/**
* @param src String of markdown source to be compiled
* @param options Hash of options
*/
lexer(src: string, options?: MarkedOptions): any[];
function lexer(src: string, options?: MarkedOptions): TokensList;
/**
* Compiles markdown to HTML.
......@@ -41,7 +46,7 @@ export interface MarkedStatic {
* @param callback Function called when the markdownString has been fully parsed when using async highlighting
* @return String of compiled HTML
*/
parse(src: string, callback: Function): string;
function parse(src: string, callback: (error: any | undefined, parseResult: string) => void): string;
/**
* Compiles markdown to HTML.
......@@ -51,112 +56,242 @@ export interface MarkedStatic {
* @param callback Function called when the markdownString has been fully parsed when using async highlighting
* @return String of compiled HTML
*/
parse(src: string, options?: MarkedOptions, callback?: Function): string;
function parse(src: string, options?: MarkedOptions, callback?: (error: any | undefined, parseResult: string) => void): string;
/**
* @param src Tokenized source as array of tokens
* @param options Hash of options
*/
parser(src: any[], options?: MarkedOptions): string;
function parser(src: TokensList, options?: MarkedOptions): string;
/**
* Sets the default options.
*
* @param options Hash of options
*/
setOptions(options: MarkedOptions): void;
function setOptions(options: MarkedOptions): typeof marked;
/**
* Custom renderer for marked.
*/
Renderer: Renderer;
}
class Renderer {
constructor(options?: MarkedOptions);
code(code: string, language: string, isEscaped: boolean): string;
blockquote(quote: string): string;
html(html: string): string;
heading(text: string, level: number, raw: string): string;
hr(): string;
list(body: string, ordered: boolean): string;
listitem(text: string): string;
paragraph(text: string): string;
table(header: string, body: string): string;
tablerow(content: string): string;
tablecell(content: string, flags: {
header: boolean;
align: 'center' | 'left' | 'right' | null;
}): string;
strong(text: string): string;
em(text: string): string;
codespan(code: string): string;
br(): string;
del(text: string): string;
link(href: string, title: string, text: string): string;
image(href: string, title: string, text: string): string;
text(text: string): string;
}
export interface Renderer {
prototype: MarkedRenderer;
new(): MarkedRenderer;
}
class Lexer {
rules: Rules;
tokens: TokensList;
constructor(options?: MarkedOptions);
lex(src: string): TokensList;
}
export interface MarkedRenderer {
image(href: string, title: string, text: string): string;
code(code: string, language: string): string;
blockquote(quote: string): string;
html(html: string): string;
heading(text: string, level: number): string;
hr(): string;
list(body: string, ordered: boolean): string;
listitem(text: string): string;
paragraph(text: string): string;
table(header: string, body: string): string;
tablerow(content: string): string;
tablecell(content: string, flags: ITableFlags): string;
strong(text: string): string;
em(text: string): string;
codespan(code: string): string;
br(): string;
del(text: string): string;
link(href: string, title: string, text: string): string;
}
interface Rules {
[ruleName: string]: RegExp | Rules;
}
export interface ITableFlags {
header: boolean;
align: string; // 'center' || 'left' || 'right'
}
type TokensList = Token[] & {
links: {
[key: string]: { href: string; title: string; }
}
};
export interface MarkedOptions {
/**
* Enable GitHub flavored markdown.
*/
gfm?: boolean;
/**
* Enable GFM tables. This option requires the gfm option to be true.
*/
tables?: boolean;
/**
* Enable GFM line breaks. This option requires the gfm option to be true.
*/
breaks?: boolean;
/**
* Conform to obscure parts of markdown.pl as much as possible. Don't fix any of the original markdown bugs or poor behavior.
*/
pedantic?: boolean;
/**
* Sanitize the output. Ignore any HTML that has been input.
*/
sanitize?: boolean;
/**
* Use smarter list behavior than the original markdown. May eventually be default with the old behavior moved into pedantic.
*/
smartLists?: boolean;
/**
* Shows an HTML error message when rendering fails.
*/
silent?: boolean;
/**
* A function to highlight code blocks. The function takes three arguments:code, lang, and callback.
*/
highlight?(code: string, lang: string, callback?: Function): void;
/**
* Set the prefix for code block classes.
*/
langPrefix?: string;
/**
* Use "smart" typograhic punctuation for things like quotes and dashes.
*/
smartypants?: boolean;
/**
* The renderer to use with marked rendering.
*/
renderer?: any;
}
type Token =
Tokens.Space
| Tokens.Code
| Tokens.Heading
| Tokens.Table
| Tokens.Hr
| Tokens.BlockquoteStart
| Tokens.BlockquoteEnd
| Tokens.ListStart
| Tokens.LooseItemStart
| Tokens.ListItemStart
| Tokens.ListItemEnd
| Tokens.ListEnd
| Tokens.Paragraph
| Tokens.HTML
| Tokens.Text;
namespace Tokens {
interface Space {
type: 'space';
}
interface Code {
type: 'code';
lang?: string;
text: string;
}
interface Heading {
type: 'heading';
depth: number;
text: string;
}
interface Table {
type: 'table';
header: string[];
align: Array<'center' | 'left' | 'right' | null>;
cells: string[][];
}
interface Hr {
type: 'hr';
}
interface BlockquoteStart {
type: 'blockquote_start';
}
export declare var marked: MarkedStatic;
\ No newline at end of file
interface BlockquoteEnd {
type: 'blockquote_end';
}
interface ListStart {
type: 'list_start';
ordered: boolean;
}
interface LooseItemStart {
type: 'loose_item_start';
}
interface ListItemStart {
type: 'list_item_start';
}
interface ListItemEnd {
type: 'list_item_end';
}
interface ListEnd {
type: 'list_end';
}
interface Paragraph {
type: 'paragraph';
pre?: boolean;
text: string;
}
interface HTML {
type: 'html';
pre: boolean;
text: string;
}
interface Text {
type: 'text';
text: string;
}
}
interface MarkedOptions {
/**
* A prefix URL for any relative link.
*/
baseUrl?: string;
/**
* Enable GFM line breaks. This option requires the gfm option to be true.
*/
breaks?: boolean;
/**
* Enable GitHub flavored markdown.
*/
gfm?: boolean;
/**
* Include an id attribute when emitting headings.
*/
headerIds?: boolean;
/**
* Set the prefix for header tag ids.
*/
headerPrefix?: string;
/**
* A function to highlight code blocks. The function takes three arguments: code, lang, and callback.
*/
highlight?(code: string, lang: string, callback?: (error: any | undefined, code: string) => void): string;
/**
* Set the prefix for code block classes.
*/
langPrefix?: string;
/**
* Mangle autolinks (<email@domain.com>).
*/
mangle?: boolean;
/**
* Conform to obscure parts of markdown.pl as much as possible. Don't fix any of the original markdown bugs or poor behavior.
*/
pedantic?: boolean;
/**
* Type: object Default: new Renderer()
*
* An object containing functions to render tokens to HTML.
*/
renderer?: Renderer;
/**
* Sanitize the output. Ignore any HTML that has been input.
*/
sanitize?: boolean;
/**
* Optionally sanitize found HTML with a sanitizer function.
*/
sanitizer?(html: string): string;
/**
* Shows an HTML error message when rendering fails.
*/
silent?: boolean;
/**
* Use smarter list behavior than the original markdown. May eventually be default with the old behavior moved into pedantic.
*/
smartLists?: boolean;
/**
* Use "smart" typograhic punctuation for things like quotes and dashes.
*/
smartypants?: boolean;
/**
* Enable GFM tables. This option requires the gfm option to be true.
*/
tables?: boolean;
/**
* Generate closing slash for self-closing tags (<br/> instead of <br>)
*/
xhtml?: boolean;
}
}
......@@ -4,9 +4,7 @@
* https://github.com/markedjs/marked
*/
var __marked_exports;
; (function (root) {
;(function(root) {
'use strict';
/**
......@@ -137,7 +135,7 @@ block.pedantic = merge({}, block.normal, {
function Lexer(options) {
this.tokens = [];
this.tokens.links = {};
this.tokens.links = Object.create(null);
this.options = options || marked.defaults;
this.rules = block.normal;
......@@ -193,6 +191,9 @@ Lexer.prototype.token = function(src, top) {
bull,
b,
item,
listStart,
listItems,
t,
space,
i,
tag,
......@@ -318,15 +319,19 @@ Lexer.prototype.token = function(src, top) {
bull = cap[2];
isordered = bull.length > 1;
this.tokens.push({
listStart = {
type: 'list_start',
ordered: isordered,
start: isordered ? +bull : ''
});
start: isordered ? +bull : '',
loose: false
};
this.tokens.push(listStart);
// Get each top-level item.
cap = cap[0].match(this.rules.item);
listItems = [];
next = false;
l = cap.length;
i = 0;
......@@ -367,6 +372,10 @@ Lexer.prototype.token = function(src, top) {
if (!loose) loose = next;
}
if (loose) {
listStart.loose = true;
}
// Check for task list items
istask = /^\[[ xX]\] /.test(item);
ischecked = undefined;
......@@ -375,13 +384,15 @@ Lexer.prototype.token = function(src, top) {
item = item.replace(/^\[[ xX]\] +/, '');
}
this.tokens.push({
type: loose
? 'loose_item_start'
: 'list_item_start',
t = {
type: 'list_item_start',
task: istask,
checked: ischecked
});
checked: ischecked,
loose: loose
};
listItems.push(t);
this.tokens.push(t);
// Recurse.
this.token(item, false);
......@@ -391,6 +402,14 @@ Lexer.prototype.token = function(src, top) {
});
}
if (listStart.loose) {
l = listItems.length;
i = 0;
for (; i < l; i++) {
listItems[i].loose = true;
}
}
this.tokens.push({
type: 'list_end'
});
......@@ -521,10 +540,10 @@ var inline = {
link: /^!?\[(label)\]\(href(?:\s+(title))?\s*\)/,
reflink: /^!?\[(label)\]\[(?!\s*\])((?:\\[\[\]]?|[^\[\]\\])+)\]/,
nolink: /^!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?/,
strong: /^__([^\s][\s\S]*?[^\s])__(?!_)|^\*\*([^\s][\s\S]*?[^\s])\*\*(?!\*)|^__([^\s])__(?!_)|^\*\*([^\s])\*\*(?!\*)/,
em: /^_([^\s][\s\S]*?[^\s_])_(?!_)|^_([^\s_][\s\S]*?[^\s])_(?!_)|^\*([^\s][\s\S]*?[^\s*])\*(?!\*)|^\*([^\s*][\s\S]*?[^\s])\*(?!\*)|^_([^\s_])_(?!_)|^\*([^\s*])\*(?!\*)/,
strong: /^__([^\s])__(?!_)|^\*\*([^\s])\*\*(?!\*)|^__([^\s][\s\S]*?[^\s])__(?!_)|^\*\*([^\s][\s\S]*?[^\s])\*\*(?!\*)/,
em: /^_([^\s_])_(?!_)|^\*([^\s*"<\[])\*(?!\*)|^_([^\s][\s\S]*?[^\s_])_(?!_)|^_([^\s_][\s\S]*?[^\s])_(?!_)|^\*([^\s"<\[][\s\S]*?[^\s*])\*(?!\*)|^\*([^\s*"<\[][\s\S]*?[^\s])\*(?!\*)/,
code: /^(`+)\s*([\s\S]*?[^`]?)\s*\1(?!`)/,
br: /^ {2,}\n(?!\s*$)/,
br: /^( {2,}|\\)\n(?!\s*$)/,
del: noop,
text: /^[\s\S]+?(?=[\\<!\[`*]|\b_| {2,}\n|$)/
};
......@@ -546,7 +565,7 @@ inline.tag = edit(inline.tag)
.getRegex();
inline._label = /(?:\[[^\[\]]*\]|\\[\[\]]?|`[^`]*`|[^\[\]\\])*?/;
inline._href = /\s*(<(?:\\[<>]?|[^\s<>\\])*>|(?:\\[()]?|\([^\s\x00-\x1f()\\]*\)|[^\s\x00-\x1f()\\])*?)/;
inline._href = /\s*(<(?:\\[<>]?|[^\s<>\\])*>|(?:\\[()]?|\([^\s\x00-\x1f\\]*\)|[^\s\x00-\x1f()\\])*?)/;
inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/;
inline.link = edit(inline.link)
......@@ -590,7 +609,7 @@ inline.gfm = merge({}, inline.normal, {
.replace('email', inline._email)
.getRegex(),
_backpedal: /(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,
del: /^~~(?=\S)([\s\S]*?\S)~~/,
del: /^~+(?=\S)([\s\S]*?\S)~+/,
text: edit(inline.text)
.replace(']|', '~]|')
.replace('|', '|https?://|ftp://|www\\.|[a-zA-Z0-9.!#$%&\'*+/=?^_`{\\|}~-]+@|')
......@@ -657,7 +676,8 @@ InlineLexer.prototype.output = function(src) {
text,
href,
title,
cap;
cap,
prevCapZero;
while (src) {
// escape
......@@ -683,7 +703,10 @@ InlineLexer.prototype.output = function(src) {
// url (gfm)
if (!this.inLink && (cap = this.rules.url.exec(src))) {
cap[0] = this.rules._backpedal.exec(cap[0])[0];
do {
prevCapZero = cap[0];
cap[0] = this.rules._backpedal.exec(cap[0])[0];
} while (prevCapZero !== cap[0]);
src = src.substring(cap[0].length);
if (cap[2] === '@') {
text = escape(cap[0]);
......@@ -1219,30 +1242,22 @@ Parser.prototype.tok = function() {
}
case 'list_item_start': {
body = '';
var loose = this.token.loose;
if (this.token.task) {
body += this.renderer.checkbox(this.token.checked);
}
while (this.next().type !== 'list_item_end') {
body += this.token.type === 'text'
body += !loose && this.token.type === 'text'
? this.parseText()
: this.tok();
}
return this.renderer.listitem(body);
}
case 'loose_item_start': {
body = '';
while (this.next().type !== 'list_item_end') {
body += this.tok();
}
return this.renderer.listitem(body);
}
case 'html': {
// TODO@matt parse inline content if parameter markdown=1
// TODO parse inline content if parameter markdown=1
return this.renderer.html(this.token.text);
}
case 'paragraph': {
......@@ -1547,27 +1562,12 @@ marked.InlineLexer = InlineLexer;
marked.inlineLexer = InlineLexer.output;
marked.parse = marked;
__marked_exports = marked;
}).call(this);
// ESM-comment-begin
define([], function() {
return {
marked: __marked_exports
};
});
// ESM-comment-end
// ESM-uncomment-begin
// export var marked = __marked_exports;
// export var Parser = __marked_exports.Parser;
// export var parser = __marked_exports.parser;
// export var Renderer = __marked_exports.Renderer;
// export var TextRenderer = __marked_exports.TextRenderer;
// export var Lexer = __marked_exports.Lexer;
// export var lexer = __marked_exports.lexer;
// export var InlineLexer = __marked_exports.InlineLexer;
// export var inlineLexer = __marked_exports.inlineLexer;
// export var parse = __marked_exports.parse;
// ESM-uncomment-end
if (typeof module !== 'undefined' && typeof exports === 'object') {
module.exports = marked;
} else if (typeof define === 'function' && define.amd) {
define(function() { return marked; });
} else {
root.marked = marked;
}
})(this || (typeof window !== 'undefined' ? window : global));
\ No newline at end of file
......@@ -5,7 +5,7 @@
'use strict';
import * as assert from 'assert';
import { marked } from 'vs/base/common/marked/marked';
import * as marked from 'vs/base/common/marked/marked';
import { renderMarkdown, renderText, renderFormattedText } from 'vs/base/browser/htmlContentRenderer';
suite('HtmlContent', () => {
......
......@@ -8,7 +8,7 @@
import 'vs/css!./media/extensionEditor';
import { localize } from 'vs/nls';
import { TPromise, Promise } from 'vs/base/common/winjs.base';
import { marked } from 'vs/base/common/marked/marked';
import * as marked from 'vs/base/common/marked/marked';
import { createCancelablePromise } from 'vs/base/common/async';
import * as arrays from 'vs/base/common/arrays';
import { OS } from 'vs/base/common/platform';
......
......@@ -6,7 +6,7 @@
'use strict';
import { onUnexpectedError } from 'vs/base/common/errors';
import { marked } from 'vs/base/common/marked/marked';
import * as marked from 'vs/base/common/marked/marked';
import { OS } from 'vs/base/common/platform';
import { URI } from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
......
......@@ -16,7 +16,7 @@ import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { WalkThroughInput } from 'vs/workbench/parts/welcome/walkThrough/node/walkThroughInput';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { marked } from 'vs/base/common/marked/marked';
import * as marked from 'vs/base/common/marked/marked';
import { IModelService } from 'vs/editor/common/services/modelService';
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
......
......@@ -13,7 +13,7 @@ import { ITextFileService } from 'vs/workbench/services/textfile/common/textfile
import { ITextModel, DefaultEndOfLine, EndOfLinePreference, ITextBufferFactory } from 'vs/editor/common/model';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { marked } from 'vs/base/common/marked/marked';
import * as marked from 'vs/base/common/marked/marked';
import { Schemas } from 'vs/base/common/network';
import { Range } from 'vs/editor/common/core/range';
......
......@@ -11,7 +11,7 @@ import { URI } from 'vs/base/common/uri';
import { IReference, IDisposable, dispose } from 'vs/base/common/lifecycle';
import { telemetryURIDescriptor } from 'vs/platform/telemetry/common/telemetryUtils';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { marked } from 'vs/base/common/marked/marked';
import * as marked from 'vs/base/common/marked/marked';
import { Schemas } from 'vs/base/common/network';
import { IHashService } from 'vs/workbench/services/hash/common/hashService';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册