markdown-to-jsx
Advanced tools
Comparing version 6.7.0 to 6.7.1
@@ -118,8 +118,7 @@ 'use strict'; | ||
var BREAK_THEMATIC_R = /^(?:( *[-*_]) *){3,}(?:\n *)+\n/; | ||
var CODE_BLOCK_FENCED_R = /^\s*(`{3,}|~{3,}) *(\S+)? *\n([\s\S]+?)\s*\1 *(?:\n *)+\n/; | ||
var CODE_BLOCK_R = /^(?: {4}[^\n]+\n*)+(?:\n *)+\n/; | ||
var CODE_BLOCK_FENCED_R = /^\s*(`{3,}|~{3,}) *(\S+)? *\n([\s\S]+?)\s*\1 *(?:\n *)+\n?/; | ||
var CODE_BLOCK_R = /^(?: {4}[^\n]+\n*)+(?:\n *)+\n?/; | ||
var CODE_INLINE_R = /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/; | ||
var CONSECUTIVE_NEWLINE_R = /^(?:\n *)*\n/; | ||
var CR_NEWLINE_R = /\r\n?/g; | ||
var DETECT_BLOCK_SYNTAX = /(^[-*] |^#+ ?\w|^ {2,}|^-{2,}|^> |^`{3})/m; | ||
var FOOTNOTE_R = /^\[\^(.*)\](:.*)\n/; | ||
@@ -129,3 +128,3 @@ var FOOTNOTE_REFERENCE_R = /^\[\^(.*)\]/; | ||
var GFM_TASK_R = /^\s*?\[(x|\s)\]/; | ||
var HEADING_R = /^ *(#{1,6}) *([^\n]+?) *#* *\n+/; | ||
var HEADING_R = /^ *(#{1,6}) *([^\n]+)\n{0,2}/; | ||
var HEADING_SETEXT_R = /^([^\n]+)\n *(=|-){3,} *(?:\n *)+\n/; | ||
@@ -155,3 +154,3 @@ | ||
*/ | ||
var HTML_BLOCK_ELEMENT_R = /^ *<([A-Za-z][^ >/]*) ?([^>]*)\/{0}>\s*((?:<\1[^>]*?>[\s\S]*?<\/\1>|(?!<\1)[\s\S])*?)<\/\1>\n*/; | ||
var HTML_BLOCK_ELEMENT_R = /^ *<([A-Za-z][^ >/]*) ?([^>]*)\/{0}>\n?(\s*(?:<\1[^>]*?>[\s\S]*?<\/\1>|(?!<\1)[\s\S])*?)<\/\1>\n*/; | ||
@@ -216,12 +215,3 @@ var HTML_COMMENT_R = /^<!--.*?-->/; | ||
/** | ||
* Indentation-significant syntaxes cannot be used inside arbitrary HTML at this time because | ||
* it's not clear if the indentation is intentional or just there from how the composer | ||
* laid things out. | ||
* | ||
* For code blocks, use fenced blocks instead (```). | ||
* | ||
* There's more detail on this in the README. | ||
*/ | ||
var TRIM_HTML = /^[ \t]*|[ \t]*$/gm; | ||
var HTML_LEFT_TRIM_AMOUNT_R = /^(\s*)/; | ||
@@ -261,2 +251,10 @@ var UNESCAPE_URL_R = /\\([^0-9A-Z\s])/gi; | ||
var BLOCK_SYNTAXES = [BLOCKQUOTE_R, CODE_BLOCK_R, CODE_BLOCK_FENCED_R, HEADING_R, HEADING_SETEXT_R, HTML_BLOCK_ELEMENT_R, HTML_COMMENT_R, HTML_SELF_CLOSING_ELEMENT_R, LIST_ITEM_R, LIST_R, NP_TABLE_R]; | ||
function containsBlockSyntax(input) { | ||
return BLOCK_SYNTAXES.some(function (r) { | ||
return r.test(input); | ||
}); | ||
} | ||
// based on https://stackoverflow.com/a/18123682/1141611 | ||
@@ -959,5 +957,10 @@ // not complete, but probably good enough | ||
parse: function parse(capture, _parse4, state) { | ||
var trimmed = capture[3].replace(TRIM_HTML, ''); | ||
var parseFunc = DETECT_BLOCK_SYNTAX.test(trimmed) ? parseBlock : parseInline; | ||
var _capture$3$match = capture[3].match(HTML_LEFT_TRIM_AMOUNT_R), | ||
whitespace = _capture$3$match[1]; | ||
var trimmer = new RegExp('^' + whitespace, 'gm'); | ||
var trimmed = capture[3].replace(trimmer, ''); | ||
var parseFunc = containsBlockSyntax(trimmed) ? parseBlock : parseInline; | ||
var noInnerParse = DO_NOT_PROCESS_HTML_ELEMENTS.indexOf(capture[1]) !== -1; | ||
@@ -964,0 +967,0 @@ |
@@ -104,8 +104,7 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var BREAK_THEMATIC_R = /^(?:( *[-*_]) *){3,}(?:\n *)+\n/; | ||
var CODE_BLOCK_FENCED_R = /^\s*(`{3,}|~{3,}) *(\S+)? *\n([\s\S]+?)\s*\1 *(?:\n *)+\n/; | ||
var CODE_BLOCK_R = /^(?: {4}[^\n]+\n*)+(?:\n *)+\n/; | ||
var CODE_BLOCK_FENCED_R = /^\s*(`{3,}|~{3,}) *(\S+)? *\n([\s\S]+?)\s*\1 *(?:\n *)+\n?/; | ||
var CODE_BLOCK_R = /^(?: {4}[^\n]+\n*)+(?:\n *)+\n?/; | ||
var CODE_INLINE_R = /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/; | ||
var CONSECUTIVE_NEWLINE_R = /^(?:\n *)*\n/; | ||
var CR_NEWLINE_R = /\r\n?/g; | ||
var DETECT_BLOCK_SYNTAX = /(^[-*] |^#+ ?\w|^ {2,}|^-{2,}|^> |^`{3})/m; | ||
var FOOTNOTE_R = /^\[\^(.*)\](:.*)\n/; | ||
@@ -115,3 +114,3 @@ var FOOTNOTE_REFERENCE_R = /^\[\^(.*)\]/; | ||
var GFM_TASK_R = /^\s*?\[(x|\s)\]/; | ||
var HEADING_R = /^ *(#{1,6}) *([^\n]+?) *#* *\n+/; | ||
var HEADING_R = /^ *(#{1,6}) *([^\n]+)\n{0,2}/; | ||
var HEADING_SETEXT_R = /^([^\n]+)\n *(=|-){3,} *(?:\n *)+\n/; | ||
@@ -141,3 +140,3 @@ | ||
*/ | ||
var HTML_BLOCK_ELEMENT_R = /^ *<([A-Za-z][^ >/]*) ?([^>]*)\/{0}>\s*((?:<\1[^>]*?>[\s\S]*?<\/\1>|(?!<\1)[\s\S])*?)<\/\1>\n*/; | ||
var HTML_BLOCK_ELEMENT_R = /^ *<([A-Za-z][^ >/]*) ?([^>]*)\/{0}>\n?(\s*(?:<\1[^>]*?>[\s\S]*?<\/\1>|(?!<\1)[\s\S])*?)<\/\1>\n*/; | ||
@@ -202,12 +201,3 @@ var HTML_COMMENT_R = /^<!--.*?-->/; | ||
/** | ||
* Indentation-significant syntaxes cannot be used inside arbitrary HTML at this time because | ||
* it's not clear if the indentation is intentional or just there from how the composer | ||
* laid things out. | ||
* | ||
* For code blocks, use fenced blocks instead (```). | ||
* | ||
* There's more detail on this in the README. | ||
*/ | ||
var TRIM_HTML = /^[ \t]*|[ \t]*$/gm; | ||
var HTML_LEFT_TRIM_AMOUNT_R = /^(\s*)/; | ||
@@ -247,2 +237,10 @@ var UNESCAPE_URL_R = /\\([^0-9A-Z\s])/gi; | ||
var BLOCK_SYNTAXES = [BLOCKQUOTE_R, CODE_BLOCK_R, CODE_BLOCK_FENCED_R, HEADING_R, HEADING_SETEXT_R, HTML_BLOCK_ELEMENT_R, HTML_COMMENT_R, HTML_SELF_CLOSING_ELEMENT_R, LIST_ITEM_R, LIST_R, NP_TABLE_R]; | ||
function containsBlockSyntax(input) { | ||
return BLOCK_SYNTAXES.some(function (r) { | ||
return r.test(input); | ||
}); | ||
} | ||
// based on https://stackoverflow.com/a/18123682/1141611 | ||
@@ -945,5 +943,10 @@ // not complete, but probably good enough | ||
parse: function parse(capture, _parse4, state) { | ||
var trimmed = capture[3].replace(TRIM_HTML, ''); | ||
var parseFunc = DETECT_BLOCK_SYNTAX.test(trimmed) ? parseBlock : parseInline; | ||
var _capture$3$match = capture[3].match(HTML_LEFT_TRIM_AMOUNT_R), | ||
whitespace = _capture$3$match[1]; | ||
var trimmer = new RegExp('^' + whitespace, 'gm'); | ||
var trimmed = capture[3].replace(trimmer, ''); | ||
var parseFunc = containsBlockSyntax(trimmed) ? parseBlock : parseInline; | ||
var noInnerParse = DO_NOT_PROCESS_HTML_ELEMENTS.indexOf(capture[1]) !== -1; | ||
@@ -950,0 +953,0 @@ |
45
index.js
@@ -100,8 +100,7 @@ /* @jsx h */ | ||
const BREAK_THEMATIC_R = /^(?:( *[-*_]) *){3,}(?:\n *)+\n/; | ||
const CODE_BLOCK_FENCED_R = /^\s*(`{3,}|~{3,}) *(\S+)? *\n([\s\S]+?)\s*\1 *(?:\n *)+\n/; | ||
const CODE_BLOCK_R = /^(?: {4}[^\n]+\n*)+(?:\n *)+\n/; | ||
const CODE_BLOCK_FENCED_R = /^\s*(`{3,}|~{3,}) *(\S+)? *\n([\s\S]+?)\s*\1 *(?:\n *)+\n?/; | ||
const CODE_BLOCK_R = /^(?: {4}[^\n]+\n*)+(?:\n *)+\n?/; | ||
const CODE_INLINE_R = /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/; | ||
const CONSECUTIVE_NEWLINE_R = /^(?:\n *)*\n/; | ||
const CR_NEWLINE_R = /\r\n?/g; | ||
const DETECT_BLOCK_SYNTAX = /(^[-*] |^#+ ?\w|^ {2,}|^-{2,}|^> |^`{3})/m; | ||
const FOOTNOTE_R = /^\[\^(.*)\](:.*)\n/; | ||
@@ -111,3 +110,3 @@ const FOOTNOTE_REFERENCE_R = /^\[\^(.*)\]/; | ||
const GFM_TASK_R = /^\s*?\[(x|\s)\]/; | ||
const HEADING_R = /^ *(#{1,6}) *([^\n]+?) *#* *\n+/; | ||
const HEADING_R = /^ *(#{1,6}) *([^\n]+)\n{0,2}/; | ||
const HEADING_SETEXT_R = /^([^\n]+)\n *(=|-){3,} *(?:\n *)+\n/; | ||
@@ -137,3 +136,3 @@ | ||
*/ | ||
const HTML_BLOCK_ELEMENT_R = /^ *<([A-Za-z][^ >/]*) ?([^>]*)\/{0}>\s*((?:<\1[^>]*?>[\s\S]*?<\/\1>|(?!<\1)[\s\S])*?)<\/\1>\n*/; | ||
const HTML_BLOCK_ELEMENT_R = /^ *<([A-Za-z][^ >/]*) ?([^>]*)\/{0}>\n?(\s*(?:<\1[^>]*?>[\s\S]*?<\/\1>|(?!<\1)[\s\S])*?)<\/\1>\n*/; | ||
@@ -198,12 +197,3 @@ const HTML_COMMENT_R = /^<!--.*?-->/; | ||
/** | ||
* Indentation-significant syntaxes cannot be used inside arbitrary HTML at this time because | ||
* it's not clear if the indentation is intentional or just there from how the composer | ||
* laid things out. | ||
* | ||
* For code blocks, use fenced blocks instead (```). | ||
* | ||
* There's more detail on this in the README. | ||
*/ | ||
const TRIM_HTML = /^[ \t]*|[ \t]*$/gm; | ||
const HTML_LEFT_TRIM_AMOUNT_R = /^(\s*)/ | ||
@@ -263,2 +253,20 @@ const UNESCAPE_URL_R = /\\([^0-9A-Z\s])/gi; | ||
const BLOCK_SYNTAXES = [ | ||
BLOCKQUOTE_R, | ||
CODE_BLOCK_R, | ||
CODE_BLOCK_FENCED_R, | ||
HEADING_R, | ||
HEADING_SETEXT_R, | ||
HTML_BLOCK_ELEMENT_R, | ||
HTML_COMMENT_R, | ||
HTML_SELF_CLOSING_ELEMENT_R, | ||
LIST_ITEM_R, | ||
LIST_R, | ||
NP_TABLE_R, | ||
]; | ||
function containsBlockSyntax (input) { | ||
return BLOCK_SYNTAXES.some(r => r.test(input)) | ||
} | ||
// based on https://stackoverflow.com/a/18123682/1141611 | ||
@@ -1034,4 +1042,7 @@ // not complete, but probably good enough | ||
parse(capture, parse, state) { | ||
const trimmed = capture[3].replace(TRIM_HTML, ''); | ||
const parseFunc = DETECT_BLOCK_SYNTAX.test(trimmed) | ||
const [, whitespace] = capture[3].match(HTML_LEFT_TRIM_AMOUNT_R) | ||
const trimmer = new RegExp(`^${whitespace}`, 'gm') | ||
const trimmed = capture[3].replace(trimmer, ''); | ||
const parseFunc = containsBlockSyntax(trimmed) | ||
? parseBlock | ||
@@ -1038,0 +1049,0 @@ : parseInline; |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "6.7.0", | ||
"version": "6.7.1", | ||
"engines": { | ||
@@ -9,0 +9,0 @@ "node": ">= 4" |
@@ -10,24 +10,23 @@ **markdown-to-jsx** | ||
- [Installation](#installation) | ||
- [Usage](#usage) | ||
- [Parsing Options](#parsing-options) | ||
- [options.forceBlock](#optionsforceblock) | ||
- [options.forceInline](#optionsforceinline) | ||
- [options.overrides - Override Any HTML Tag's Representation](#optionsoverrides---override-any-html-tags-representation) | ||
- [options.overrides - Rendering Arbitrary React Components](#optionsoverrides---rendering-arbitrary-react-components) | ||
- [options.createElement - Custom React.createElement behavior](#optionscreateelement---custom-reactcreateelement-behavior) | ||
- [options.slugify](#optionsslugify) | ||
- [Getting the smallest possible bundle size](#getting-the-smallest-possible-bundle-size) | ||
- [Usage with Preact](#usage-with-preact) | ||
- [Gotchas](#gotchas) | ||
- [Significant indentation inside arbitrary HTML](#significant-indentation-inside-arbitrary-html) | ||
- [Code blocks](#code-blocks) | ||
- [Nested lists](#nested-lists) | ||
- [Using The Compiler Directly](#using-the-compiler-directly) | ||
- [Changelog](#changelog) | ||
- [Donate](#donate) | ||
- [Credits](#credits) | ||
- [Contributors](#contributors) | ||
- [Backers](#backers) | ||
- [Sponsors](#sponsors) | ||
- [Installation](#installation) | ||
- [Usage](#usage) | ||
- [Parsing Options](#parsing-options) | ||
- [options.forceBlock](#optionsforceblock) | ||
- [options.forceInline](#optionsforceinline) | ||
- [options.overrides - Override Any HTML Tag's Representation](#optionsoverrides---override-any-html-tags-representation) | ||
- [options.overrides - Rendering Arbitrary React Components](#optionsoverrides---rendering-arbitrary-react-components) | ||
- [options.createElement - Custom React.createElement behavior](#optionscreateelement---custom-reactcreateelement-behavior) | ||
- [options.slugify](#optionsslugify) | ||
- [Getting the smallest possible bundle size](#getting-the-smallest-possible-bundle-size) | ||
- [Usage with Preact](#usage-with-preact) | ||
- [Gotchas](#gotchas) | ||
- [Significant indentation inside arbitrary HTML](#significant-indentation-inside-arbitrary-html) | ||
- [Code blocks](#code-blocks) | ||
- [Using The Compiler Directly](#using-the-compiler-directly) | ||
- [Changelog](#changelog) | ||
- [Donate](#donate) | ||
- [Credits](#credits) | ||
- [Contributors](#contributors) | ||
- [Backers](#backers) | ||
- [Sponsors](#sponsors) | ||
@@ -392,4 +391,14 @@ <!-- /TOC --> | ||
To get around this, `markdown-to-jsx` strips leading and trailing whitespace inside of arbitrary HTML within markdown. This means that certain syntaxes that use significant whitespace won't work in this edge case. | ||
To get around this, `markdown-to-jsx` left-trims approximately as much whitespace as the first line inside the HTML block. So for example: | ||
```html | ||
<div> | ||
# Hello | ||
How are you? | ||
</div> | ||
``` | ||
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. | ||
> NOTE! These syntaxes work just fine when you aren't writing arbitrary HTML wrappers inside your markdown. This is very much an edge case of an edge case. 🙃 | ||
@@ -399,12 +408,2 @@ | ||
✅ | ||
```md | ||
<div> | ||
```js | ||
var some = code(); | ||
``` | ||
</div> | ||
``` | ||
⛔️ | ||
@@ -418,13 +417,9 @@ | ||
#### Nested lists | ||
✅ | ||
This won't work at all at the moment. Trying to figure out a solution that will coexist peacefully with all the syntax permutations. | ||
⛔️ | ||
```md | ||
<div> | ||
* something | ||
* something related | ||
* something else | ||
```js | ||
var some = code(); | ||
``` | ||
</div> | ||
@@ -431,0 +426,0 @@ ``` |
Sorry, the diff of this file is not supported yet
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
257866
4051
485