From 7f7d9d8a522563c5083ca3a233f507438f660a61 Mon Sep 17 00:00:00 2001 From: Ryan DeStefano <67760716+rdestefa@users.noreply.github.com> Date: Sun, 3 May 2026 03:51:21 -0700 Subject: [PATCH 1/2] Add Support for Custom Alert Titles --- CHANGELOG.md | 16 +- README.md | 19 +- commonmark-ext-gfm-alerts/README.md | 52 +++- .../org/commonmark/ext/gfm/alerts/Alert.java | 2 + .../commonmark/ext/gfm/alerts/AlertTitle.java | 25 ++ .../ext/gfm/alerts/AlertsExtension.java | 63 +++- .../gfm/alerts/internal/AlertBlockParser.java | 243 +++++++++++++++ .../internal/AlertHtmlNodeRenderer.java | 14 +- .../internal/AlertMarkdownNodeRenderer.java | 15 +- .../alerts/internal/AlertPostProcessor.java | 111 ------- .../alerts/AlertsMarkdownRendererTest.java | 55 +++- .../ext/gfm/alerts/AlertsSpecTest.java | 9 +- .../commonmark/ext/gfm/alerts/AlertsTest.java | 286 +++++++++++++++++- .../testutil/RenderingTestCase.java | 2 - 14 files changed, 765 insertions(+), 147 deletions(-) create mode 100644 commonmark-ext-gfm-alerts/src/main/java/org/commonmark/ext/gfm/alerts/AlertTitle.java create mode 100644 commonmark-ext-gfm-alerts/src/main/java/org/commonmark/ext/gfm/alerts/internal/AlertBlockParser.java delete mode 100644 commonmark-ext-gfm-alerts/src/main/java/org/commonmark/ext/gfm/alerts/internal/AlertPostProcessor.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c5c67268..29a61b48f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,12 +9,20 @@ with the exception that 0.x versions can break between minor versions. ## [Unreleased] ### Added - Allow customizing HTML attributes for alert title `

` tag via `AttributeProvider` +- New configuration for `AlertsExtension` to allow authors to provide custom + titles per alert. See the + [custom titles section of the alerts README](./commonmark-ext-gfm-alerts/README.md#custom-alert-titles) + for more information. +- New configuration for `AlertsExtension` to allow alerts to be nested within + other blocks (including other alerts). See + [this section of the alerts README](./commonmark-ext-gfm-alerts/README.md#nesting-alerts) + for more information. ## [0.28.0] - 2026-03-31 ### Added - New extension for alerts (aka callouts/admonitions) - Syntax: - ``` + ```markdown > [!NOTE] > The text of the note. ``` @@ -102,9 +110,9 @@ with the exception that 0.x versions can break between minor versions. ### Added - New extension for footnotes! - Syntax: - ``` + ```markdown Main text[^1] - + [^1]: Additional text in a footnote ``` - Inline footnotes like `^[inline footnote]` are also supported when enabled @@ -269,7 +277,7 @@ with the exception that 0.x versions can break between minor versions. - Use class `ImageAttributesExtension` in artifact `commonmark-ext-image-attributes` - Extension for task lists (GitHub-style), thanks @dohertyfjatl - Syntax: - ``` + ```markdown - [x] task #1 - [ ] task #2 ``` diff --git a/README.md b/README.md index 845226729..6ea222e6a 100644 --- a/README.md +++ b/README.md @@ -337,21 +337,22 @@ Use class `TablesExtension` in artifact `commonmark-ext-gfm-tables`. Adds support for GitHub-style alerts (also known as callouts or admonitions) as described [here](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts), e.g.: -``` +```markdown > [!NOTE] > The text of the note. ``` As types you can use NOTE, TIP, IMPORTANT, WARNING, CAUTION; or configure the extension to add additional ones. -Use class `AlertsExtension` in artifact `commonmark-ext-gfm-alerts`. +Use class `AlertsExtension` in artifact `commonmark-ext-gfm-alerts`. See the +[`AlertsExtension` README](./commonmark-ext-gfm-alerts/README.md) for more information. ### Footnotes Enables footnotes like in [GitHub](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#footnotes) or [Pandoc](https://pandoc.org/MANUAL.html#footnotes): -``` +```markdown Main text[^1] [^1]: Additional text in a footnote @@ -368,7 +369,7 @@ is based on the text of the heading. `# Heading` will be rendered as: -``` +```html

Heading

``` @@ -389,7 +390,7 @@ Use class `InsExtension` in artifact `commonmark-ext-ins`. Adds support for metadata through a YAML front matter block. This extension only supports a subset of YAML syntax. Here's an example of what's supported: -``` +```markdown --- key: value list: @@ -412,11 +413,11 @@ Adds support for specifying attributes (specifically height and width) for image The attribute elements are given as `key=value` pairs inside curly braces `{ }` after the image node to which they apply, for example: -``` +```markdown ![text](/url.png){width=640 height=480} ``` will be rendered as: -``` +```html text ``` @@ -434,12 +435,12 @@ whitespace character or the letter `x` in lowercase or uppercase, then a right b whitespace before any other content. For example: -``` +```markdown - [ ] task #1 - [x] task #2 ``` will be rendered as: -``` +```html