style: format

pull/665/head
Kia King Ishii 3 years ago
parent abd96bda87
commit ab8413fa90

@ -20,17 +20,17 @@ const vueReservedTags = [
/**
* According to markdown spec, all non-block html tags are treated as "inline"
* tags (wrapped with <p></p>), including those "unknown" tags
* tags (wrapped with <p></p>), including those "unknown" tags.
*
* Therefore, markdown-it processes "inline" tags and "unknown" tags in the same
* way, and does not care if a tag is "inline" or "unknown"
* Therefore, markdown-it processes "inline" tags and "unknown" tags in the
* same way, and does not care if a tag is "inline" or "unknown".
*
* As we want to take those "unknown" tags as custom components, we should
* treat them as "block" tags
* treat them as "block" tags.
*
* So we have to distinguish between "inline" and "unknown" tags ourselves
* So we have to distinguish between "inline" and "unknown" tags ourselves.
*
* The inline tags list comes from MDN
* The inline tags list comes from MDN.
*
* @see https://spec.commonmark.org/0.29/#raw-html
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements
@ -56,7 +56,7 @@ const inlineTags = [
'em',
'embed',
'i',
/* iframe is treated as HTML blocks in markdown spec */
// iframe is treated as HTML blocks in markdown spec
// 'iframe',
'img',
'input',
@ -94,10 +94,10 @@ const inlineTags = [
'wbr'
]
// Replacing the default htmlBlock rule to allow using custom components at
// replacing the default htmlBlock rule to allow using custom components at
// root level
// An array of opening and corresponding closing sequences for html tags,
//
// an array of opening and corresponding closing sequences for html tags,
// last argument defines whether it can terminate a paragraph or not
const HTML_SEQUENCES: [RegExp, RegExp, boolean][] = [
[/^<(script|pre|style)(?=(\s|>|$))/i, /<\/(script|pre|style)>/i, true],
@ -105,13 +105,16 @@ const HTML_SEQUENCES: [RegExp, RegExp, boolean][] = [
[/^<\?/, /\?>/, true],
[/^<![A-Z]/, />/, true],
[/^<!\[CDATA\[/, /\]\]>/, true],
// MODIFIED HERE: Treat vue reserved tags as block tags
// MODIFIED HERE: treat vue reserved tags as block tags
[
new RegExp('^</?(' + vueReservedTags.join('|') + ')(?=(\\s|/?>|$))', 'i'),
/^$/,
true
],
// MODIFIED HERE: Treat unknown tags as block tags (custom components), excluding known inline tags
// MODIFIED HERE: treat unknown tags as block tags (custom components),
// excluding known inline tags
[
new RegExp(
'^</?(?!(' + inlineTags.join('|') + ')(?![\\w-]))\\w[\\w-]*[\\s/>]'
@ -119,6 +122,7 @@ const HTML_SEQUENCES: [RegExp, RegExp, boolean][] = [
/^$/,
true
],
[
new RegExp('^</?(' + blockNames.join('|') + ')(?=(\\s|/?>|$))', 'i'),
/^$/,
@ -168,8 +172,7 @@ const htmlBlock: RuleBlock = (state, startLine, endLine, silent): boolean => {
nextLine = startLine + 1
// If we are here - we detected HTML block.
// Let's roll down till block end.
// if we are here - we detected HTML block. let's roll down till block end
if (!HTML_SEQUENCES[i][1].test(lineText)) {
for (; nextLine < endLine; nextLine++) {
if (state.sCount[nextLine] < state.blkIndent) {

Loading…
Cancel
Save