From d2df7f6763ddcf8b87a08c813cdecc5a410856f9 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/6] Add Support for Custom Alert Titles --- CHANGELOG.md | 19 +- 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 +++++++++++++++++- 13 files changed, 767 insertions(+), 146 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 afce7250..254826f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,15 +8,24 @@ with the exception that 0.x versions can break between minor versions. ## [Unreleased] ### Added -- Allow customizing HTML attributes for alert title `

` tag via `AttributeProvider` - Support rendering GFM task list items to Markdown - Support rendering YAML front matter to Markdown +- Alerts + - 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. ``` @@ -104,9 +113,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 @@ -271,7 +280,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 7bf598ba..1f00e0f0 100644 --- a/README.md +++ b/README.md @@ -339,21 +339,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 @@ -370,7 +371,7 @@ is based on the text of the heading. `# Heading` will be rendered as: -``` +```html

Heading

``` @@ -391,7 +392,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: @@ -414,11 +415,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 ``` @@ -436,12 +437,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