marked 3.0.7 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/Tokenizer.js CHANGED
@@ -1,10 +1,10 @@
1
- const { defaults } = require('./defaults.js');
2
- const {
1
+ import { defaults } from './defaults.js';
2
+ import {
3
3
  rtrim,
4
4
  splitCells,
5
5
  escape,
6
6
  findClosingBracket
7
- } = require('./helpers.js');
7
+ } from './helpers.js';
8
8
 
9
9
  function outputLink(cap, link, raw, lexer) {
10
10
  const href = link.href;
@@ -65,7 +65,7 @@ function indentCodeCompensation(raw, text) {
65
65
  /**
66
66
  * Tokenizer
67
67
  */
68
- module.exports = class Tokenizer {
68
+ export class Tokenizer {
69
69
  constructor(options) {
70
70
  this.options = options || defaults;
71
71
  }
@@ -752,4 +752,4 @@ module.exports = class Tokenizer {
752
752
  };
753
753
  }
754
754
  }
755
- };
755
+ }
package/src/defaults.js CHANGED
@@ -1,4 +1,4 @@
1
- function getDefaults() {
1
+ export function getDefaults() {
2
2
  return {
3
3
  baseUrl: null,
4
4
  breaks: false,
@@ -22,12 +22,8 @@ function getDefaults() {
22
22
  };
23
23
  }
24
24
 
25
- function changeDefaults(newDefaults) {
26
- module.exports.defaults = newDefaults;
27
- }
25
+ export let defaults = getDefaults();
28
26
 
29
- module.exports = {
30
- defaults: getDefaults(),
31
- getDefaults,
32
- changeDefaults
33
- };
27
+ export function changeDefaults(newDefaults) {
28
+ defaults = newDefaults;
29
+ }
package/src/helpers.js CHANGED
@@ -13,7 +13,7 @@ const escapeReplacements = {
13
13
  "'": '''
14
14
  };
15
15
  const getEscapeReplacement = (ch) => escapeReplacements[ch];
16
- function escape(html, encode) {
16
+ export function escape(html, encode) {
17
17
  if (encode) {
18
18
  if (escapeTest.test(html)) {
19
19
  return html.replace(escapeReplace, getEscapeReplacement);
@@ -29,7 +29,7 @@ function escape(html, encode) {
29
29
 
30
30
  const unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
31
31
 
32
- function unescape(html) {
32
+ export function unescape(html) {
33
33
  // explicitly match decimal, hex, and named HTML entities
34
34
  return html.replace(unescapeTest, (_, n) => {
35
35
  n = n.toLowerCase();
@@ -44,7 +44,7 @@ function unescape(html) {
44
44
  }
45
45
 
46
46
  const caret = /(^|[^\[])\^/g;
47
- function edit(regex, opt) {
47
+ export function edit(regex, opt) {
48
48
  regex = regex.source || regex;
49
49
  opt = opt || '';
50
50
  const obj = {
@@ -63,7 +63,7 @@ function edit(regex, opt) {
63
63
 
64
64
  const nonWordAndColonTest = /[^\w:]/g;
65
65
  const originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
66
- function cleanUrl(sanitize, base, href) {
66
+ export function cleanUrl(sanitize, base, href) {
67
67
  if (sanitize) {
68
68
  let prot;
69
69
  try {
@@ -93,7 +93,7 @@ const justDomain = /^[^:]+:\/*[^/]*$/;
93
93
  const protocol = /^([^:]+:)[\s\S]*$/;
94
94
  const domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
95
95
 
96
- function resolveUrl(base, href) {
96
+ export function resolveUrl(base, href) {
97
97
  if (!baseUrls[' ' + base]) {
98
98
  // we can ignore everything in base after the last slash of its path component,
99
99
  // but we might need to add _that_
@@ -122,9 +122,9 @@ function resolveUrl(base, href) {
122
122
  }
123
123
  }
124
124
 
125
- const noopTest = { exec: function noopTest() {} };
125
+ export const noopTest = { exec: function noopTest() {} };
126
126
 
127
- function merge(obj) {
127
+ export function merge(obj) {
128
128
  let i = 1,
129
129
  target,
130
130
  key;
@@ -141,7 +141,7 @@ function merge(obj) {
141
141
  return obj;
142
142
  }
143
143
 
144
- function splitCells(tableRow, count) {
144
+ export function splitCells(tableRow, count) {
145
145
  // ensure that every cell-delimiting pipe has a space
146
146
  // before it to distinguish it from an escaped pipe
147
147
  const row = tableRow.replace(/\|/g, (match, offset, str) => {
@@ -180,7 +180,7 @@ function splitCells(tableRow, count) {
180
180
  // Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
181
181
  // /c*$/ is vulnerable to REDOS.
182
182
  // invert: Remove suffix of non-c chars instead. Default falsey.
183
- function rtrim(str, c, invert) {
183
+ export function rtrim(str, c, invert) {
184
184
  const l = str.length;
185
185
  if (l === 0) {
186
186
  return '';
@@ -204,7 +204,7 @@ function rtrim(str, c, invert) {
204
204
  return str.substr(0, l - suffLen);
205
205
  }
206
206
 
207
- function findClosingBracket(str, b) {
207
+ export function findClosingBracket(str, b) {
208
208
  if (str.indexOf(b[1]) === -1) {
209
209
  return -1;
210
210
  }
@@ -226,14 +226,14 @@ function findClosingBracket(str, b) {
226
226
  return -1;
227
227
  }
228
228
 
229
- function checkSanitizeDeprecation(opt) {
229
+ export function checkSanitizeDeprecation(opt) {
230
230
  if (opt && opt.sanitize && !opt.silent) {
231
231
  console.warn('marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options');
232
232
  }
233
233
  }
234
234
 
235
235
  // copied from https://stackoverflow.com/a/5450113/806777
236
- function repeatString(pattern, count) {
236
+ export function repeatString(pattern, count) {
237
237
  if (count < 1) {
238
238
  return '';
239
239
  }
@@ -247,18 +247,3 @@ function repeatString(pattern, count) {
247
247
  }
248
248
  return result + pattern;
249
249
  }
250
-
251
- module.exports = {
252
- escape,
253
- unescape,
254
- edit,
255
- cleanUrl,
256
- resolveUrl,
257
- noopTest,
258
- merge,
259
- splitCells,
260
- rtrim,
261
- findClosingBracket,
262
- checkSanitizeDeprecation,
263
- repeatString
264
- };
package/src/marked.js CHANGED
@@ -1,24 +1,24 @@
1
- const Lexer = require('./Lexer.js');
2
- const Parser = require('./Parser.js');
3
- const Tokenizer = require('./Tokenizer.js');
4
- const Renderer = require('./Renderer.js');
5
- const TextRenderer = require('./TextRenderer.js');
6
- const Slugger = require('./Slugger.js');
7
- const {
1
+ import { Lexer } from './Lexer.js';
2
+ import { Parser } from './Parser.js';
3
+ import { Tokenizer } from './Tokenizer.js';
4
+ import { Renderer } from './Renderer.js';
5
+ import { TextRenderer } from './TextRenderer.js';
6
+ import { Slugger } from './Slugger.js';
7
+ import {
8
8
  merge,
9
9
  checkSanitizeDeprecation,
10
10
  escape
11
- } = require('./helpers.js');
12
- const {
11
+ } from './helpers.js';
12
+ import {
13
13
  getDefaults,
14
14
  changeDefaults,
15
15
  defaults
16
- } = require('./defaults.js');
16
+ } from './defaults.js';
17
17
 
18
18
  /**
19
19
  * Marked
20
20
  */
21
- function marked(src, opt, callback) {
21
+ export function marked(src, opt, callback) {
22
22
  // throw error in case of non string input
23
23
  if (typeof src === 'undefined' || src === null) {
24
24
  throw new Error('marked(): input parameter is undefined or null');
@@ -235,10 +235,10 @@ marked.use = function(...args) {
235
235
  // ==-- Parse WalkTokens extensions --== //
236
236
  if (pack.walkTokens) {
237
237
  const walkTokens = marked.defaults.walkTokens;
238
- opts.walkTokens = (token) => {
238
+ opts.walkTokens = function(token) {
239
239
  pack.walkTokens.call(this, token);
240
240
  if (walkTokens) {
241
- walkTokens(token);
241
+ walkTokens.call(this, token);
242
242
  }
243
243
  };
244
244
  }
@@ -257,7 +257,7 @@ marked.use = function(...args) {
257
257
 
258
258
  marked.walkTokens = function(tokens, callback) {
259
259
  for (const token of tokens) {
260
- callback(token);
260
+ callback.call(marked, token);
261
261
  switch (token.type) {
262
262
  case 'table': {
263
263
  for (const cell of token.header) {
@@ -333,4 +333,18 @@ marked.Tokenizer = Tokenizer;
333
333
  marked.Slugger = Slugger;
334
334
  marked.parse = marked;
335
335
 
336
- module.exports = marked;
336
+ export const options = marked.options;
337
+ export const setOptions = marked.setOptions;
338
+ export const use = marked.use;
339
+ export const walkTokens = marked.walkTokens;
340
+ export const parseInline = marked.parseInline;
341
+ export const parse = marked;
342
+ export const parser = Parser.parse;
343
+ export const lexer = Lexer.lex;
344
+ export { defaults, getDefaults } from './defaults.js';
345
+ export { Lexer } from './Lexer.js';
346
+ export { Parser } from './Parser.js';
347
+ export { Tokenizer } from './Tokenizer.js';
348
+ export { Renderer } from './Renderer.js';
349
+ export { TextRenderer } from './TextRenderer.js';
350
+ export { Slugger } from './Slugger.js';
package/src/rules.js CHANGED
@@ -1,13 +1,13 @@
1
- const {
1
+ import {
2
2
  noopTest,
3
3
  edit,
4
4
  merge
5
- } = require('./helpers.js');
5
+ } from './helpers.js';
6
6
 
7
7
  /**
8
8
  * Block-Level Grammar
9
9
  */
10
- const block = {
10
+ export const block = {
11
11
  newline: /^(?: *(?:\n|$))+/,
12
12
  code: /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,
13
13
  fences: /^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?=\n|$)|$)/,
@@ -139,7 +139,7 @@ block.pedantic = merge({}, block.normal, {
139
139
  /**
140
140
  * Inline-Level Grammar
141
141
  */
142
- const inline = {
142
+ export const inline = {
143
143
  escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,
144
144
  autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
145
145
  url: noopTest,
@@ -283,8 +283,3 @@ inline.breaks = merge({}, inline.gfm, {
283
283
  .replace(/\{2,\}/g, '*')
284
284
  .getRegex()
285
285
  });
286
-
287
- module.exports = {
288
- block,
289
- inline
290
- };
package/src/esm-entry.js DELETED
@@ -1,18 +0,0 @@
1
- const marked = require('./marked.js');
2
- const Lexer = require('./Lexer.js');
3
- const Parser = require('./Parser.js');
4
- const Tokenizer = require('./Tokenizer.js');
5
- const Renderer = require('./Renderer.js');
6
- const TextRenderer = require('./TextRenderer.js');
7
- const Slugger = require('./Slugger.js');
8
-
9
- module.exports = marked;
10
- module.exports.parse = marked;
11
- module.exports.Parser = Parser;
12
- module.exports.parser = Parser.parse;
13
- module.exports.Renderer = Renderer;
14
- module.exports.TextRenderer = TextRenderer;
15
- module.exports.Lexer = Lexer;
16
- module.exports.lexer = Lexer.lex;
17
- module.exports.Tokenizer = Tokenizer;
18
- module.exports.Slugger = Slugger;