Skip to content

Commit

Permalink
Allow title to be defined as a markdown header.
Browse files Browse the repository at this point in the history
Close #3
  • Loading branch information
coatless committed Oct 25, 2024
1 parent d5cc90e commit 13d396d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
10 changes: 9 additions & 1 deletion _extensions/custom-callout/customcallout.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions docs/qcustom-callout-example.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
:::
````
:::

Expand Down Expand Up @@ -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"`
:::
Expand Down Expand Up @@ -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"`
:::
Expand Down
9 changes: 9 additions & 0 deletions docs/qcustom-callout-release-notes.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 13d396d

Please sign in to comment.