Add support for GitHub-style alert - #158
Conversation
927b149 to
b208496
Compare
|
Love it. Hope this gets added! |
|
Sorry for the delay. Reviewing now! |
|
@guoPhineas Two issues:
|
|
|
||
| @Suite("Markdown Quote Alert") | ||
| struct MarkdownQuoteAlertTests { | ||
| @Test( |
| #expect(renderedBody.contains(fixture.expectedFirstBodyParagraph)) | ||
| } | ||
|
|
||
| @Test( |
|
@LiYanan2004 I just fixed the issues you raised. But the test isn't also passed. I speculate that there may be code logic issues with the current testing: The For this fixture, Swift Markdown produces the following AST:
However, when there is more than one child, the test uses: bodyChildren = Array(children.dropFirst())This discards the first paragraph, including The renderer should strip the alert marker/title line from the first paragraph, preserve the remaining inline content, and then append the remaining blockquote children. The implementation now follows that behavior, but the test’s extraction logic would need the same adjustment. So, I fixed the issue in |
|
@guoPhineas Here are some edge cases that need to be fixed.
|
|
Thank you for your patient review and corrections. I have just fixed these issues, and all tests have passed. To test as many edge cases as possible, I used the Markdown text below for testing, and it displayed correctly. 2026-09-02.22.46.22.mov # GitHub Alert Test Cases
## Valid Alerts
> [!NOTE]
> This is a standard note alert.
> [!TIP]
> This is a standard tip alert.
> [!IMPORTANT]
> This is a standard important alert.
> [!WARNING]
> This is a standard warning alert.
> [!CAUTION]
> This is a standard caution alert.
## Case-Insensitive Markers
> [!note]
> This lowercase marker should render as a note.
> [!Tip]
> This mixed-case marker should render as a tip.
> [!important]
> This lowercase marker should render as important.
> [!Warning]
> This mixed-case marker should render as a warning.
> [!Caution]
> This mixed-case marker should render as a caution.
## Body Layouts
> [!NOTE]
> The body starts immediately after the marker.
> This line belongs to the same paragraph.
> [!TIP]
>
> The body starts after a blank quoted line.
> [!IMPORTANT]
> First paragraph.
>
> Second paragraph.
>
> Third paragraph.
> [!CAUTION]
> A body containing **bold text**, *italic text*, `inline code`,
> [a link](https://github.com), and ~~strikethrough text~~.
## Nested Block Content
> [!NOTE]
> - First list item
> - Second list item
> - Nested list item
> [!TIP]
> 1. First ordered item
> 2. Second ordered item
> [!IMPORTANT]
> > A nested blockquote.
> >
> > Another nested blockquote paragraph.
> [!WARNING]
> ```swift
> let warning = "Code block inside an alert"
> print(warning)
> ```
> [!CAUTION]
> | Column A | Column B |
> |----------|----------|
> | Value A | Value B |
## Marker-Only Alerts
> [!NOTE]
> [!TIP]
> [!IMPORTANT]
> [!WARNING]
> [!CAUTION]
## Surrounding Whitespace
> [!NOTE]
> The marker has surrounding whitespace.
> [!WARNING]
> The marker has trailing spaces before the line break.Thank you. |
|
Additionally, regarding the following cases, I have looked into them and it seems that they should not be supported. If I am mistaken, please feel free to correct me. > `[!NOTE]` is the token used to create a GitHub alert.
> Place it on a dedicated line.
> **[!WARNING]** is an example marker.
> This paragraph documents the syntax. |


WIP