Skip to content

Commit 06f67c2

Browse files
committed
u
1 parent 75a3461 commit 06f67c2

File tree

7 files changed

+60
-31
lines changed

7 files changed

+60
-31
lines changed

src/comment.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,9 @@ impl ItemizedBlock {
462462
fn get_marker_length(trimmed: &str) -> Option<usize> {
463463
// https://spec.commonmark.org/0.30/#bullet-list-marker or
464464
// https://spec.commonmark.org/0.30/#block-quote-marker
465-
let itemized_start = ["* ", "- ", "> ", "+ "];
466-
if itemized_start.iter().any(|s| trimmed.starts_with(s)) {
467-
return Some(2); // All items in `itemized_start` have length 2.
465+
let itemized_start = ["* ", "- ", ">", "+ "];
466+
if let Some(s) = itemized_start.iter().find(|&&s| trimmed.starts_with(s)) {
467+
return Some(s.len());
468468
}
469469

470470
// https://spec.commonmark.org/0.30/#ordered-list-marker, where at most 2 digits are
@@ -491,12 +491,12 @@ impl ItemizedBlock {
491491
let mut line_start = " ".repeat(indent);
492492

493493
// Markdown blockquote start with a "> "
494-
if line.trim_start().starts_with("> ") {
495-
// remove the original +2 indent because there might be multiple nested block quotes
494+
if line.trim_start().starts_with('>') {
495+
// remove the original +1 indent because there might be multiple nested block quotes
496496
// and it's easier to reason about the final indent by just taking the length
497497
// of the new line_start. We update the indent because it effects the max width
498498
// of each formatted line.
499-
line_start = itemized_block_quote_start(line, line_start, 2);
499+
line_start = itemized_block_quote_start(line, line_start, 1);
500500
indent = line_start.len();
501501
}
502502

@@ -557,11 +557,10 @@ fn itemized_block_quote_start(line: &str, mut line_start: String, remove_indent:
557557

558558
while chars.peek() == Some(&'>') {
559559
chars.next();
560-
if chars.peek() == Some(&' ') {
560+
quote_level += 1;
561+
// Skip all spaces after '>'
562+
while chars.peek() == Some(&' ') {
561563
chars.next();
562-
quote_level += 1;
563-
} else {
564-
break;
565564
}
566565
}
567566

@@ -570,7 +569,7 @@ fn itemized_block_quote_start(line: &str, mut line_start: String, remove_indent:
570569
}
571570

572571
for _ in 0..quote_level {
573-
line_start.push_str("> ")
572+
line_start.push_str("> ");
574573
}
575574

576575
line_start

tests/source/issue-6660.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/source/itemized-blocks/no_wrap.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,12 @@ fn func2() {}
7979
/// * `tag` is a tag that identifies the message type
8080
/// * `msg` is the (serialized) message
8181
fn func3() {}
82+
83+
/// >>This is a blockquote comment that is very long and should be wrapped according to max_width setting
84+
/// >> This is a blockquote comment that is very long and should be wrapped according to max_width setting
85+
/// > >This is a blockquote comment that is very long and should be wrapped according to max_width setting
86+
/// > > This is a blockquote comment that is very long and should be wrapped according to max_width setting
87+
/// > > This is a blockquote comment that is very long and should be wrapped according to max_width setting
88+
/// > >= >> >>= >>> >>>= This is a blockquote comment that is very long and should be wrapped according to max_width setting
89+
/// > > = >> >>= >>> >>>= This is a blockquote comment that is very long and should be wrapped according to max_width setting
90+
fn func4() {}

tests/source/itemized-blocks/wrap.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,12 @@ fn func2() {}
8787
/// * `tag` is a tag that identifies the message type
8888
/// * `msg` is the (serialized) message
8989
fn func3() {}
90+
91+
/// >>This is a blockquote comment that is very long and should be wrapped according to max_width setting
92+
/// >> This is a blockquote comment that is very long and should be wrapped according to max_width setting
93+
/// > >This is a blockquote comment that is very long and should be wrapped according to max_width setting
94+
/// > > This is a blockquote comment that is very long and should be wrapped according to max_width setting
95+
/// > > This is a blockquote comment that is very long and should be wrapped according to max_width setting
96+
/// > >= >> >>= >>> >>>= This is a blockquote comment that is very long and should be wrapped according to max_width setting
97+
/// > > = >> >>= >>> >>>= This is a blockquote comment that is very long and should be wrapped according to max_width setting
98+
fn func4() {}

tests/target/issue-6660.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/target/itemized-blocks/no_wrap.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,12 @@ fn func2() {}
7979
/// * `tag` is a tag that identifies the message type
8080
/// * `msg` is the (serialized) message
8181
fn func3() {}
82+
83+
/// >>This is a blockquote comment that is very long and should be wrapped according to max_width setting
84+
/// >> This is a blockquote comment that is very long and should be wrapped according to max_width setting
85+
/// > >This is a blockquote comment that is very long and should be wrapped according to max_width setting
86+
/// > > This is a blockquote comment that is very long and should be wrapped according to max_width setting
87+
/// > > This is a blockquote comment that is very long and should be wrapped according to max_width setting
88+
/// > >= >> >>= >>> >>>= This is a blockquote comment that is very long and should be wrapped according to max_width setting
89+
/// > > = >> >>= >>> >>>= This is a blockquote comment that is very long and should be wrapped according to max_width setting
90+
fn func4() {}

tests/target/itemized-blocks/wrap.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,26 @@ fn func2() {}
147147
/// type
148148
/// * `msg` is the (serialized) message
149149
fn func3() {}
150+
151+
/// >>This is a blockquote comment that is very
152+
/// > > long and should be wrapped according to
153+
/// > > max_width setting
154+
/// >> This is a blockquote comment that is very
155+
/// > > long and should be wrapped according to
156+
/// > > max_width setting
157+
/// > >This is a blockquote comment that is very
158+
/// > > long and should be wrapped according to
159+
/// > > max_width setting
160+
/// > > This is a blockquote comment that is
161+
/// > > very long and should be wrapped according
162+
/// > > to max_width setting
163+
/// > > This is a blockquote comment that is
164+
/// > > very long and should be wrapped according
165+
/// > > to max_width setting
166+
/// > >=>> >>= >>> >>>= This is a blockquote
167+
/// > > comment that is very long and should be
168+
/// > > wrapped according to max_width setting
169+
/// > > = >> >>= >>> >>>= This is a blockquote
170+
/// > > comment that is very long and should be
171+
/// > > wrapped according to max_width setting
172+
fn func4() {}

0 commit comments

Comments
 (0)