fix: keep a line starting with # but no space in the list item (#4127)

This commit is contained in:
Krishna Anubhav
2026-10-25 23:50:21 -06:00
committed by GitHub
parent 5d8e2340d7
commit 6b63189546
6 changed files with 37 additions and 2 deletions
+3 -1
View File
@@ -382,7 +382,9 @@ export class _Tokenizer<ParserOutput = string, RendererOutput = string> {
const nextBulletRegex = this.rules.other.nextBulletRegex(indent);
const hrRegex = this.rules.other.hrRegex(indent);
const fencesBeginRegex = this.rules.other.fencesBeginRegex(indent);
const headingBeginRegex = this.rules.other.headingBeginRegex(indent);
const headingBeginRegex = this.options.pedantic
? this.rules.other.pedanticHeadingBeginRegex(indent)
: this.rules.other.headingBeginRegex(indent);
const htmlBeginRegex = this.rules.other.htmlBeginRegex(indent);
const blockquoteBeginRegex = this.rules.other.blockquoteBeginRegex(indent);
+4 -1
View File
@@ -98,7 +98,10 @@ export const other = {
nextBulletRegex: cachedIndentRegex((indent: number) => new RegExp(`^ {0,${indent}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`)),
hrRegex: cachedIndentRegex((indent: number) => new RegExp(`^ {0,${indent}}((?:-[ \t]*){3,}|(?:_[ \t]*){3,}|(?:\\*[ \t]*){3,})(?:\\n+|$)`)),
fencesBeginRegex: cachedIndentRegex((indent: number) => new RegExp(`^ {0,${indent}}(?:\`\`\`|~~~)`)),
headingBeginRegex: cachedIndentRegex((indent: number) => new RegExp(`^ {0,${indent}}#`)),
// an ATX heading needs a space (or the end of the line) after the hashes, so a line
// like `#tag` does not end a list item; pedantic mode accepts it as a heading
headingBeginRegex: cachedIndentRegex((indent: number) => new RegExp(`^ {0,${indent}}#{1,6}(?:\\s|$)`)),
pedanticHeadingBeginRegex: cachedIndentRegex((indent: number) => new RegExp(`^ {0,${indent}}#`)),
// a list item ends where a paragraph would be interrupted, so this mirrors the
// html start conditions in the paragraph rule below; type 7 is excluded there
htmlBeginRegex: cachedIndentRegex((indent: number) => new RegExp(`^ {0,${indent}}(?:</?(?:${_tag})(?: +|$|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|<![A-Za-z]|<!\\[CDATA\\[)`, 'i')),
@@ -0,0 +1,12 @@
<ul>
<li>item
#tag</li>
</ul>
<ol>
<li>one
#######</li>
</ol>
<ul>
<li>last</li>
</ul>
<h1>heading</h1>
@@ -0,0 +1,8 @@
- item
#tag
1. one
#######
- last
# heading
@@ -0,0 +1,4 @@
<ul>
<li>item</li>
</ul>
<h1>tag</h1>
@@ -0,0 +1,6 @@
---
pedantic: true
---
- item
#tag