Socket
Socket
Sign inDemoInstall

marked-ts

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

marked-ts - npm Package Compare versions

Comparing version 0.0.0-alpha.2 to 0.0.0-alpha.3

6

dist/block-lexer.d.ts

@@ -7,3 +7,3 @@ import { MarkedOptions, LexerReturns } from './interfaces';

private tokens;
constructor(options: MarkedOptions);
constructor(options?: MarkedOptions);
/**

@@ -13,5 +13,5 @@ * Accepts Markdown text and returns object with tokens and links.

* @param src String of markdown source to be compiled.
* @param options Hash of options. Can also be set using the `Marked.setOptions` method as seen above.
* @param options Hash of options.
*/
static lex(src: string, options: MarkedOptions): LexerReturns;
static lex(src: string, options?: MarkedOptions): LexerReturns;
/**

@@ -18,0 +18,0 @@ * Preprocessing.

@@ -95,3 +95,3 @@ "use strict";

* @param src String of markdown source to be compiled.
* @param options Hash of options. Can also be set using the `Marked.setOptions` method as seen above.
* @param options Hash of options.
*/

@@ -323,8 +323,14 @@ static lex(src, options) {

nextPart = nextPart.substring(execArr[0].length);
this.tokens.push({
type: 'paragraph',
text: execArr[1].charAt(execArr[1].length - 1) === '\n'
? execArr[1].slice(0, -1)
: execArr[1]
});
if (execArr[1].charAt(execArr[1].length - 1) === '\n') {
this.tokens.push({
type: 'paragraph',
text: execArr[1].slice(0, -1),
});
}
else {
this.tokens.push({
type: this.tokens.length > 0 ? 'paragraph' : 'html',
text: execArr[1],
});
}
continue;

@@ -331,0 +337,0 @@ }

@@ -23,9 +23,2 @@ "use strict";

const escapeReplaceNoEncode = /(?:[<>"']|&(?!#?\w+;))/g;
const replacementsNoEncode = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;'
};
function escape(html, encode) {

@@ -39,3 +32,3 @@ if (encode) {

if (escapeTestNoEncode.test(html)) {
return html.replace(escapeReplaceNoEncode, (ch) => replacementsNoEncode[ch]);
return html.replace(escapeReplaceNoEncode, (ch) => replacements[ch]);
}

@@ -42,0 +35,0 @@ }

@@ -0,3 +1,3 @@

import { Renderer } from './renderer';
import { MarkedOptions, Links, Link } from './interfaces';
import { Renderer } from './renderer';
/**

@@ -4,0 +4,0 @@ * Inline Lexer & Compiler.

@@ -23,3 +23,3 @@ "use strict";

del: helpers_1.Noop,
autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
autolink: /^<([^ <>]+(@|:\/)[^ <>]+)>/,
tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,

@@ -119,3 +119,3 @@ link: /^!?\[(inside)\]\(href\)/,

else {
text = helpers_1.escape(execArr[1]);
text = this.options.escape(execArr[1]);
href = text;

@@ -130,3 +130,3 @@ }

nextPart = nextPart.substring(execArr[0].length);
text = helpers_1.escape(execArr[1]);
text = this.options.escape(execArr[1]);
href = text;

@@ -148,3 +148,3 @@ out += this.renderer.link(href, null, text);

? this.options.sanitizer(execArr[0])
: helpers_1.escape(execArr[0])
: this.options.escape(execArr[0])
: execArr[0];

@@ -195,3 +195,3 @@ continue;

nextPart = nextPart.substring(execArr[0].length);
out += this.renderer.codespan(helpers_1.escape(execArr[2].trim(), true));
out += this.renderer.codespan(this.options.escape(execArr[2].trim(), true));
continue;

@@ -214,3 +214,3 @@ }

nextPart = nextPart.substring(execArr[0].length);
out += this.renderer.text(helpers_1.escape(this.smartypants(execArr[0])));
out += this.renderer.text(this.options.escape(this.smartypants(execArr[0])));
continue;

@@ -227,6 +227,6 @@ }

outputLink(execArr, link) {
const href = helpers_1.escape(link.href), title = link.title ? helpers_1.escape(link.title) : null;
const href = this.options.escape(link.href), title = link.title ? this.options.escape(link.title) : null;
return execArr[0].charAt(0) !== '!'
? this.renderer.link(href, title, this.output(execArr[1]))
: this.renderer.image(href, title, helpers_1.escape(execArr[1]));
: this.renderer.image(href, title, this.options.escape(execArr[1]));
}

@@ -233,0 +233,0 @@ /**

@@ -99,3 +99,8 @@ /**

}
export declare type ParseCallback = (err: Error, output?: string) => any;
export declare type ParseCallback<T = string> = (err: Error, output?: string) => T;
export interface HighlightOverloading {
fn(code: string, lang?: string): string;
fn<T>(code: string, lang?: string, callback?: ParseCallback<T>): T;
}
export declare type HighlightType = HighlightOverloading['fn'];
export declare class MarkedOptions {

@@ -107,3 +112,3 @@ gfm?: boolean;

sanitize?: boolean;
sanitizer?: any;
sanitizer?: (text: string) => string;
mangle?: boolean;

@@ -117,3 +122,3 @@ smartLists?: boolean;

*/
highlight?: (code: string, lang: string, callback?: ParseCallback) => string;
highlight?: HighlightType;
langPrefix?: string;

@@ -126,3 +131,17 @@ smartypants?: boolean;

renderer?: Renderer;
/**
* Self-close the tags for void elements (&lt;br/&gt;, &lt;img/&gt;, etc.)
* with a "/" as required by XHTML.
*/
xhtml?: boolean;
/**
* The function that will be using to escape HTML entities.
* By default using inner helper.
*/
escape?: (html: string, encode?: boolean) => string;
/**
* The function that will be using to unescape HTML entities.
* By default using inner helper.
*/
unescape?: (html: string) => string;
}

@@ -133,1 +152,4 @@ export interface LexerReturns {

}
export interface Replacements {
[key: string]: string;
}

@@ -9,2 +9,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const helpers_1 = require("./helpers");
class MarkedOptions {

@@ -17,16 +18,23 @@ constructor() {

this.sanitize = false;
this.sanitizer = null;
this.mangle = true;
this.smartLists = false;
this.silent = false;
/**
* @param code The section of code to pass to the highlighter.
* @param lang The programming language specified in the code block.
* @param callback The callback function to call when using an async highlighter.
*/
this.highlight = null;
this.langPrefix = 'lang-';
this.smartypants = false;
this.headerPrefix = '';
/**
* Self-close the tags for void elements (&lt;br/&gt;, &lt;img/&gt;, etc.)
* with a "/" as required by XHTML.
*/
this.xhtml = false;
/**
* The function that will be using to escape HTML entities.
* By default using inner helper.
*/
this.escape = helpers_1.escape;
/**
* The function that will be using to unescape HTML entities.
* By default using inner helper.
*/
this.unescape = helpers_1.unescape;
}

@@ -33,0 +41,0 @@ }

@@ -7,3 +7,3 @@ import { ParseCallback, MarkedOptions } from './interfaces';

*
* @param options Hash of options. Can also be set using the `Marked.setOptions` method as seen above.
* @param options Hash of options.
*/

@@ -21,5 +21,6 @@ static setOptions(options: MarkedOptions): typeof Marked;

* @param src String of markdown source to be compiled.
* @param options Hash of options. Can also be set using the `Marked.setOptions` method as seen above.
* @param options Hash of options. They do not merge with default options. If you want
* the merging, you can to do this via `Marked.setOptions()`.
*/
static parse(src: string, options: object): string;
static parse(src: string, options: MarkedOptions): string;
/**

@@ -31,3 +32,3 @@ * Accepts Markdown text and returns text in HTML format.

*/
static parse(src: string, callback: ParseCallback): string;
static parse<T>(src: string, callback: ParseCallback<T>): T;
/**

@@ -37,6 +38,9 @@ * Accepts Markdown text and returns text in HTML format.

* @param src String of markdown source to be compiled.
* @param options Hash of options. Can also be set using the `Marked.setOptions` method as seen above.
*
* @param options Hash of options. They do not merge with default options. If you want
* the merging, you can to do this via `Marked.setOptions()`.
*
* @param callback Function that handles errors.
*/
static parse(src: string, options: object, callback: ParseCallback): string;
static parse<T>(src: string, options: MarkedOptions, callback: ParseCallback<T>): T;
}

@@ -14,3 +14,2 @@ "use strict";

const block_lexer_1 = require("./block-lexer");
const helpers_1 = require("./helpers");
const interfaces_1 = require("./interfaces");

@@ -21,3 +20,3 @@ class Marked {

*
* @param options Hash of options. Can also be set using the `Marked.setOptions` method as seen above.
* @param options Hash of options.
*/

@@ -35,3 +34,2 @@ static setOptions(options) {

const options = this.defaults || optsOrCallback;
const highlight = options.highlight;
let tokens, links;

@@ -44,7 +42,10 @@ try {

}
let pending = tokens.length;
const highlight = options.highlight;
// `length` here it's number of function arguments
if (!highlight || highlight.length < 3) {
return done();
}
// ************** Highlighting ************** //
delete options.highlight;
let pending = tokens.length;
if (!pending)

@@ -55,13 +56,17 @@ return done();

if (token.type !== 'code') {
return --pending || done();
if (!--pending)
return done();
continue;
}
return highlight(token.text, token.lang, function (err, code) {
return highlight(token.text, token.lang, (err, code) => {
if (err)
return done(err);
if (code == null || code === token.text) {
return --pending || done();
if (!--pending)
return done();
}
token.text = code;
token.escaped = true;
--pending || done();
if (!--pending)
return done();
});

@@ -83,3 +88,3 @@ }

options.highlight = highlight;
return err ? callback(err) : callback(null, out);
return callback(err, out);
}

@@ -94,4 +99,4 @@ }

err.message += '\nPlease report this to https://github.com/KostyaTretyak/marked-ts';
if ((options || this.defaults).silent) {
return '<p>An error occured:</p><pre>' + helpers_1.escape(err.message + '', true) + '</pre>';
if (options.silent) {
return '<p>An error occured:</p><pre>' + this.defaults.escape(err.message + '', true) + '</pre>';
}

@@ -98,0 +103,0 @@ throw err;

import { MarkedOptions, ParamsToken, Links } from './interfaces';
import { Renderer } from './renderer';
/**

@@ -12,4 +11,4 @@ * Parsing & Compiling.

private renderer;
constructor(options?: MarkedOptions, renderer?: Renderer);
static parse(srcTokens: ParamsToken[], links: Links, options?: MarkedOptions, renderer?: Renderer): string;
constructor(options?: MarkedOptions);
static parse(srcTokens: ParamsToken[], links: Links, options?: MarkedOptions): string;
private parse(links, srcTokens);

@@ -16,0 +15,0 @@ next(): ParamsToken;

@@ -19,3 +19,3 @@ "use strict";

class Parser {
constructor(options, renderer) {
constructor(options) {
this.tokens = [];

@@ -26,4 +26,4 @@ this.token = null;

}
static parse(srcTokens, links, options, renderer) {
const parser = new this(options, renderer);
static parse(srcTokens, links, options) {
const parser = new this(options);
return parser.parse(links, srcTokens);

@@ -73,8 +73,9 @@ }

{
let header = '', body = '', row, cell, flags;
let header = '', body = '', row, cell;
// header
cell = '';
for (let i = 0; i < this.token.header.length; i++) {
flags = { header: true, align: this.token.align[i] };
cell += this.renderer.tablecell(this.inlineLexer.output(this.token.header[i]), { header: true, align: this.token.align[i] });
const flags = { header: true, align: this.token.align[i] };
const out = this.inlineLexer.output(this.token.header[i]);
cell += this.renderer.tablecell(out, flags);
}

@@ -81,0 +82,0 @@ header += this.renderer.tablerow(cell);

@@ -12,3 +12,2 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const helpers_1 = require("./helpers");
const marked_1 = require("./marked");

@@ -28,6 +27,6 @@ class Renderer {

if (!lang) {
return '<pre><code>' + (escaped ? code : helpers_1.escape(code, true)) + '\n</code></pre>';
return '<pre><code>' + (escaped ? code : this.options.escape(code, true)) + '\n</code></pre>';
}
return '<pre><code class="' + this.options.langPrefix + helpers_1.escape(lang, true) + '">'
+ (escaped ? code : helpers_1.escape(code, true))
return '<pre><code class="' + this.options.langPrefix + this.options.escape(lang, true) + '">'
+ (escaped ? code : this.options.escape(code, true))
+ '\n</code></pre>\n';

@@ -100,3 +99,3 @@ }

try {
prot = decodeURIComponent(helpers_1.unescape(href))
prot = decodeURIComponent(this.options.unescape(href))
.replace(/[^\w:]/g, '')

@@ -106,3 +105,3 @@ .toLowerCase();

catch (e) {
return '';
return text;
}

@@ -112,3 +111,3 @@ if (prot.indexOf('javascript:') === 0

|| prot.indexOf('data:') === 0) {
return '';
return text;
}

@@ -115,0 +114,0 @@ }

@@ -5,3 +5,3 @@ {

"author": "Костя Третяк <ktretiak.in.ua@gmail.com>",
"version": "0.0.0-alpha.2",
"version": "0.0.0-alpha.3",
"main": "dist/index",

@@ -28,2 +28,5 @@ "typings": "dist/index",

],
"optionalDependencies": {
"typescript": "^2.6.2"
},
"devDependencies": {

@@ -33,2 +36,3 @@ "@types/highlight.js": "^9.12.2",

"@types/node": "^8.5.1",
"concurrently": "^3.5.1",
"highlight.js": "^9.12.0",

@@ -39,9 +43,10 @@ "markdown": "*",

"remarkable": "^1.7.1",
"showdown": "*",
"typescript": "^2.6.2"
"showdown": "*"
},
"scripts": {
"test": "node dist-test/index.js",
"bench": "node test --bench"
"compile": "./node_modules/.bin/tsc && ./node_modules/.bin/tsc --project test",
"bench": "node dist-test/index.js --bench",
"watch": "concurrently './node_modules/.bin/tsc -w' './node_modules/.bin/tsc -w --project test'"
}
}

@@ -5,4 +5,3 @@ [![Build Status](https://travis-ci.org/KostyaTretyak/marked-ts.svg?branch=master)](https://travis-ci.org/KostyaTretyak/marked-ts)

> A full-featured markdown parser and compiler, written in JavaScript. Built
> for speed.
> A full-featured markdown parser and compiler, written in TypeScript.

@@ -16,4 +15,6 @@ This is fork of popular library `marked` from [this commit](https://github.com/chjj/marked/tree/39fbc8aedb3e17e0b098cf753492402614bd6b3e)

If you want to use `marked-ts` without TypeScript functionality, you can install it with `--no-optional` switch:
``` bash
npm install marked-ts --save
npm install marked-ts --no-optional --save
```

@@ -29,3 +30,3 @@

console.log(Marked.parse('I am using __markdown__.'));
// Outputs: <p>I am using <strong>markdown</strong>.</p>
// Outputs: I am using <strong>markdown</strong>.
```

@@ -61,3 +62,3 @@

console.log(marked.Marked.parse('I am using __markdown__.'));
// Outputs: <p>I am using <strong>markdown</strong>.</p>
// Outputs: I am using <strong>markdown</strong>.
```

@@ -86,3 +87,3 @@

### Methods of Marked class
### Methods of Marked class and necessary types

@@ -104,18 +105,17 @@ ```ts

static parse(src: string): string;
static parse(src: string, options: object): string;
static parse(src: string, callback: ParseCallback): string;
static parse(src: string, options: object, callback: ParseCallback): string;
static parse(src: string, options: MarkedOptions): string;
static parse(src: string, callback: ParseCallback): any;
static parse(src: string, options: MarkedOptions, callback: ParseCallback): any;
type ParseCallback = (err: Error, output?: string) => any;
/**
* Merges the default options with options that will be set.
*
* @param options Hash of options. Can also be set using
* the `Marked.setOptions` method as seen above.
* @param options Hash of options.
*/
static setOptions(options: MarkedOptions): this;
type ParseCallback<T=string> = (err: Error, output?: string) => T;
// This class also using as a type.
class MarkedOptions

@@ -128,3 +128,3 @@ {

sanitize?: boolean = false;
sanitizer?: any = null;
sanitizer?: (text: string) => string;
mangle?: boolean = true;

@@ -138,3 +138,3 @@ smartLists?: boolean = false;

*/
highlight?: (code: string, lang: string, callback?: ParseCallback) => string = null;
highlight?: (code: string, lang: string, callback?: ParseCallback) => any;
langPrefix?: string = 'lang-';

@@ -147,7 +147,21 @@ smartypants?: boolean = false;

renderer?: Renderer;
/**
* Self-close the tags for void elements (&lt;br/&gt;, &lt;img/&gt;, etc.)
* with a "/" as required by XHTML.
*/
xhtml?: boolean = false;
/**
* The function that will be using to escape HTML entities.
* By default using inner helper.
*/
escape?: (html: string, encode?: boolean) => string = escape;
/**
* The function that will be using to unescape HTML entities.
* By default using inner helper.
*/
unescape: (html: string) => string = unescape;
}
```
### Example useage with highlight.js
### Example usage with highlight.js

@@ -176,3 +190,3 @@ ```bash

// Synchronous highlighting with highlight.js
Marked.setOptions({ highlight: code => highlightAuto(code).value; });
Marked.setOptions({ highlight: code => highlightAuto(code).value });

@@ -227,3 +241,3 @@ console.log(Marked.parse(md));

#### Renderer methods API
### Renderer methods API

@@ -285,6 +299,3 @@ ```ts

cannot pass more than a few tests. It was very difficult to get marked as
compliant as it is. It could have cut corners in several areas for the sake
of performance, but did not in order to be exactly what you expect in terms
of a markdown rendering. In fact, this is why marked could be considered at a
disadvantage in the benchmarks above.
compliant as it is.

@@ -299,19 +310,19 @@ Along with implementing every markdown feature, marked also implements [GFM

``` bash
$ node dist-test/index.js --bench
npm install
npm run compile
npm run bench
```
These benchmarks run the entire markdown test suite (51 files) once. The test suite includes every feature.
It doesn't cater to specific aspects.
| engine | completed in ms
| ---------------------------- | ---------
| marked-ts alpha.2 | 4 563
| marked-ts (gfm) alpha.2 | 4 785
| marked-ts (pedantic) alpha.2 | 4 245
| marked v0.3.7 | 6 429
| marked (gfm) v0.3.7 | 6 818
| marked (pedantic) v0.3.7 | 6 205
| remarkable v1.7.1 | 6 260
| markdown-it v8.4.0 | 7 026
| markdown v0.5.0 | 27 180
| showdown v1.8.5 | 42 775
| marked-ts alpha.2 | 16
| marked v0.3.7 | 18
| markdown v0.5.0 | 52
| remarkable v1.7.1 | 53
| showdown v1.8.5 | 107
| markdown-it v8.4.0 | 118
For those feeling skeptical: These benchmarks run the entire markdown test suite 1000 times. The test suite tests every feature. It doesn't cater to specific aspects.

@@ -318,0 +329,0 @@ ### Contribution and License Agreement

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc