markdown-to-jsx 7.2.1 → 7.3.1

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/README.md CHANGED
@@ -17,6 +17,7 @@ The most lightweight, customizable React markdown component.
17
17
  - [options.overrides - Override Any HTML Tag's Representation](#optionsoverrides---override-any-html-tags-representation)
18
18
  - [options.overrides - Rendering Arbitrary React Components](#optionsoverrides---rendering-arbitrary-react-components)
19
19
  - [options.createElement - Custom React.createElement behavior](#optionscreateelement---custom-reactcreateelement-behavior)
20
+ - [options.enforceAtxHeadings](#optionsenforceatxheadings)
20
21
  - [options.slugify](#optionsslugify)
21
22
  - [options.namedCodesToUnicode](#optionsnamedcodestounicode)
22
23
  - [options.disableParsingRawHTML](#optionsdisableparsingrawhtml)
@@ -26,6 +27,7 @@ The most lightweight, customizable React markdown component.
26
27
  - [Gotchas](#gotchas)
27
28
  - [Significant indentation inside arbitrary HTML](#significant-indentation-inside-arbitrary-html)
28
29
  - [Code blocks](#code-blocks)
30
+ - [Using The Compiler Directly](#using-the-compiler-directly)
29
31
  - [Changelog](#changelog)
30
32
  - [Donate](#donate)
31
33
 
@@ -35,17 +37,17 @@ The most lightweight, customizable React markdown component.
35
37
 
36
38
  `markdown-to-jsx` uses a heavily-modified fork of [simple-markdown](https://github.com/Khan/simple-markdown) as its parsing engine and extends it in a number of ways to make your life easier. Notably, this package offers the following additional benefits:
37
39
 
38
- - Arbitrary HTML is supported and parsed into the appropriate JSX representation
39
- without `dangerouslySetInnerHTML`
40
+ - Arbitrary HTML is supported and parsed into the appropriate JSX representation
41
+ without `dangerouslySetInnerHTML`
40
42
 
41
- - Any HTML tags rendered by the compiler and/or `<Markdown>` component can be overridden to include additional
42
- props or even a different HTML representation entirely.
43
+ - Any HTML tags rendered by the compiler and/or `<Markdown>` component can be overridden to include additional
44
+ props or even a different HTML representation entirely.
43
45
 
44
- - GFM task list support.
46
+ - GFM task list support.
45
47
 
46
- - Fenced code blocks with [highlight.js](https://highlightjs.org/) support.
48
+ - Fenced code blocks with [highlight.js](https://highlightjs.org/) support.
47
49
 
48
- All this clocks in at around 5 kB gzipped, which is a fraction of the size of most other React markdown components.
50
+ All this clocks in at around 6 kB gzipped, which is a fraction of the size of most other React markdown components.
49
51
 
50
52
  Requires React >= 0.14.
51
53
 
@@ -64,11 +66,11 @@ npm i markdown-to-jsx
64
66
  ES6-style usage\*:
65
67
 
66
68
  ```jsx
67
- import Markdown from 'markdown-to-jsx';
68
- import React from 'react';
69
- import { render } from 'react-dom';
69
+ import Markdown from 'markdown-to-jsx'
70
+ import React from 'react'
71
+ import { render } from 'react-dom'
70
72
 
71
- render(<Markdown># Hello world!</Markdown>, document.body);
73
+ render(<Markdown># Hello world!</Markdown>, document.body)
72
74
 
73
75
  /*
74
76
  renders:
@@ -98,15 +100,14 @@ But this string would be considered "block" due to the existence of a header tag
98
100
  However, if you really want all input strings to be treated as "block" layout, simply pass `options.forceBlock = true` like this:
99
101
 
100
102
  ```jsx
101
- <Markdown options={{ forceBlock: true }}>Hello there old chap!</Markdown>;
103
+ ;<Markdown options={{ forceBlock: true }}>Hello there old chap!</Markdown>
102
104
 
103
105
  // or
104
106
 
105
- compiler('Hello there old chap!', { forceBlock: true });
107
+ compiler('Hello there old chap!', { forceBlock: true })
106
108
 
107
109
  // renders
108
-
109
- <p>Hello there old chap!</p>;
110
+ ;<p>Hello there old chap!</p>
110
111
  ```
111
112
 
112
113
  #### options.forceInline
@@ -114,15 +115,14 @@ compiler('Hello there old chap!', { forceBlock: true });
114
115
  The inverse is also available by passing `options.forceInline = true`:
115
116
 
116
117
  ```jsx
117
- <Markdown options={{ forceInline: true }}># You got it babe!</Markdown>;
118
+ ;<Markdown options={{ forceInline: true }}># You got it babe!</Markdown>
118
119
 
119
120
  // or
120
121
 
121
- compiler('# You got it babe!', { forceInline: true });
122
+ compiler('# You got it babe!', { forceInline: true })
122
123
 
123
124
  // renders
124
-
125
- <span># You got it babe!</span>;
125
+ ;<span># You got it babe!</span>
126
126
  ```
127
127
 
128
128
  #### options.wrapper
@@ -153,15 +153,10 @@ compiler(str, { wrapper: 'article' });
153
153
  To get an array of children back without a wrapper, set `wrapper` to `null`. This is particularly useful when using `compiler(…)` directly.
154
154
 
155
155
  ```jsx
156
- compiler('One\n\nTwo\n\nThree', { wrapper: null });
156
+ compiler('One\n\nTwo\n\nThree', { wrapper: null })
157
157
 
158
158
  // returns
159
-
160
- [
161
- (<p>One</p>),
162
- (<p>Two</p>),
163
- (<p>Three</p>)
164
- ]
159
+ ;[<p>One</p>, <p>Two</p>, <p>Three</p>]
165
160
  ```
166
161
 
167
162
  To render children at the same DOM level as `<Markdown>` with no HTML wrapper, set `wrapper` to `React.Fragment`. This will still wrap your children in a React node for the purposes of rendering, but the wrapper element won't show up in the DOM.
@@ -186,32 +181,30 @@ By default, the compiler does not wrap the rendered contents if there is only a
186
181
  Pass the `options.overrides` prop to the compiler or `<Markdown>` component to seamlessly revise the rendered representation of any HTML tag. You can choose to change the component itself, add/change props, or both.
187
182
 
188
183
  ```jsx
189
- import Markdown from 'markdown-to-jsx';
190
- import React from 'react';
191
- import { render } from 'react-dom';
184
+ import Markdown from 'markdown-to-jsx'
185
+ import React from 'react'
186
+ import { render } from 'react-dom'
192
187
 
193
188
  // surprise, it's a div instead!
194
- const MyParagraph = ({ children, ...props }) => (
195
- <div {...props}>{children}</div>
196
- );
189
+ const MyParagraph = ({ children, ...props }) => <div {...props}>{children}</div>
197
190
 
198
191
  render(
199
- <Markdown
200
- options={{
201
- overrides: {
202
- h1: {
203
- component: MyParagraph,
204
- props: {
205
- className: 'foo',
206
- },
207
- },
208
- },
209
- }}
210
- >
211
- # Hello world!
212
- </Markdown>,
213
- document.body
214
- );
192
+ <Markdown
193
+ options={{
194
+ overrides: {
195
+ h1: {
196
+ component: MyParagraph,
197
+ props: {
198
+ className: 'foo',
199
+ },
200
+ },
201
+ },
202
+ }}
203
+ >
204
+ # Hello world!
205
+ </Markdown>,
206
+ document.body
207
+ )
215
208
 
216
209
  /*
217
210
  renders:
@@ -234,19 +227,19 @@ If you only wish to provide a component override, a simplified syntax is availab
234
227
 
235
228
  Depending on the type of element, there are some props that must be preserved to ensure the markdown is converted as intended. They are:
236
229
 
237
- - `a`: `title`, `href`
238
- - `img`: `title`, `alt`, `src`
239
- - `input[type="checkbox"]`: `checked`, `readonly` (specifically, the one rendered by a GFM task list)
240
- - `ol`: `start`
241
- - `td`: `style`
242
- - `th`: `style`
230
+ - `a`: `title`, `href`
231
+ - `img`: `title`, `alt`, `src`
232
+ - `input[type="checkbox"]`: `checked`, `readonly` (specifically, the one rendered by a GFM task list)
233
+ - `ol`: `start`
234
+ - `td`: `style`
235
+ - `th`: `style`
243
236
 
244
237
  Any conflicts between passed `props` and the specific properties above will be resolved in favor of `markdown-to-jsx`'s code.
245
238
 
246
239
  Some element mappings are a bit different from other libraries, in particular:
247
240
 
248
- - `span`: Used for inline text.
249
- - `code`: Used for inline code.
241
+ - `span`: Used for inline text.
242
+ - `code`: Used for inline code.
250
243
  - `pre > code`: Code blocks are a `code` element with a `pre` as its direct ancestor.
251
244
 
252
245
  #### options.overrides - Rendering Arbitrary React Components
@@ -256,11 +249,11 @@ One of the most interesting use cases enabled by the HTML syntax processing in `
256
249
  By adding an override for the components you plan to use in markdown documents, it's possible to dynamically render almost anything. One possible scenario could be writing documentation:
257
250
 
258
251
  ```jsx
259
- import Markdown from 'markdown-to-jsx';
260
- import React from 'react';
261
- import { render } from 'react-dom';
252
+ import Markdown from 'markdown-to-jsx'
253
+ import React from 'react'
254
+ import { render } from 'react-dom'
262
255
 
263
- import DatePicker from './date-picker';
256
+ import DatePicker from './date-picker'
264
257
 
265
258
  const md = `
266
259
  # DatePicker
@@ -269,21 +262,21 @@ The DatePicker works by supplying a date to bias towards,
269
262
  as well as a default timezone.
270
263
 
271
264
  <DatePicker biasTowardDateTime="2017-12-05T07:39:36.091Z" timezone="UTC+5" />
272
- `;
265
+ `
273
266
 
274
267
  render(
275
- <Markdown
276
- children={md}
277
- options={{
278
- overrides: {
279
- DatePicker: {
280
- component: DatePicker,
281
- },
282
- },
283
- }}
284
- />,
285
- document.body
286
- );
268
+ <Markdown
269
+ children={md}
270
+ options={{
271
+ overrides: {
272
+ DatePicker: {
273
+ component: DatePicker,
274
+ },
275
+ },
276
+ }}
277
+ />,
278
+ document.body
279
+ )
287
280
  ```
288
281
 
289
282
  `markdown-to-jsx` also handles JSX interpolation syntax, but in a minimal way to not introduce a potential attack vector. Interpolations are sent to the component as their raw string, which the consumer can then `eval()` or process as desired to their security needs.
@@ -291,11 +284,11 @@ render(
291
284
  In the following case, `DatePicker` could simply run `parseInt()` on the passed `startTime` for example:
292
285
 
293
286
  ```jsx
294
- import Markdown from 'markdown-to-jsx';
295
- import React from 'react';
296
- import { render } from 'react-dom';
287
+ import Markdown from 'markdown-to-jsx'
288
+ import React from 'react'
289
+ import { render } from 'react-dom'
297
290
 
298
- import DatePicker from './date-picker';
291
+ import DatePicker from './date-picker'
299
292
 
300
293
  const md = `
301
294
  # DatePicker
@@ -308,40 +301,40 @@ as well as a default timezone.
308
301
  timezone="UTC+5"
309
302
  startTime={1514579720511}
310
303
  />
311
- `;
304
+ `
312
305
 
313
306
  render(
314
- <Markdown
315
- children={md}
316
- options={{
317
- overrides: {
318
- DatePicker: {
319
- component: DatePicker,
320
- },
321
- },
322
- }}
323
- />,
324
- document.body
325
- );
307
+ <Markdown
308
+ children={md}
309
+ options={{
310
+ overrides: {
311
+ DatePicker: {
312
+ component: DatePicker,
313
+ },
314
+ },
315
+ }}
316
+ />,
317
+ document.body
318
+ )
326
319
  ```
327
320
 
328
321
  Another possibility is to use something like [recompose's `withProps()` HOC](https://github.com/acdlite/recompose/blob/main/docs/API.md#withprops) to create various pregenerated scenarios and then reference them by name in the markdown:
329
322
 
330
323
  ```jsx
331
- import Markdown from 'markdown-to-jsx';
332
- import React from 'react';
333
- import { render } from 'react-dom';
334
- import withProps from 'recompose/withProps';
324
+ import Markdown from 'markdown-to-jsx'
325
+ import React from 'react'
326
+ import { render } from 'react-dom'
327
+ import withProps from 'recompose/withProps'
335
328
 
336
- import DatePicker from './date-picker';
329
+ import DatePicker from './date-picker'
337
330
 
338
331
  const DecemberDatePicker = withProps({
339
- range: {
340
- start: new Date('2017-12-01'),
341
- end: new Date('2017-12-31'),
342
- },
343
- timezone: 'UTC+5',
344
- })(DatePicker);
332
+ range: {
333
+ start: new Date('2017-12-01'),
334
+ end: new Date('2017-12-31'),
335
+ },
336
+ timezone: 'UTC+5',
337
+ })(DatePicker)
345
338
 
346
339
  const md = `
347
340
  # DatePicker
@@ -358,20 +351,20 @@ as well as a default timezone.
358
351
  Here's an example of a DatePicker pre-set to only the month of December:
359
352
 
360
353
  <DecemberDatePicker />
361
- `;
354
+ `
362
355
 
363
356
  render(
364
- <Markdown
365
- children={md}
366
- options={{
367
- overrides: {
368
- DatePicker,
369
- DecemberDatePicker,
370
- },
371
- }}
372
- />,
373
- document.body
374
- );
357
+ <Markdown
358
+ children={md}
359
+ options={{
360
+ overrides: {
361
+ DatePicker,
362
+ DecemberDatePicker,
363
+ },
364
+ }}
365
+ />,
366
+ document.body
367
+ )
375
368
  ```
376
369
 
377
370
  #### options.createElement - Custom React.createElement behavior
@@ -379,57 +372,62 @@ render(
379
372
  Sometimes, you might want to override the `React.createElement` default behavior to hook into the rendering process before the JSX gets rendered. This might be useful to add extra children or modify some props based on runtime conditions. The function mirrors the `React.createElement` function, so the params are [`type, [props], [...children]`](https://reactjs.org/docs/react-api.html#createelement):
380
373
 
381
374
  ```javascript
382
- import Markdown from 'markdown-to-jsx';
383
- import React from 'react';
384
- import { render } from 'react-dom';
375
+ import Markdown from 'markdown-to-jsx'
376
+ import React from 'react'
377
+ import { render } from 'react-dom'
385
378
 
386
379
  const md = `
387
380
  # Hello world
388
- `;
381
+ `
389
382
 
390
383
  render(
391
- <Markdown
392
- children={md}
393
- options={{
394
- createElement(type, props, children) {
395
- return (
396
- <div className="parent">
397
- {React.createElement(type, props, children)}
398
- </div>
399
- );
400
- },
401
- }}
402
- />,
403
- document.body
404
- );
384
+ <Markdown
385
+ children={md}
386
+ options={{
387
+ createElement(type, props, children) {
388
+ return (
389
+ <div className="parent">
390
+ {React.createElement(type, props, children)}
391
+ </div>
392
+ )
393
+ },
394
+ }}
395
+ />,
396
+ document.body
397
+ )
405
398
  ```
406
399
 
400
+ #### options.enforceAtxHeadings
401
+
402
+ Forces the compiler to have space between hash sign `#` and the header text which is explicitly stated in the most of the [markdown specs](https://github.github.com/gfm/#atx-heading).
403
+
404
+ > The opening sequence of `#` characters must be followed by a space or by the end of line.
405
+
407
406
  #### options.slugify
408
407
 
409
408
  By default, a [lightweight deburring function](https://github.com/probablyup/markdown-to-jsx/blob/bc2f57412332dc670f066320c0f38d0252e0f057/index.js#L261-L275) is used to generate an HTML id from headings. You can override this by passing a function to `options.slugify`. This is helpful when you are using non-alphanumeric characters (e.g. Chinese or Japanese characters) in headings. For example:
410
409
 
411
410
  ```jsx
412
- <Markdown options={{ slugify: str => str }}># 中文</Markdown>;
411
+ ;<Markdown options={{ slugify: str => str }}># 中文</Markdown>
413
412
 
414
413
  // or
415
414
 
416
- compiler('# 中文', { slugify: str => str });
415
+ compiler('# 中文', { slugify: str => str })
417
416
 
418
417
  // renders:
419
-
420
- <h1 id="中文">中文</h1>
418
+ ;<h1 id="中文">中文</h1>
421
419
  ```
422
420
 
423
421
  #### options.namedCodesToUnicode
424
422
 
425
423
  By default only a couple of named html codes are converted to unicode characters:
426
424
 
427
- * `&` (`&amp;`)
428
- * `'` (`&apos;`)
429
- * `>` (`&gt;`)
430
- * `<` (`&lt;`)
431
- * ` ` (`&nbsp;`)
432
- * `"` (`&quot;`)
425
+ - `&` (`&amp;`)
426
+ - `'` (`&apos;`)
427
+ - `>` (`&gt;`)
428
+ - `<` (`&lt;`)
429
+ - ` ` (`&nbsp;`)
430
+ - `"` (`&quot;`)
433
431
 
434
432
  Some projects require to extend this map of named codes and unicode characters. To customize this list with additional html codes pass the option namedCodesToUnicode as object with the code names needed as in the example below:
435
433
 
@@ -437,6 +435,7 @@ Some projects require to extend this map of named codes and unicode characters.
437
435
  <Markdown options={{ namedCodesToUnicode: {
438
436
  le: '\u2264',
439
437
  ge: '\u2265',
438
+ '#39': '\u0027',
440
439
  } }}>This text is &le; than this text.</Markdown>;
441
440
 
442
441
  // or
@@ -444,6 +443,7 @@ Some projects require to extend this map of named codes and unicode characters.
444
443
  compiler('This text is &le; than this text.', namedCodesToUnicode: {
445
444
  le: '\u2264',
446
445
  ge: '\u2265',
446
+ '#39': '\u0027',
447
447
  });
448
448
 
449
449
  // renders:
@@ -471,30 +471,31 @@ compiler('This text has <span>html</span> in it but it won't be rendered', { dis
471
471
 
472
472
  ### Syntax highlighting
473
473
 
474
- Some syntax highlighters require you to specify the language. The language of the code fence is
474
+ Some syntax highlighters require you to specify the language. The language of the code fence is
475
475
  forwarded in the className prop of the element used for `<code>`:
476
476
 
477
477
  ```jsx
478
- const Code = ({className, children}) => {
479
- const language = className.replace("lang-", "");
478
+ const Code = ({ className, children }) => {
479
+ const language = className.replace('lang-', '')
480
480
 
481
481
  return (
482
482
  <SyntaxHighlighter language={language}>
483
483
  <code>{children}</code>
484
484
  </SyntaxHighlighter>
485
- );
485
+ )
486
486
  }
487
487
  ```
488
+
488
489
  ### Getting the smallest possible bundle size
489
490
 
490
491
  Many development conveniences are placed behind `process.env.NODE_ENV !== "production"` conditionals. When bundling your app, it's a good idea to replace these code snippets such that a minifier (like uglify) can sweep them away and leave a smaller overall bundle.
491
492
 
492
493
  Here are instructions for some of the popular bundlers:
493
494
 
494
- - [webpack](https://webpack.js.org/guides/production/#specify-the-environment)
495
- - [browserify plugin](https://github.com/hughsk/envify)
496
- - [parcel](https://parceljs.org/production.html)
497
- - [fuse-box](http://fuse-box.org/plugins/replace-plugin#notes)
495
+ - [webpack](https://webpack.js.org/guides/production/#specify-the-environment)
496
+ - [browserify plugin](https://github.com/hughsk/envify)
497
+ - [parcel](https://parceljs.org/production.html)
498
+ - [fuse-box](http://fuse-box.org/plugins/replace-plugin#notes)
498
499
 
499
500
  ### Usage with Preact
500
501
 
@@ -507,9 +508,7 @@ Everything will work just fine! Simply [Alias `react` to `preact/compat`](https:
507
508
  People usually write HTML like this:
508
509
 
509
510
  ```html
510
- <div>
511
- Hey, how are you?
512
- </div>
511
+ <div>Hey, how are you?</div>
513
512
  ```
514
513
 
515
514
  Note the leading spaces before the inner content. This sort of thing unfortunately clashes with existing markdown syntaxes since 4 spaces === a code block and other similar collisions.
@@ -517,11 +516,7 @@ Note the leading spaces before the inner content. This sort of thing unfortunate
517
516
  To get around this, `markdown-to-jsx` left-trims approximately as much whitespace as the first line inside the HTML block. So for example:
518
517
 
519
518
  ```html
520
- <div>
521
- # Hello
522
-
523
- How are you?
524
- </div>
519
+ <div># Hello How are you?</div>
525
520
  ```
526
521
 
527
522
  The two leading spaces in front of "# Hello" would be left-trimmed from all lines inside the HTML block. In the event that there are varying amounts of indentation, only the amount of the first line is trimmed.
@@ -540,24 +535,24 @@ The two leading spaces in front of "# Hello" would be left-trimmed from all line
540
535
 
541
536
 
542
537
 
543
- ```md
538
+ ````md
544
539
  <div>
545
540
  ```js
546
541
  var some = code();
547
542
  ``\`
548
543
  </div>
549
- ```
544
+ ````
550
545
 
551
546
  ## Using The Compiler Directly
552
547
 
553
548
  If desired, the compiler function is a "named" export on the `markdown-to-jsx` module:
554
549
 
555
550
  ```jsx
556
- import { compiler } from 'markdown-to-jsx';
557
- import React from 'react';
558
- import { render } from 'react-dom';
551
+ import { compiler } from 'markdown-to-jsx'
552
+ import React from 'react'
553
+ import { render } from 'react-dom'
559
554
 
560
- render(compiler('# Hello world!'), document.body);
555
+ render(compiler('# Hello world!'), document.body)
561
556
 
562
557
  /*
563
558
  renders:
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ function n(n){if(n&&n._)return n;var t=Object.create(null);return n&&Object.keys(n).forEach(function(r){if("default"!==r){var e=Object.getOwnPropertyDescriptor(n,r);Object.defineProperty(t,r,e.get?e:{enumerable:!0,get:function(){return n[r]}})}}),t.default=n,t}var t=/*#__PURE__*/n(require("react"));function r(){return r=Object.assign?Object.assign.bind():function(n){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(n[e]=r[e])}return n},r.apply(this,arguments)}var e=["children","options"],u=["allowFullScreen","allowTransparency","autoComplete","autoFocus","autoPlay","cellPadding","cellSpacing","charSet","className","classId","colSpan","contentEditable","contextMenu","crossOrigin","encType","formAction","formEncType","formMethod","formNoValidate","formTarget","frameBorder","hrefLang","inputMode","keyParams","keyType","marginHeight","marginWidth","maxLength","mediaGroup","minLength","noValidate","radioGroup","readOnly","rowSpan","spellCheck","srcDoc","srcLang","srcSet","tabIndex","useMap"].reduce(function(n,t){return n[t.toLowerCase()]=t,n},{for:"htmlFor"}),o={amp:"&",apos:"'",gt:">",lt:"<",nbsp:" ",quot:"“"},i=["style","script"],c=/([-A-Z0-9_:]+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|(?:\{((?:\\.|{[^}]*?}|[^}])*)\})))?/gi,a=/mailto:/i,f=/\n{2,}$/,l=/^( *>[^\n]+(\n[^\n]+)*\n*)+\n{2,}/,v=/^ *> ?/gm,s=/^ {2,}\n/,d=/^(?:( *[-*_])){3,} *(?:\n *)+\n/,y=/^\s*(`{3,}|~{3,}) *(\S+)?([^\n]*?)?\n([\s\S]+?)\s*\1 *(?:\n *)*\n?/,g=/^(?: {4}[^\n]+\n*)+(?:\n *)+\n?/,p=/^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,k=/^(?:\n *)*\n/,m=/\r\n?/g,S=/^\[\^([^\]]+)](:.*)\n/,_=/^\[\^([^\]]+)]/,h=/\f/g,b=/^\s*?\[(x|\s)\]/,x=/^ *(#{1,6}) *([^\n]+?)(?: +#*)?(?:\n *)*(?:\n|$)/,$=/^ *(#{1,6}) +([^\n]+?)(?: +#*)?(?:\n *)*(?:\n|$)/,O=/^([^\n]+)\n *(=|-){3,} *(?:\n *)+\n/,B=/^ *(?!<[a-z][^ >/]* ?\/>)<([a-z][^ >/]*) ?([^>]*)\/{0}>\n?(\s*(?:<\1[^>]*?>[\s\S]*?<\/\1>|(?!<\1)[\s\S])*?)<\/\1>\n*/i,j=/&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});/gi,z=/^<!--[\s\S]*?(?:-->)/,w=/^(data|aria|x)-[a-z_][a-z\d_.-]*$/,A=/^ *<([a-z][a-z0-9:]*)(?:\s+((?:<.*?>|[^>])*))?\/?>(?!<\/\1>)(\s*\n)?/i,M=/^\{.*\}$/,E=/^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,L=/^<([^ >]+@[^ >]+)>/,F=/^<([^ >]+:\/[^ >]+)>/,I=/-([a-z])?/gi,R=/^(.*\|?.*)\n *(\|? *[-:]+ *\|[-| :]*)\n((?:.*\|.*\n)*)\n?/,T=/^\[([^\]]*)\]:\s+<?([^\s>]+)>?\s*("([^"]*)")?/,C=/^!\[([^\]]*)\] ?\[([^\]]*)\]/,D=/^\[([^\]]*)\] ?\[([^\]]*)\]/,H=/(\[|\])/g,N=/(\n|^[-*]\s|^#|^ {2,}|^-{2,}|^>\s)/,P=/\t/g,Z=/^ *\| */,G=/(^ *\||\| *$)/g,q=/ *$/,U=/^ *:-+: *$/,V=/^ *:-+ *$/,W=/^ *-+: *$/,Q=/^([*_])\1((?:\[.*?\][([].*?[)\]]|<.*?>(?:.*?<.*?>)?|`.*?`|~+.*?~+|.)*?)\1\1(?!\1)/,X=/^([*_])((?:\[.*?\][([].*?[)\]]|<.*?>(?:.*?<.*?>)?|`.*?`|~+.*?~+|.)*?)\1(?!\1|\w)/,J=/^==((?:\[.*?\]|<.*?>(?:.*?<.*?>)?|`.*?`|.)*?)==/,K=/^~~((?:\[.*?\]|<.*?>(?:.*?<.*?>)?|`.*?`|.)*?)~~/,Y=/^\\([^0-9A-Za-z\s])/,nn=/^[\s\S]+?(?=[^0-9A-Z\s\u00c0-\uffff&#;.()'"]|\d+\.|\n\n| {2,}\n|\w+:\S|$)/i,tn=/^\n+/,rn=/^([ \t]*)/,en=/\\([^\\])/g,un=/ *\n+$/,on=/(?:^|\n)( *)$/,cn="(?:\\d+\\.)",an="(?:[*+-])";function fn(n){return"( *)("+(1===n?cn:an)+") +"}var ln=fn(1),vn=fn(2);function sn(n){return new RegExp("^"+(1===n?ln:vn))}var dn=sn(1),yn=sn(2);function gn(n){return new RegExp("^"+(1===n?ln:vn)+"[^\\n]*(?:\\n(?!\\1"+(1===n?cn:an)+" )[^\\n]*)*(\\n|$)","gm")}var pn=gn(1),kn=gn(2);function mn(n){var t=1===n?cn:an;return new RegExp("^( *)("+t+") [\\s\\S]+?(?:\\n{2,}(?! )(?!\\1"+t+" (?!"+t+" ))\\n*|\\s*\\n*$)")}var Sn=mn(1),_n=mn(2);function hn(n,t){var r=1===t,e=r?Sn:_n,u=r?pn:kn,o=r?dn:yn;return{t:function(n,t,r){var u=on.exec(r);return u&&(t.o||!t.u&&!t.i)?e.exec(n=u[1]+n):null},q:Nn.HIGH,l:function(n,t,e){var i=r?+n[2]:void 0,c=n[0].replace(f,"\n").match(u),a=!1;return{p:c.map(function(n,r){var u=o.exec(n)[0].length,i=new RegExp("^ {1,"+u+"}","gm"),f=n.replace(i,"").replace(o,""),l=r===c.length-1,v=-1!==f.indexOf("\n\n")||l&&a;a=v;var s,d=e.u,y=e.o;e.o=!0,v?(e.u=!1,s=f.replace(un,"\n\n")):(e.u=!0,s=f.replace(un,""));var g=t(s,e);return e.u=d,e.o=y,g}),m:r,g:i}},v:function(t,r,e){return n(t.m?"ol":"ul",{key:e.h,start:t.g},t.p.map(function(t,u){return n("li",{key:u},r(t,e))}))}}}var bn=/^\[([^\]]*)]\( *((?:\([^)]*\)|[^() ])*) *"?([^)"]*)?"?\)/,xn=/^!\[([^\]]*)]\( *((?:\([^)]*\)|[^() ])*) *"?([^)"]*)?"?\)/,$n=[l,y,g,x,O,$,z,R,pn,Sn,kn,_n],On=[].concat($n,[/^[^\n]+(?: \n|\n{2,})/,B,A]);function Bn(n){return n.replace(/[ÀÁÂÃÄÅàáâãä忯]/g,"a").replace(/[çÇ]/g,"c").replace(/[ðÐ]/g,"d").replace(/[ÈÉÊËéèêë]/g,"e").replace(/[ÏïÎîÍíÌì]/g,"i").replace(/[Ññ]/g,"n").replace(/[øØœŒÕõÔôÓóÒò]/g,"o").replace(/[ÜüÛûÚúÙù]/g,"u").replace(/[ŸÿÝý]/g,"y").replace(/[^a-z0-9- ]/gi,"").replace(/ /gi,"-").toLowerCase()}function jn(n){return W.test(n)?"right":U.test(n)?"center":V.test(n)?"left":null}function zn(n,t,r){var e=r.k;r.k=!0;var u=t(n.trim(),r);r.k=e;var o=[[]];return u.forEach(function(n,t){"tableSeparator"===n.type?0!==t&&t!==u.length-1&&o.push([]):("text"!==n.type||null!=u[t+1]&&"tableSeparator"!==u[t+1].type||(n.S=n.S.replace(q,"")),o[o.length-1].push(n))}),o}function wn(n,t,r){r.u=!0;var e=zn(n[1],t,r),u=n[2].replace(G,"").split("|").map(jn),o=function(n,t,r){return n.trim().split("\n").map(function(n){return zn(n,t,r)})}(n[3],t,r);return r.u=!1,{$:u,A:o,L:e,type:"table"}}function An(n,t){return null==n.$[t]?{}:{textAlign:n.$[t]}}function Mn(n){return function(t,r){return r.u?n.exec(t):null}}function En(n){return function(t,r){return r.u||r.i?n.exec(t):null}}function Ln(n){return function(t,r){return r.u||r.i?null:n.exec(t)}}function Fn(n){return function(t){return n.exec(t)}}function In(n,t,r){if(t.u||t.i)return null;if(r&&!r.endsWith("\n"))return null;var e="";n.split("\n").every(function(n){return!$n.some(function(t){return t.test(n)})&&(e+=n+"\n",n.trim())});var u=e.trimEnd();return""==u?null:[e,u]}function Rn(n){try{if(decodeURIComponent(n).replace(/[^A-Za-z0-9/:]/g,"").match(/^\s*(javascript|vbscript|data(?!:image)):/i))return}catch(n){return null}return n}function Tn(n){return n.replace(en,"$1")}function Cn(n,t,r){var e=r.u||!1,u=r.i||!1;r.u=!0,r.i=!0;var o=n(t,r);return r.u=e,r.i=u,o}function Dn(n,t,r){var e=r.u||!1,u=r.i||!1;r.u=!1,r.i=!0;var o=n(t,r);return r.u=e,r.i=u,o}function Hn(n,t,r){return r.u=!1,n(t,r)}var Nn,Pn,Zn=function(n,t,r){return{S:Cn(t,n[1],r)}};function Gn(){return{}}function qn(){return null}function Un(){return[].slice.call(arguments).filter(Boolean).join(" ")}function Vn(n,t,r){for(var e=n,u=t.split(".");u.length&&void 0!==(e=e[u[0]]);)u.shift();return e||r}function Wn(n,t){var r=Vn(t,n);return r?"function"==typeof r||"object"==typeof r&&"render"in r?r:Vn(t,n+".component",n):n}function Qn(n,e){void 0===e&&(e={}),e.overrides=e.overrides||{},e.slugify=e.slugify||Bn,e.namedCodesToUnicode=e.namedCodesToUnicode?r({},o,e.namedCodesToUnicode):o;var f=e.createElement||t.createElement;function G(n,t){var u=Vn(e.overrides,n+".props",{});return f.apply(void 0,[Wn(n,e.overrides),r({},t,u,{className:Un(null==t?void 0:t.className,u.className)||void 0})].concat([].slice.call(arguments,2)))}function q(n){var r=!1;e.forceInline?r=!0:e.forceBlock||(r=!1===N.test(n));for(var u=an(cn(r?n:n.trimEnd().replace(tn,"")+"\n\n",{u:r}));"string"==typeof u[u.length-1]&&!u[u.length-1].trim();)u.pop();if(null===e.wrapper)return u;var o,i=e.wrapper||(r?"span":"div");if(u.length>1||e.forceWrapper)o=u;else{if(1===u.length)return"string"==typeof(o=u[0])?G("span",{key:"outer"},o):o;o=null}return t.createElement(i,{key:"outer"},o)}function U(n){var r=n.match(c);return r?r.reduce(function(n,r,e){var o,i=r.indexOf("=");if(-1!==i){var c=(o=r.slice(0,i),-1!==o.indexOf("-")&&null===o.match(w)&&(o=o.replace(I,function(n,t){return t.toUpperCase()})),o).trim(),a=function(n){var t=n[0];return('"'===t||"'"===t)&&n.length>=2&&n[n.length-1]===t?n.slice(1,-1):n}(r.slice(i+1).trim()),f=u[c]||c,l=n[f]=function(n,t){return"style"===n?t.split(/;\s?/).reduce(function(n,t){var r=t.slice(0,t.indexOf(":"));return n[r.replace(/(-[a-z])/g,function(n){return n[1].toUpperCase()})]=t.slice(r.length+1).trim(),n},{}):"href"===n?Rn(t):(t.match(M)&&(t=t.slice(1,t.length-1)),"true"===t||"false"!==t&&t)}(c,a);"string"==typeof l&&(B.test(l)||A.test(l))&&(n[f]=t.cloneElement(q(l.trim()),{key:e}))}else"style"!==r&&(n[u[r]||r]=!0);return n},{}):null}var V=[],W={},en={blockQuote:{t:Ln(l),q:Nn.HIGH,l:function(n,t,r){return{S:t(n[0].replace(v,""),r)}},v:function(n,t,r){return G("blockquote",{key:r.h},t(n.S,r))}},breakLine:{t:Fn(s),q:Nn.HIGH,l:Gn,v:function(n,t,r){return G("br",{key:r.h})}},breakThematic:{t:Ln(d),q:Nn.HIGH,l:Gn,v:function(n,t,r){return G("hr",{key:r.h})}},codeBlock:{t:Ln(g),q:Nn.MAX,l:function(n){return{S:n[0].replace(/^ {4}/gm,"").replace(/\n+$/,""),M:void 0}},v:function(n,t,e){return G("pre",{key:e.h},G("code",r({},n.O,{className:n.M?"lang-"+n.M:""}),n.S))}},codeFenced:{t:Ln(y),q:Nn.MAX,l:function(n){return{O:U(n[3]||""),S:n[4],M:n[2]||void 0,type:"codeBlock"}}},codeInline:{t:En(p),q:Nn.LOW,l:function(n){return{S:n[2]}},v:function(n,t,r){return G("code",{key:r.h},n.S)}},footnote:{t:Ln(S),q:Nn.MAX,l:function(n){return V.push({I:n[2],j:n[1]}),{}},v:qn},footnoteReference:{t:Mn(_),q:Nn.HIGH,l:function(n){return{S:n[1],B:"#"+e.slugify(n[1])}},v:function(n,t,r){return G("a",{key:r.h,href:Rn(n.B)},G("sup",{key:r.h},n.S))}},gfmTask:{t:Mn(b),q:Nn.HIGH,l:function(n){return{R:"x"===n[1].toLowerCase()}},v:function(n,t,r){return G("input",{checked:n.R,key:r.h,readOnly:!0,type:"checkbox"})}},heading:{t:Ln(e.enforceAtxHeadings?$:x),q:Nn.HIGH,l:function(n,t,r){return{S:Cn(t,n[2],r),T:e.slugify(n[2]),C:n[1].length}},v:function(n,t,r){return G("h"+n.C,{id:n.T,key:r.h},t(n.S,r))}},headingSetext:{t:Ln(O),q:Nn.MAX,l:function(n,t,r){return{S:Cn(t,n[1],r),C:"="===n[2]?1:2,type:"heading"}}},htmlComment:{t:Fn(z),q:Nn.HIGH,l:function(){return{}},v:qn},image:{t:En(xn),q:Nn.HIGH,l:function(n){return{D:n[1],B:Tn(n[2]),F:n[3]}},v:function(n,t,r){return G("img",{key:r.h,alt:n.D||void 0,title:n.F||void 0,src:Rn(n.B)})}},link:{t:Mn(bn),q:Nn.LOW,l:function(n,t,r){return{S:Dn(t,n[1],r),B:Tn(n[2]),F:n[3]}},v:function(n,t,r){return G("a",{key:r.h,href:Rn(n.B),title:n.F},t(n.S,r))}},linkAngleBraceStyleDetector:{t:Mn(F),q:Nn.MAX,l:function(n){return{S:[{S:n[1],type:"text"}],B:n[1],type:"link"}}},linkBareUrlDetector:{t:function(n,t){return t.N?null:Mn(E)(n,t)},q:Nn.MAX,l:function(n){return{S:[{S:n[1],type:"text"}],B:n[1],F:void 0,type:"link"}}},linkMailtoDetector:{t:Mn(L),q:Nn.MAX,l:function(n){var t=n[1],r=n[1];return a.test(r)||(r="mailto:"+r),{S:[{S:t.replace("mailto:",""),type:"text"}],B:r,type:"link"}}},orderedList:hn(G,1),unorderedList:hn(G,2),newlineCoalescer:{t:Ln(k),q:Nn.LOW,l:Gn,v:function(){return"\n"}},paragraph:{t:In,q:Nn.LOW,l:Zn,v:function(n,t,r){return G("p",{key:r.h},t(n.S,r))}},ref:{t:Mn(T),q:Nn.MAX,l:function(n){return W[n[1]]={B:n[2],F:n[4]},{}},v:qn},refImage:{t:En(C),q:Nn.MAX,l:function(n){return{D:n[1]||void 0,P:n[2]}},v:function(n,t,r){return G("img",{key:r.h,alt:n.D,src:Rn(W[n.P].B),title:W[n.P].F})}},refLink:{t:Mn(D),q:Nn.MAX,l:function(n,t,r){return{S:t(n[1],r),Z:t(n[0].replace(H,"\\$1"),r),P:n[2]}},v:function(n,t,r){return W[n.P]?G("a",{key:r.h,href:Rn(W[n.P].B),title:W[n.P].F},t(n.S,r)):G("span",{key:r.h},t(n.Z,r))}},table:{t:Ln(R),q:Nn.HIGH,l:wn,v:function(n,t,r){return G("table",{key:r.h},G("thead",null,G("tr",null,n.L.map(function(e,u){return G("th",{key:u,style:An(n,u)},t(e,r))}))),G("tbody",null,n.A.map(function(e,u){return G("tr",{key:u},e.map(function(e,u){return G("td",{key:u,style:An(n,u)},t(e,r))}))})))}},tableSeparator:{t:function(n,t){return t.k?(t.u=!0,Z.exec(n)):null},q:Nn.HIGH,l:function(){return{type:"tableSeparator"}},v:function(){return" | "}},text:{t:Fn(nn),q:Nn.MIN,l:function(n){return{S:n[0].replace(j,function(n,t){return e.namedCodesToUnicode[t]?e.namedCodesToUnicode[t]:n})}},v:function(n){return n.S}},textBolded:{t:En(Q),q:Nn.MED,l:function(n,t,r){return{S:t(n[2],r)}},v:function(n,t,r){return G("strong",{key:r.h},t(n.S,r))}},textEmphasized:{t:En(X),q:Nn.LOW,l:function(n,t,r){return{S:t(n[2],r)}},v:function(n,t,r){return G("em",{key:r.h},t(n.S,r))}},textEscaped:{t:En(Y),q:Nn.HIGH,l:function(n){return{S:n[1],type:"text"}}},textMarked:{t:En(J),q:Nn.LOW,l:Zn,v:function(n,t,r){return G("mark",{key:r.h},t(n.S,r))}},textStrikethroughed:{t:En(K),q:Nn.LOW,l:Zn,v:function(n,t,r){return G("del",{key:r.h},t(n.S,r))}}};!0!==e.disableParsingRawHTML&&(en.htmlBlock={t:Fn(B),q:Nn.HIGH,l:function(n,t,r){var e,u=n[3].match(rn),o=new RegExp("^"+u[1],"gm"),c=n[3].replace(o,""),a=(e=c,On.some(function(n){return n.test(e)})?Hn:Cn),f=n[1].toLowerCase(),l=-1!==i.indexOf(f);r.N=r.N||"a"===f;var v=l?n[3]:a(t,c,r);return r.N=!1,{O:U(n[2]),S:v,G:l,H:l?f:n[1]}},v:function(n,t,e){return G(n.H,r({key:e.h},n.O),n.G?n.S:t(n.S,e))}},en.htmlSelfClosing={t:Fn(A),q:Nn.HIGH,l:function(n){return{O:U(n[2]||""),H:n[1]}},v:function(n,t,e){return G(n.H,r({},n.O,{key:e.h}))}});var un,on,cn=function(n){var t=Object.keys(n);function r(e,u){for(var o=[],i="";e;)for(var c=0;c<t.length;){var a=t[c],f=n[a],l=f.t(e,u,i);if(l){var v=l[0];e=e.substring(v.length);var s=f.l(l,r,u);null==s.type&&(s.type=a),o.push(s),i=v;break}c++}return o}return t.sort(function(t,r){var e=n[t].q,u=n[r].q;return e!==u?e-u:t<r?-1:1}),function(n,t){return r(function(n){return n.replace(m,"\n").replace(h,"").replace(P," ")}(n),t)}}(en),an=(on=en,un=function(n,t,r){return on[n.type].v(n,t,r)},function n(t,r){if(void 0===r&&(r={}),Array.isArray(t)){for(var e=r.h,u=[],o=!1,i=0;i<t.length;i++){r.h=i;var c=n(t[i],r),a="string"==typeof c;a&&o?u[u.length-1]+=c:null!==c&&u.push(c),o=a}return r.h=e,u}return un(t,n,r)}),fn=q(n);return V.length?G("div",null,fn,G("footer",{key:"footer"},V.map(function(n){return G("div",{id:e.slugify(n.j),key:n.j},n.j,an(cn(n.I,{u:!0})))}))):fn}function Xn(n){var r=n.children,u=n.options,o=function(n,t){if(null==n)return{};var r,e,u={},o=Object.keys(n);for(e=0;e<o.length;e++)t.indexOf(r=o[e])>=0||(u[r]=n[r]);return u}(n,e);return t.cloneElement(Qn(r,u),o)}(Pn=Nn||(Nn={}))[Pn.MAX=0]="MAX",Pn[Pn.HIGH=1]="HIGH",Pn[Pn.MED=2]="MED",Pn[Pn.LOW=3]="LOW",Pn[Pn.MIN=4]="MIN",Object.assign(Xn,{compiler:Qn}),module.exports=Xn;
2
+ //# sourceMappingURL=index.cjs.map
@@ -1,22 +1,23 @@
1
- /// <reference types="react" />
2
- import { compiler } from './';
3
- declare const _default: import("react").FC<{
4
- [key: string]: any;
5
- children: string;
6
- options?: Partial<{
7
- createElement: (tag: string | import("react").FunctionComponent<{}> | import("react").ComponentClass<{}, any>, props: JSX.IntrinsicAttributes, ...children: import("react").ReactChild[]) => JSX.Element;
8
- disableParsingRawHTML: boolean;
9
- forceBlock: boolean;
10
- forceInline: boolean;
11
- namedCodesToUnicode: {
12
- [key: string]: string;
13
- };
14
- overrides: import("./").MarkdownToJSX.Overrides;
15
- wrapper: import("react").ElementType<any>;
16
- forceWrapper: boolean;
17
- slugify: (source: string) => string;
18
- }>;
19
- }> & {
20
- compiler: typeof compiler;
21
- };
22
- export default _default;
1
+ /// <reference types="react" />
2
+ import { compiler } from './';
3
+ declare const _default: import("react").FC<{
4
+ [key: string]: any;
5
+ children: string;
6
+ options?: Partial<{
7
+ createElement: (tag: string | import("react").FunctionComponent<{}> | import("react").ComponentClass<{}, any>, props: JSX.IntrinsicAttributes, ...children: import("react").ReactChild[]) => JSX.Element;
8
+ disableParsingRawHTML: boolean;
9
+ forceBlock: boolean;
10
+ forceInline: boolean;
11
+ namedCodesToUnicode: {
12
+ [key: string]: string;
13
+ };
14
+ overrides: import("./").MarkdownToJSX.Overrides;
15
+ wrapper: import("react").ElementType<any>;
16
+ forceWrapper: boolean;
17
+ slugify: (source: string) => string;
18
+ enforceAtxHeadings: boolean;
19
+ }>;
20
+ }> & {
21
+ compiler: typeof compiler;
22
+ };
23
+ export default _default;