Skip to content

Commit ebd7d2f

Browse files
committed
Merge branch 'space-footnotes' into 'master'
Require spacing between paragraphs and footnotes See merge request mkjeldsen/commitmsgfmt!38
2 parents 3565887 + e85b945 commit ebd7d2f

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ understanding of patterns often seen in commit messages.
1212
- Extend the range of non-breakable tokens to include any sequence of ASCII
1313
punctuation. Previously `foo ...` could wrap; now it cannot.
1414

15+
- Restrict the definition of footnotes to require a vertical space after
16+
a preceding paragraph. This prevents footnote references that have ended up
17+
at the start of a line from degenerating into footnotes. That is, previously
18+
`foo\n[1] bar` would be a paragraph followed by a footnote whereas now it is
19+
a single paragraph containing a footnote reference.
20+
1521
## 1.4.1 - 2021-04-05
1622

1723
- Fix an errant man page header accidentally added in v1.4.0.

doc/commitmsgfmt.1.adoc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,16 @@ a space is considered a _footnote_:
128128
Official Git Web site [1][git]
129129
130130
[1] https://git-scm.com/
131-
[git]: https://git-scm.com/
131+
[git]: Git is a free and open source distributed version control system
132+
designed to handle everything from small to very large projects
133+
with speed and efficiency.
132134
----
133135

134136
This syntax is inspired by the IEEE whitepaper reference style.
135137

138+
Multiple footnotes may follow each other immediately, however, the first
139+
footnote in any block of footnotes must be preceded by an empty line.
140+
136141
Footnotes are wrapped like _paragraphs_, with continuation lines space-indented
137142
to match the first line. Additional spaces after the mandatory space are
138143
stripped. Footnotes are not considered to have a natural order and

src/commitmsgfmt.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ foo
223223
foo
224224
225225
paragraph
226+
226227
[2] note
227228
[1] note
228229
[3] foo bar baz qux https://a.really-long-url.example
@@ -236,6 +237,7 @@ paragraph
236237
foo
237238
238239
paragraph
240+
239241
[2] note
240242
[1] note
241243
[3] foo bar baz qux
@@ -279,12 +281,11 @@ x [1]
279281
x [1].
280282
x [1] .
281283
282-
yy [2] y
283-
[2] .
284+
yy [2]
285+
y [2] .
284286
285287
zzz [3]
286-
z
287-
[3] .
288+
z [3] .
288289
289290
www [4]
290291
w

src/parser.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub fn parse(input: &str, comment_char: char) -> Vec<Token> {
5555
\s+)",
5656
)
5757
.unwrap();
58+
let mut px = false;
5859
for line in lines {
5960
if has_scissors {
6061
match *toks.last_mut().expect("has_scissors") {
@@ -79,10 +80,12 @@ pub fn parse(input: &str, comment_char: char) -> Vec<Token> {
7980
if toks.last() != Some(&Token::VerticalSpace) {
8081
toks.push(Token::VerticalSpace);
8182
}
83+
px = true;
8284
} else if !has_subject {
8385
parse_subject(line, &mut toks);
8486
has_subject = true;
85-
} else if footnote.is_match(line) {
87+
px = false;
88+
} else if px && footnote.is_match(line) {
8689
debug_assert!(footnote.as_str().contains(' '));
8790
let mut splitter = line.splitn(2, ' ');
8891
let key = splitter.next().unwrap().to_owned();
@@ -118,6 +121,7 @@ pub fn parse(input: &str, comment_char: char) -> Vec<Token> {
118121
raw.push('\n'); // Recover linefeed lost from iterator.
119122
Some(Token::Literal(raw))
120123
} else {
124+
px = false;
121125
Some(Token::Paragraph(line.trim().to_owned()))
122126
}
123127
}
@@ -525,7 +529,7 @@ Signed-off-by: Jane Doe <jane@doe.com>
525529
}
526530

527531
#[test]
528-
fn footnotes_are_left_bracket_ident_right_bracket_space_text() {
532+
fn footnotes_are_left_bracket_ident_right_bracket_space_text_distanced_from_paragraph() {
529533
assert_eq!(
530534
parse(
531535
"
@@ -564,13 +568,18 @@ subject
564568
}
565569

566570
#[test]
567-
fn footnote_does_not_join_immediately_preceding_paragraph() {
571+
fn footnote_cannot_follow_paragraph_immediately() {
568572
assert_eq!(
569573
parse(
570574
"
571575
subject
572576
573-
paragraph
577+
paragraph 1
578+
[1] not footnote 1
579+
[2] not footnote 2
580+
581+
paragraph 2
582+
574583
[1] footnote 1
575584
[2] footnote 2
576585
"
@@ -579,7 +588,10 @@ paragraph
579588
VerticalSpace,
580589
Subject("subject".to_owned()),
581590
VerticalSpace,
582-
Paragraph("paragraph".to_owned()),
591+
Paragraph("paragraph 1 [1] not footnote 1 [2] not footnote 2".to_owned()),
592+
VerticalSpace,
593+
Paragraph("paragraph 2".to_owned()),
594+
VerticalSpace,
583595
Footnote("[1]".to_owned(), "footnote 1".to_owned()),
584596
Footnote("[2]".to_owned(), "footnote 2".to_owned()),
585597
],

0 commit comments

Comments
 (0)