Skip to content

Commit

Permalink
Mark quotes with localized labels as 'labeled' for CSS styling
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgio committed Sep 24, 2024
1 parent 8b84216 commit 87a66a4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,15 @@ class QuarkdownHtmlNodeRenderer(context: Context) : BaseHtmlNodeRenderer(context
// and a localized label is shown (e.g. 'Tip:' for English).
node.type?.asCSS?.let { type ->
`class`(type)
// The localized label is set as a CSS variable.
// Themes can customize label appearance and formatting.
style { "--quote-type-label" value context.localizeOrNull(type)?.let { "'$it'" } }
// The type is associated to a localized label
// only if the documant language is set and the set language is supported.
context.localizeOrNull(type)?.let { localizedLabel ->
// The localized label is set as a CSS variable.
// Themes can customize label appearance and formatting.
style { "--quote-type-label" value "'$localizedLabel'" }
// The quote is marked as labeled to allow further customization.
attribute("data-labeled", "")
}
}

+node.children
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/render/theme/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ blockquote[class] {
--quote-type-label: "";
}

blockquote[class] :first-child::before {
blockquote[class][data-labeled] :first-child::before {
content: var(--quote-type-label) var(--qd-quote-type-label-suffix);
font-weight: bold;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class FullPipelineTest {
""".trimIndent(),
) {
assertEquals(
"<blockquote class=\"tip\" style=\"--quote-type-label: 'Consiglio';\">" +
"<blockquote class=\"tip\" style=\"--quote-type-label: 'Consiglio';\" data-labeled=\"\">" +
"<p>you could try Quarkdown.<br />" +
"It&rsquo;s a cool language!</p>" +
"<p class=\"attribution\"><strong>iamgio</strong></p>" +
Expand Down

0 comments on commit 87a66a4

Please sign in to comment.