From 13d396de8840ef94fc264c356da5d1c6070af9c9 Mon Sep 17 00:00:00 2001 From: "james.balamuta@gmail.com" Date: Thu, 24 Oct 2024 22:03:14 -0700 Subject: [PATCH] Allow `title` to be defined as a markdown header. Close #3 --- _extensions/custom-callout/customcallout.lua | 10 ++++++++- docs/qcustom-callout-example.qmd | 22 ++++++++++++++++++++ docs/qcustom-callout-release-notes.qmd | 9 ++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/_extensions/custom-callout/customcallout.lua b/_extensions/custom-callout/customcallout.lua index b22d174..ae98513 100644 --- a/_extensions/custom-callout/customcallout.lua +++ b/_extensions/custom-callout/customcallout.lua @@ -110,12 +110,20 @@ local function convertToCustomCallout(div) local callout = customCallouts[class] if callout then + -- Use the default title if not provided + local title = callout.title + + -- Check to see if the title is specified in the div content + if div.content[1] ~= nil and div.content[1].t == "Header" then + title = div.content[1] + div.content:remove(1) + end -- Create a new Callout with the custom callout parameters local calloutParams = { type = callout.type, content = div.content, - title = div.attributes.title or callout.title, + title = div.attributes.title or title, icon = div.attributes.icon or callout.icon, appearance = div.attributes.appearance or callout.appearance, collapse = div.attributes.collapse or callout.collapse diff --git a/docs/qcustom-callout-example.qmd b/docs/qcustom-callout-example.qmd index d0a82c7..71a1320 100644 --- a/docs/qcustom-callout-example.qmd +++ b/docs/qcustom-callout-example.qmd @@ -117,12 +117,24 @@ The following examples demonstrate the use of custom callouts with additional op Demo of `title="Todo with a Custom Title!"`. ::: +::: {.todo} +## Todo with Title Defined in Content +Demo of `title` defined as a markdown header in content. +::: + + ### Source ````md ::: {.todo title="Todo with a Custom Title!"} Demo of `title="Todo with a Custom Title!"`. ::: + + +::: {.todo} +## Todo with Title Defined in Content +Demo of `title` defined as a markdown header in content. +::: ```` ::: @@ -226,6 +238,11 @@ Hello! Demo of `title="Note with Custom Title"` ::: +::: {.callout-note} +## Note with Title Defined in Content +Demo of `title` defined as a markdown header in content. +::: + ::: {.callout-note icon="false" title="Note with Title and No Icon"} Demo of `icon="false"` ::: @@ -261,6 +278,11 @@ Hello! Demo of `title="Note with Custom Title"` ::: +::: {.callout-note} +## Note with Title Defined in Content +Demo of `title` defined as a markdown header in content. +::: + ::: {.callout-note icon="false" title="Note with Title and No Icon"} Demo of `icon="false"` ::: diff --git a/docs/qcustom-callout-release-notes.qmd b/docs/qcustom-callout-release-notes.qmd index 4c0ea64..7723445 100644 --- a/docs/qcustom-callout-release-notes.qmd +++ b/docs/qcustom-callout-release-notes.qmd @@ -12,6 +12,15 @@ format: ## Features +- Allow `title` to be specified as a markdown header in the callout's content. + +````md +::: todo +## Todo with Title Defined as Markdown in Content +Hello there! +::: +```` + ## Documentation ## Bugfixes