Repository navigation
Patch Changes
-
ce92404: Raw HTML is now checked the way a browser reads it. If you render markdown written by someone else, please upgrade.
Markup that a browser reads differently from this library could reach the HTML output with a live event handler or link, and the markdown output could hand the next renderer a live tag or link. Solid and Vue could put
innerHTMLstraight into the page, and Solid'sattr:,prop:, andbool:prefixes could carry a handler past the check. Several inputs crashed or stopped rendering in React, React Native, Solid, and Vue. Deeply nested HTML, repeated<pre></pre>blocks, and long runs of unfinished HTML comments could slow rendering to tens of seconds; they now stay fast.These attributes are now removed, because they can run script:
ref,innerHTML,outerHTML, anddangerouslySetInnerHTMLwritten in markdown, on every tag.childrentoo, unless it becomes the element's content (see below).- A
{…}event handler on a hyphenated tag, such as<my-widget onclick={…}>. With the tag inoverrides, it stays on the parsed node forrenderRuleandparser(), and no output renders it. - A
{…}event handler on a capitalized tag, such as<Btn onClick={go}>, unlessoverrideslists the tag. - The
attributeNameof an SVG<animate>or<set>that changes a link or an event handler, so it stops animating. Animating any other attribute works as before.
Output that changes in every format:
- A
childrenattribute becomes the element's text content, the way React reads it, on a tagoverrideslists. Withcardrenamed toi,<Card children="z" />renders<i>z</i>in every output. The element's own content wins, so<Card children="z">own</Card>renders<i>own</i>. A void element such as<img>takes none, an object or array value is removed, and no output writeschildrenas an attribute. Vue and the HTML and markdown output used to write it as an attribute, which shows nothing. Inside a block of raw HTML, the HTML and markdown output keep such a tag as written, without the attribute, as they do for any renamed tag there. - If you build the parsed tree yourself, or store the result of
parser()and render it later, the HTML and markdown output no longer write an event handler from it, except on a capitalized tagoverrideslists, as above, and no output writes one on a code block. - For a block of raw HTML, the
textthatparser()returns is the block's content with unsafe markup removed, for every tag. A custom element such as<my-widget>held the whole tag as written, handlers included, so markdown written from a stored tree repeated the tag. - A footnote reference with no definition, such as
[^1], stays as text, as GitHub shows it, rather than a superscript linking to nothing. If you render part of a document on its own, a reference whose definition is in another part shows as text. WithoptimizeForStreaming, a reference stays one while its definition may still arrive, and one at the very end of the text so far shows as^1. - With a definition for
[^1],[x][^1]renders as[x]followed by the footnote reference, not as a link. - A URL that mentions a dangerous scheme after its first
/,?, or#, such ashttps://en.wikipedia.org/wiki/Javascript:_The_Good_Parts, is kept, andsanitizer()returns it where it returnednull.sanitizer()now rejects a scheme split by a tab or line break. - An opening tag that a browser reads but this library can't check safely, or one left unfinished at the end of a block of raw HTML, shows as text. In the HTML and markdown output, a long attribute value holding what looks like an unfinished tag is removed, or its tag shows as text.
- In a list item, a line with no indent after a finished block of raw HTML is read the way CommonMark reads it, so a footnote definition there now works.
- A link reference definition's URL ends at whitespace even after a backslash, as CommonMark says:
[r]: a\withbon the next line keepsbas text. - An entity in
<pre>text, such as<pre>a < b</pre>, shows asa < bin React, React Native, Solid, and Vue. <pre><b>x</b></pre>renders its markup in Solid and Vue rather than[object Object].- An unfinished
<pre>, such as<pre>awith no closing tag, renders as<pre>a</pre>in React, React Native, Solid, and Vue. React showed a second<pre>inside it, React Native showed<pre>as text, and Solid and Vue crashed. <?php … ?>,<!DOCTYPE html>, and<![CDATA[…]]>render nothing in React, React Native, Solid, and Vue, as in a browser. React crashed on them.
The markdown output is held to the same bar, because another renderer reads it. Rendering the input through this library is unchanged; the written text, read back by this library or another renderer, can show a difference only where a bullet says so:
- Code that another renderer could read as a tag or link is written as
<code>or<pre><code>HTML with entities rather than backticks or a fence. An unfinished tag counts, so a loop condition likei<nis written this way. A browser shows the same characters, and a language name stays asclass="language-html". Code that only names a tag such as<script>or<style>keeps its fence, unlessdisableParsingRawHTMLis on. - Text that looks like a tag, such as
\<b>or<b>, is written with<. Quotes and brackets in image alt text, an empty~~~~, and characters such as<and[in footnote names, reference names, and link titles are escaped or written as entities. - Text that reads like an entity after decoding, such as
&copy;, stays&copy;rather than becoming©. - A link target with a space or an angle bracket is percent-encoded, so
[x](<a b>)is written[x](a%20b). One with an unpaired parenthesis keeps its angle brackets, and a backslash that would read as an escape is doubled. [^1]:is written[^1]\:, and a(right after a]in text is written\(.- A heading with a
=or-underline keeps every line of its text, and one ending in a space and#keeps the#, written\#. A table cell keeps its backslashes and escaped pipes. - Continuation lines in an ordered list indent to the width of the marker, three columns for
1., so a code block there no longer gains a space each time it is written. - In a list item, a code block after raw HTML gets a blank line before it, which makes the list loose, and a raw opening tag spanning several lines is written on one line. A line break in a quoted value becomes
, and one inside a{…}value becomes a space, which changes a multi-line string there. - A tag inside
<?…?>or<![CDATA[…]]>, past its first>, is written with<. An unfinished HTML comment past the first line of raw HTML is written as text. - A byte order mark at the start of text, and a U+2028 or U+2029 line separator right before a
>in raw HTML, are written as entities. - What a rename in
overrideswrites is read again like any other markdown, so<span>y</span><b>z</b>withspanrenamed todivgets a blank line after</div>, the same as writing<div>directly.
In the HTML output,
<script>,<iframe>, and the other filtered tag names are written with<inside comments and attribute values too, and every&in a link target is written&, as React, Solid, and Vue already do. The page looks the same, except CDATA inside SVG or MathML shows the<. -
ce92404: A tag's first letter now decides how its override and its attributes are read, in every output. If you list components in
overrides, or read attributes throughrenderRuleorparser(), check the cases below.- A tag that starts with an uppercase letter is a component and finds its
overrideskey ignoring case, so<CARD>and<CaRd>now use aCardkey. A tag that starts with a lowercase letter is HTML, so<card>still never uses aCardkey. - A capitalized tag with no key renders as a plain element with its attributes as written,
{…}included, and loses its event handlers.<Table data={[1, 2, 3]} />with noTablekey givesdata="{[1, 2, 3]}"rather than an array. A component you render throughrenderRuleorcreateElementwithout listing it inoverridesnow receives that text, so list the tag inoverridesto keep parsed values. - An override on a lowercase tag receives its attributes as written text, so with
{ a: MyLink },<a data={{"a":1}}>gives MyLink the text{{"a":1}}to parse as it sees fit. An event handler on such a tag, quoted or{…}, stays on the parsed node as written text forrenderRuleandparser(), and never reaches MyLink or the page. evalUnserializableExpressionsapplies only to a capitalized tag listed inoverrides.
- A tag that starts with an uppercase letter is a component and finds its
-
ce92404: Parsing stays fast on text with many unclosed HTML tags, such as
<x1> <x2> <x3> …or[<b>] [<b>] …, where a crafted document could take over a second. If you render markdown written by someone else, please upgrade.On such text, past a limit far above what real documents reach, a
]inside a tag's attribute can end link text.