Skip to content

Commit

Permalink
Merge pull request #869 from pulldown-cmark/blockquote_tags
Browse files Browse the repository at this point in the history
Blockquote tags
  • Loading branch information
Martin1887 committed Apr 1, 2024
2 parents f0ad25e + 51fc13b commit 2540d40
Show file tree
Hide file tree
Showing 15 changed files with 603 additions and 53 deletions.
2 changes: 1 addition & 1 deletion pulldown-cmark/examples/parser-map-tag-print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn main() {
Tag::Emphasis => println!("Emphasis (this is a span tag)"),
Tag::Strong => println!("Strong (this is a span tag)"),
Tag::Strikethrough => println!("Strikethrough (this is a span tag)"),
Tag::BlockQuote => println!("BlockQuote"),
Tag::BlockQuote(kind) => println!("BlockQuote ({:?})", kind),
Tag::CodeBlock(code_block_kind) => {
println!("CodeBlock code_block_kind: {:?}", code_block_kind)
}
Expand Down
193 changes: 193 additions & 0 deletions pulldown-cmark/specs/blockquotes_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
Run this with `cargo test --features gen-tests suite::blockquotes_tags`.

Blockquotes can optionally have one of the following tags:

- [!NOTE]
- [!TIP]
- [!IMPORTANT]
- [!WARNING]
- [!CAUTION]

Using one of these tags adds a class with the same name but in lowercase
(note, tip, etc.).


```````````````````````````````` example
> This is a normal blockquote without tag.
.
<blockquote><p>This is a normal blockquote without tag.</p></blockquote>
````````````````````````````````

```````````````````````````````` example
> [!NOTE]
> Note blockquote
.
<blockquote class="markdown-alert-note"><p>Note blockquote</p></blockquote>
````````````````````````````````

```````````````````````````````` example
> [!TIP]
> Tip blockquote
.
<blockquote class="markdown-alert-tip"><p>Tip blockquote</p></blockquote>
````````````````````````````````

```````````````````````````````` example
> [!IMPORTANT]
> Important blockquote
.
<blockquote class="markdown-alert-important"><p>Important blockquote</p></blockquote>
````````````````````````````````

```````````````````````````````` example
> [!WARNING]
> Warning blockquote
.
<blockquote class="markdown-alert-warning"><p>Warning blockquote</p></blockquote>
````````````````````````````````

```````````````````````````````` example
> [!CAUTION]
> Caution blockquote
.
<blockquote class="markdown-alert-caution"><p>Caution blockquote</p></blockquote>
````````````````````````````````

A blockquote with tag can be empty:
```````````````````````````````` example
> [!CAUTION]
.
<blockquote class="markdown-alert-caution"></blockquote>
````````````````````````````````

An a blockquote can have several lines:
```````````````````````````````` example
> [!CAUTION]
> Line 1.
> Line 2.
.
<blockquote class="markdown-alert-caution"><p>Line 1.
Line 2.</p></blockquote>
````````````````````````````````

Tags are ignored in subsequent lines, literally written:
```````````````````````````````` example
> [!CAUTION]
> Line 1.
> [!CAUTION]
> Line 2.
.
<blockquote class="markdown-alert-caution"><p>Line 1.
[!CAUTION]
Line 2.</p></blockquote>
````````````````````````````````

But nested blockquotes can have their own tag:
```````````````````````````````` example
> [!CAUTION]
> Line 1.
> > [!TIP]
> Line 2.
.
<blockquote class="markdown-alert-caution"><p>Line 1.</p><blockquote class="markdown-alert-tip"><p>Line 2.</p></blockquote></blockquote>
````````````````````````````````

And consecutive blockquotes too:
```````````````````````````````` example
> [!CAUTION]
> Line 1.


> [!TIP]
> Line 2.
.
<blockquote class="markdown-alert-caution"><p>Line 1.</p></blockquote><blockquote class="markdown-alert-tip"><p>Line 2.</p></blockquote>
````````````````````````````````

Tags also work in inner blockquotes:
```````````````````````````````` example
> > [!CAUTION]
> > Line 1.
> Line 2.
.
<blockquote><blockquote class="markdown-alert-caution"><p>Line 1.
Line 2.</p></blockquote></blockquote>
````````````````````````````````

Tags can be followed by spaces (works in most implementations):
```````````````````````````````` example
> [!CAUTION]→
> Line 1.
> > [!NOTE]
> > Line 2.
.
<blockquote class="markdown-alert-caution"><p>Line 1.</p>
<blockquote class="markdown-alert-note"><p>Line 2.</p></blockquote>
</blockquote>
````````````````````````````````

Tags are case-insensitive (works in most implementations):
```````````````````````````````` example
> [!caution]→
> Line 1.
> > [!note]
> > Line 2.
.
<blockquote class="markdown-alert-caution"><p>Line 1.</p>
<blockquote class="markdown-alert-note"><p>Line 2.</p></blockquote>
</blockquote>
````````````````````````````````

Tags work inside lists (doesn't work in GitHub, but works elsewhere):
```````````````````````````````` example
* loose lists

> [!NOTE]
> sink ships
.
<ul><li><p>loose lists</p>
<blockquote class="markdown-alert-note"><p>sink ships</p></blockquote>
</li></ul>
````````````````````````````````

Tags can act as lazy paragraph continuations (works in GitHub, not commonmark-hs):
```````````````````````````````` example
> [!NOTE]
sink ships

> [!NOTE]
> sink ships

* loose lists

> [!NOTE]
sink ships

> [!NOTE]
> sink ships
.
<blockquote class="markdown-alert-note"><p>sink ships</p></blockquote>
<blockquote class="markdown-alert-note"><p>sink ships</p></blockquote>
<ul><li><p>loose lists</p>
<blockquote class="markdown-alert-note"><p>sink ships</p></blockquote>
<blockquote class="markdown-alert-note"><p>sink ships</p></blockquote>
</li></ul>
````````````````````````````````

Like lazy continuations, the blockquote marker is still needed to make nested blocks:
```````````````````````````````` example
* loose lists

> [!NOTE]
- sink ships

> [!NOTE]
> - sink ships
.
<ul><li><p>loose lists</p>
<blockquote class="markdown-alert-note"></blockquote>
<ul><li>sink ships</li></ul>
<blockquote class="markdown-alert-note">
<ul><li>sink ships</li></ul></blockquote>
</li></ul>
````````````````````````````````
2 changes: 1 addition & 1 deletion pulldown-cmark/specs/footnotes.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Run this with `cargo test --features gen-tests suite::gfm_footnotes`.
Run this with `cargo test --features gen-tests suite::footnotes`.

Parts of this test case are based on
<https://github.com/github/cmark-gfm/blob/1e230827a584ebc9938c3eadc5059c55ef3c9abf/test/extensions.txt#L702>.
Expand Down
2 changes: 2 additions & 0 deletions pulldown-cmark/specs/heading_attrs.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Run this with `cargo test --features gen-tests suite::heading_attrs`.

Examples and edge cases for attribute blocks for headings.

# Basic usage
Expand Down
2 changes: 2 additions & 0 deletions pulldown-cmark/specs/math.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Run this with `cargo test --features gen-tests suite::math`.

# `$`-delimited LaTeX Math in pulldown-cmark

Mathematical expressions extension. Syntax based on
Expand Down
2 changes: 2 additions & 0 deletions pulldown-cmark/specs/metadata_blocks.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Run this with `cargo test --features gen-tests suite::metadata_blocks`.

Examples and edge cases for metadata blocks.

YAML-style and pluses-style metadata blocks are supported.
Expand Down
2 changes: 1 addition & 1 deletion pulldown-cmark/specs/old_footnotes.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Run this with `cargo test --features gen-tests suite::footnotes`.
Run this with `cargo test --features gen-tests suite::old_footnotes`.

This is how footnotes are basically used.

Expand Down

0 comments on commit 2540d40

Please sign in to comment.