Skip to content

Commit

Permalink
refactor(blockquotes): cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
Keisir authored and craftzdog committed Mar 20, 2024
1 parent caa6a6d commit f68b0dd
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,29 @@ const processNode =
// So we just need to addtionally check if the following one is a block.
// The legacy title variant is not affected since it checks an inline and does not care about the newline.

// If this is not a gfm alert then we would manipulate the original children and the next processor would not be able to handle the children correctly.
const paragraphChildrenCopy = [...paragraph.children]
// Considering the reason why the paragraph ends here, the following one should be a children of the blockquote, which means it is always a block.
// So no more check is required.
title = text.value
admonitionType = config.types[title]

if (!admonitionType) {
return
}

// No addtional inlines can exist in this paragraph for the title...
if (paragraphChildrenCopy.length > 1) {
if (paragraph.children.length > 1) {
// Unless it is an inline break, which can be transformed to from 2 spaces with a newline.
if (paragraphChildrenCopy.at(1)?.type == 'break') {
if (paragraph.children.at(1)?.type == 'break') {
// When it is, we actually have already found the line break required by GitHub.
// So we just strip the additional `<br>` element.
// The title element will be removed later.
paragraphChildrenCopy.splice(1, 1)
paragraph.children.splice(1, 1)
} else {
return
}
}

// Considering the reason why the paragraph ends here, the following one should be a children of the blockquote, which means it is always a block.
// So no more check is required.
title = text.value
admonitionType = config.types[title]

if (admonitionType) {
// Remove the text as the title
paragraph.children.shift()
paragraph.children.shift()
} else {
return
}
// strip the title
paragraph.children.shift()
} else {
const textBody = text.value.substring(titleEnd + 1)
title = text.value.substring(0, titleEnd)
Expand Down

0 comments on commit f68b0dd

Please sign in to comment.