Skip to content

Commit c721e8f

Browse files
committed
Document fenced code blocks
References: https://gitlab.com/mkjeldsen/commitmsgfmt/-/issues/7
1 parent 1e6ea0a commit c721e8f

File tree

2 files changed

+86
-10
lines changed

2 files changed

+86
-10
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ understanding of patterns often seen in commit messages.
99
in their entirety, and allow them to follow a preceding paragraph without the
1010
empty line that is otherwise usually required.
1111

12+
- #7: Recognize fenced code blocks with backtick code fences (` ``` `) and
13+
preserve them in their entirety. Do not recognize tilde code fences (`~~~`),
14+
which are virtually never used in practice and which would interfere with
15+
many other uses. Per CommonMark 0.3.0 a code fence must be at least three
16+
characters long and may optionally be indented up to three spaces, and the
17+
closing code fence must be at least as long as the opening code fence
18+
ignoring whitespace.
19+
1220
- If `--width` is specified multiple times, ignore all but the last occurrence.
1321

1422
## 1.5.0 - 2022-07-30

doc/commitmsgfmt.1.adoc

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ The exact formatting behavior is implementation defined. This section attempts
5858
to describe the rules but deviation may be either an inexpediency in the
5959
implementation or an error in the description.
6060

61+
{self} does not attempt to recognize AsciiDoc, CommonMark, Markdown,
62+
reStructuredText, or any other markup language. Formally, {self} recognizes
63+
only plain text, and similarity to any markup language is incidental.
64+
6165
NOTE: Depending on your expectations of merge commit messages you may find
6266
{self} unsuitable for use in such messages. If you write them precisely like
6367
you write non-merge commit messages, go ahead and format them with {self}.
@@ -95,9 +99,9 @@ those cases and avoid them by preventing wrapping: it will
9599
references both preserve their context and don't degenerate into _list
96100
items_.
97101

98-
_Block quotes_ are exempt from the requirement of surrounding blank lines and
99-
will never be considered to belong to a paragraph. A block quote embedded
100-
inside a paragraph has the same effect on that paragraph as an empty line has.
102+
A paragraph may be interrupted by _block quotes_ and _fenced code blocks_,
103+
meaning these are exempt from the requirement of surrounding blank lines and
104+
will never be considered to belong to a paragraph.
101105

102106
=== Subject line
103107

@@ -196,8 +200,64 @@ literals.
196200

197201
=== Literal
198202

199-
A line starting with one tab or four spaces is considered a _literal_. Literals
200-
are printed verbatim, making them suitable for listings and tables.
203+
A line starting with one tab or four spaces is considered a _literal_:
204+
205+
----
206+
paragraph
207+
208+
literal
209+
210+
paragraph
211+
----
212+
213+
Literals are printed verbatim, making them suitable for listings and tables.
214+
215+
See also _fenced code block_.
216+
217+
=== Code fence
218+
219+
Outside of a _fenced code block_ a line starting with up to 3 spaces followed
220+
by at least 3 consecutive backticks (*`*) is considered an _opening code
221+
fence_:
222+
223+
----
224+
```opening
225+
----
226+
227+
Within a fenced code block a line starting with up to 3 spaces followed by at
228+
least as many consecutive backticks as the preceding opening code fence is
229+
considered a _closing code fence_; any sequence of fewer backticks is ignored:
230+
231+
----
232+
````opening
233+
```
234+
`````
235+
----
236+
237+
NOTE: For sake of compatibility, tilde (*~*) cannot be used in place of
238+
backtick.
239+
240+
=== Fenced code block
241+
242+
A _fenced code block_ begins with an _opening code fence_ and ends with the
243+
first following _closing code fence_:
244+
245+
----
246+
Compare the previous version of origin/topic with the current version:
247+
```sh
248+
$ git range-diff origin/main origin/topic@{1} origin/topic
249+
```
250+
----
251+
252+
The fenced code block includes both code fences and all contents in-between the
253+
code fences.
254+
255+
Fenced code blocks are printed verbatim, making them suitable for listings.
256+
Fenced code blocks are more flexible in their use than _literals_ are but
257+
otherwise solve the same problem.
258+
259+
A fenced code block may interrupt a _paragraph_; it needs no preceding or
260+
following blank line.
201261

202262
=== Block quote
203263

@@ -226,11 +286,9 @@ vip:!fmt -w72 -p'>'
226286
----
227287
====
228288

229-
Unlike other constructs a block quote may be embedded inside a _paragraph_ with
230-
no preceding or following blank line; the block quote will not be folded into
231-
the paragraph and the paragraph will otherwise observe standard behavior. This
232-
enables a common pattern of immediately preceding the block quote with an
233-
author attribution, illustrated above.
289+
A block quote may interrupt a _paragraph_; it needs no preceding or following
290+
blank line. This enables a common pattern of immediately preceding the block
291+
quote with an author attribution, illustrated above.
234292

235293
=== Comment
236294

@@ -309,6 +367,11 @@ foo baar -- baz qux wupwupwup [1][2] [wup]
309367
hex:
310368
> 0 1 2 3 4 5 6 7 8 9 a b c d e f
311369
370+
chicken:
371+
```chicken
372+
chicken chicken
373+
```
374+
312375
- foo
313376
1. foo bar
314377
baz
@@ -332,6 +395,11 @@ wupwupwup [1][2] [wup]
332395
hex:
333396
> 0 1 2 3 4 5 6 7 8 9 a b c d e f
334397
398+
chicken:
399+
```chicken
400+
chicken chicken
401+
```
402+
335403
- foo
336404
1. foo bar
337405
baz

0 commit comments

Comments
 (0)