Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(blockquotes): first line break without alerts not working #8

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ 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.

// 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 (paragraph.children.length > 1) {
// Unless it is an inline break, which can be transformed to from 2 spaces with a newline.
Expand All @@ -53,18 +62,8 @@ const processNode =
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()
} else {
return
}
// strip the title
paragraph.children.shift()
} else {
const textBody = text.value.substring(titleEnd + 1)
title = text.value.substring(0, titleEnd)
Expand Down
22 changes: 22 additions & 0 deletions test/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,25 @@ exports[`GitHub beta blockquote-based admonitions with titles like [!NOTE] > sho
</ul>
</div>"
`;

exports[`verify default behavior with plugin enabled > should transform a plain blockquote with line breaks (" " - note the two spaces) 1`] = `
"<blockquote>
<p>Each time you increase the amount of code, your software grows exponentially more complicated.<br>
-- DHH, Getting Real</p>
</blockquote>"
`;

exports[`verify default behavior with plugin enabled > should transform a plain blockquote with line breaks (\\) 1`] = `
"<blockquote>
<p>Each time you increase the amount of code, your software grows exponentially more complicated.<br>
-- DHH, Getting Real</p>
</blockquote>"
`;

exports[`verify default behavior with plugin enabled > should transform a plain blockquote with line breaks (\\) 2x 1`] = `
"<blockquote>
<p>Each time you increase the amount of code, your software grows exponentially more complicated.<br>
-- DHH, Getting Real<br>
-- DHH, Getting Real</p>
</blockquote>"
`;
39 changes: 39 additions & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,42 @@ describe('GitHub beta blockquote-based admonitions with titles like [!NOTE]', fu
}
})
})

describe('verify default behavior with plugin enabled', function () {
defineCase('should transform a plain blockquote with line breaks (\\)', {
input: `\
> Each time you increase the amount of code, your software grows exponentially more complicated.\\
> -- DHH, Getting Real
`,
assertions(html) {
const elem = selectAll('blockquote > p > br', parseDocument(html))
expect(elem).to.lengthOf(1)
}
})

defineCase(
'should transform a plain blockquote with line breaks (" " - note the two spaces)',
{
input: `\
> Each time you increase the amount of code, your software grows exponentially more complicated.
> -- DHH, Getting Real
`,
assertions(html) {
const elem = selectAll('blockquote > p > br', parseDocument(html))
expect(elem).to.lengthOf(1)
}
}
)

defineCase('should transform a plain blockquote with line breaks (\\) 2x', {
input: `\
> Each time you increase the amount of code, your software grows exponentially more complicated.\\
> -- DHH, Getting Real\\
> -- DHH, Getting Real
`,
assertions(html) {
const elem = selectAll('blockquote > p > br', parseDocument(html))
expect(elem).to.lengthOf(2)
}
})
})
Loading