得鹿梦鱼 得鹿梦鱼

解析规则 rules

正则编辑器

function editregex: string  RegExp, opt = '' {  let source = typeof regex === 'string' ? regex : regex.source;  const obj = {    replace: name: string  RegExp, val: string  RegExp => {      let valSource = typeof val === 'string' ? val : val.source;      valSource = valSource.replaceother.caret, '$1';      source = source.replacename, valSource;      return obj;    },    getRegex:  => {      return new RegExpsource, opt;    },  };  return obj;}

其他类型

匹配代码行的缩进 codeRemoveIndent /^?: {1,4} {0,3}\t/gm
outputLinkReplace /\\[\[\]]/g
匹配围栏代码是不是有缩进 indentCodeCompensation /^\s+?:```/
beginningSpace /^\s+/
标题内容的# endingHash: /#$/
startingSpaceChar /^ /
标题内容的空白 endingSpaceChar / $/
nonSpaceChar: /[^ ]/
newLineCharGlobal /\n/g
制表符 tabCharGlobal /\t/g
multipleSpaceGlobal /\s+/g
blankLine /^[ \t]*$/
doubleBlankLine /\n[ \t]*\n[ \t]*$/
块引用的开始符 blockquoteStart /^ {0,3}>/
块引用中嵌套列表 blockquoteSetextReplace /\n {0,3}?:=+-+ *?=\n$/g
块引用中的空白 blockquoteSetextReplace2 /^ {0,3}>[ \t]?/gm
listReplaceTabs /^\t+/
listReplaceNesting /^ {1,4}?= {4}*[^ ]/g
listIsTask /^\[[ xX]\] /
listReplaceTask /^\[[ xX]\] +/
anyLine /\n.*\n/
hrefBrackets /^<.*>$/
tableDelimiter /[:]/
tableAlignChars /^\\ *$/g
tableRowBlankLine /\n[ \t]*$/
tableAlignRight /^ *-+: *$/
tableAlignCenter /^ *:-+: *$/
tableAlignLeft /^ *:-+ *$/
startATag /^<a /i
endATag /^<\/a>/i
startPreScriptTag /^<precodekbdscript\s>/i
endPreScriptTag /^<\/precodekbdscript\s>/i
startAngleBracket /^</
endAngleBracket />$/
pedanticHrefTitle /^[^'"]*[^\s]\s+['"].*\2/
unicodeAlphaNumeric /[\p{L}\p{N}]/u
escapeTest /[&<>"']/
escapeReplace /[&<>"']/g
escapeTestNoEncode /[<>"']&?!#\d{1,7}#[Xx][a-fA-F0-9]{1,6}\w+;/
escapeReplaceNoEncode /[<>"']&?!#\d{1,7}#[Xx][a-fA-F0-9]{1,6}\w+;/g
unescapeTest /&#?:\d+?:#x[0-9A-Fa-f]+?:\w+;?/ig
caret /^[^\[]\^/g
percentDecode /%25/g
findPipe /\/g
splitPipe / \/
slashPipe /\\\/g
回车换行 carriageReturn/\r\n\r/g
空行 spaceLine /^ +$/gm
notSpaceStart /^\S*/
endingNewline /\n$/
listItemRegex bull: string => new RegExp`^ {0,3}${bull}?:[\t ][^\\n]*??:\\n$`
nextBulletRegex indent: number => new RegExp`^ {0,${Math.min3, indent - 1}}?:[*+-]\\d{1,9}[.]?:[ \t][^\\n]*??:\\n$`
hrRegex indent: number => new RegExp`^ {0,${Math.min3, indent - 1}}?:- *{3,}?:_ *{3,}?:\\* *{3,}?:\\n+$`
fencesBeginRegex indent: number => new RegExp`^ {0,${Math.min3, indent - 1}}?:\`\`\`~~~`
headingBeginRegex indent: number => new RegExp`^ {0,${Math.min3, indent - 1}}#`
htmlBeginRegex indent: number => new RegExp`^ {0,${Math.min3, indent - 1}}<?:[a-z].*>!--`, 'i'

块级类型

空白行 newline /^?:[ \t]*?:\n$+/
代码块(缩进)blockCode /^?: {4} {0,3}\t[^\n]+?:\n?:[ \t]*?:\n$*?+/;
围栏代码块 fences /^ {0,3}`{3,}?=[^`\n]*?:\n$~{3,}[^\n]*?:\n$?:[\s\S]*??:\n$?: {0,3}\1[~`]* *?=\n$$/
水平线 hr /^ {0,3}?:-[\t ]*{3,}?:_[ \t]*{3,}?:\*[ \t]*{3,}?:\n+$/
标题匹配 heading /^ {0,3}#{1,6}?=\s$.*?:\n+$/
bullet /?:[*+-]\d{1,9}[.]/
lheading

edit/^?!bull blockCodefencesblockquoteheadinghtml?:.\n?!\s*?\nbull blockCodefencesblockquoteheadinghtml+?\n {0,3}=+-+ *?:\n+$/  .replace/bull/g, bullet // lists can interrupt  .replace/blockCode/g, /?: {4} {0,3}\t/ // indented code blocks can interrupt  .replace/fences/g, / {0,3}?:`{3,}~{3,}/ // fenced code blocks can interrupt  .replace/blockquote/g, / {0,3}>/ // blockquote can interrupt  .replace/heading/g, / {0,3}#{1,6}/ // ATX heading can interrupt  .replace/html/g, / {0,3}<[^\n>]+>\n/ // block html can interrupt  .getRegex

_paragraph /^[^\n]+?:\n?!hrheadinglheadingblockquotefenceslisthtmltable +\n[^\n]+*/
blockText /^[^\n]+/
_blockLabel /?!\s*\]?:\\.[^\[\]\\]+/
def

edit/^ {0,3}\[label\]: *?:\n[ \t]*?[^<\s][^\s]*<.*?>?:?: +?:\n[ \t]*? *\n[ \t]*title? *?:\n+$/  .replace'label', _blockLabel  .replace'title', /?:"?:\\"?[^"\\]*"'[^'\n]*?:\n[^'\n]+*\n?'\[^]*\/  .getRegex

list

edit/^ {0,3}bull[ \t][^\n]+???:\n$/  .replace/bull/g, bullet  .getRegex

_tag

'addressarticleasidebasebasefontblockquotebodycaption'  + 'centercolcolgroupdddetailsdialogdirdivdldtfieldsetfigcaption'  + 'figurefooterformframeframeseth[1-6]headheaderhrhtmliframe'  + 'legendlilinkmainmenumenuitemmetanavnoframesoloptgroupoption'  + 'pparamsearchsectionsummarytabletbodytdtfootththeadtitle'  + 'trtrackul'

_comment /<!--?:-?>[\s\S]*??:-->$/
html

edit  '^ {0,3}?:' // optional indentation+ '<scriptprestyletextarea[\\s>][\\s\\S]*??:</\\1>[^\\n]*\\n+$' // 1+ 'comment[^\\n]*\\n+$' // 2+ '<\\?[\\s\\S]*??:\\?>\\n*$' // 3+ '<![A-Z][\\s\\S]*??:>\\n*$' // 4+ '<!\\[CDATA\\[[\\s\\S]*??:\\]\\]>\\n*$' // 5+ '</?tag?: +\\n/?>[\\s\\S]*??:?:\\n[ \t]*+\\n$' // 6+ '<?!scriptprestyletextarea[a-z][\\w-]*?:attribute*? */?>?=[ \\t]*?:\\n$[\\s\\S]*??:?:\\n[ \t]*+\\n$' // 7 open tag+ '</?!scriptprestyletextarea[a-z][\\w-]*\\s*>?=[ \\t]*?:\\n$[\\s\\S]*??:?:\\n[ \t]*+\\n$' // 7 closing tag+ '', 'i'  .replace'comment', _comment  .replace'tag', _tag  .replace'attribute', / +[a-zA-Z:_][\w.:-]*?: *= *"[^"\n]*" *= *'[^'\n]*' *= *[^\s"'=<>`]+?/  .getRegex

paragraph

 edit_paragraph  .replace'hr', hr  .replace'heading', ' {0,3}#{1,6}?:\\s$'  .replace'lheading', '' // setext headings don't interrupt commonmark paragraphs  .replace'table', ''  .replace'blockquote', ' {0,3}>'  .replace'fences', ' {0,3}?:`{3,}?=[^`\\n]*\\n~{3,}[^\\n]*\\n'  .replace'list', ' {0,3}?:[*+-]1[.] ' // only lists starting from 1 can interrupt  .replace'html', '</??:tag?: +\\n/?><?:scriptprestyletextarea!--'  .replace'tag', _tag // pars can be interrupted by type 6 html blocks  .getRegex;

块引用 blockquote

edit/^ {0,3}> ?paragraph[^\n]*?:\n$+/  .replace'paragraph', paragraph  .getRegex

gfmTable

edit  '^ *[^\\n ].*\\n' // Header+ ' {0,3}?:\\ *?:?-+:? *?:\\ *:?-+:? **?:\\ *?' // Align+ '?:\\n?:?! *\\nhrheadingblockquotecodefenceslisthtml.*?:\\n$*\\n*$' // Cells  .replace'hr', hr  .replace'heading', ' {0,3}#{1,6}?:\\s$'  .replace'blockquote', ' {0,3}>'  .replace'code', '?: {4} {0,3}\t[^\\n]'  .replace'fences', ' {0,3}?:`{3,}?=[^`\\n]*\\n~{3,}[^\\n]*\\n'  .replace'list', ' {0,3}?:[*+-]1[.] ' // only lists starting from 1 can interrupt  .replace'html', '</??:tag?: +\\n/?><?:scriptprestyletextarea!--'  .replace'tag', _tag // tables can be interrupted by type 6 html blocks  .getRegex

行内类型