You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// quotes"](https://spec.commonmark.org/0.30/#block-quotes), but note that only a subset of
439
+
/// CommonMark is recognized - see the doc comment of [`ItemizedBlock::get_marker_length`] for more
440
+
/// details.
441
+
///
436
442
/// Different level of indentation are handled by shrinking the shape accordingly.
437
443
structItemizedBlock{
438
444
/// the lines that are identified as part of an itemized block
439
445
lines:Vec<String>,
440
-
/// the number of characters (typically whitespaces) up to the item sigil
446
+
/// the number of characters (typically whitespaces) up to the item marker
441
447
indent:usize,
442
448
/// the string that marks the start of an item
443
449
opener:String,
@@ -446,37 +452,70 @@ struct ItemizedBlock {
446
452
}
447
453
448
454
implItemizedBlock{
449
-
/// Returns `true` if the line is formatted as an item
450
-
fnis_itemized_line(line:&str) -> bool{
451
-
let trimmed = line.trim_start();
455
+
/// Checks whether the `trimmed` line includes an item marker. Returns `None` if there is no
456
+
/// marker. Returns the length of the marker (in bytes) if one is present. Note that the length
457
+
/// includes the whitespace that follows the marker, for example the marker in `"* list item"`
458
+
/// has the length of 2.
459
+
///
460
+
/// This function recognizes item markers that correspond to CommonMark's
461
+
/// ["bullet list marker"](https://spec.commonmark.org/0.30/#bullet-list-marker),
/// ["ordered list marker"](https://spec.commonmark.org/0.30/#ordered-list-marker).
464
+
///
465
+
/// Compared to CommonMark specification, the number of digits that are allowed in an ["ordered
466
+
/// list marker"](https://spec.commonmark.org/0.30/#ordered-list-marker) is more limited (to at
467
+
/// most 2 digits). Limiting the length of the marker helps reduce the risk of recognizing
468
+
/// arbitrary numbers as markers. See also
469
+
/// <https://talk.commonmark.org/t/blank-lines-before-lists-revisited/1990> which gives the
470
+
/// following example where a number (i.e. "1868") doesn't signify an ordered list:
// Non-numeric item markers (e.g. `a.` or `iv.`) are not allowed by
2117
+
// https://spec.commonmark.org/0.30/#ordered-list-marker. We also note that allowing
2118
+
// them would risk misidentifying regular words as item markers. See also the
2119
+
// discussion in https://talk.commonmark.org/t/blank-lines-before-lists-revisited/1990
2120
+
"word. rest of the paragraph.",
2121
+
"a. maybe this is a list item? maybe not?",
2122
+
"iv. maybe this is a list item? maybe not?",
2123
+
// Numbers with 3 or more digits are not recognized as item markers, to avoid
2124
+
// formatting the following example as a list:
2125
+
//
2126
+
// ```
2127
+
// The Captain died in
2128
+
// 1868. He was buried in...
2129
+
// ```
2130
+
"123. only 2-digit numbers are recognized as item markers.",
2131
+
// Parens:
2132
+
"123) giving some coverage to parens as well.",
2133
+
"a) giving some coverage to parens as well.",
2134
+
// https://spec.commonmark.org/0.30 says that "at least one space or tab is needed
2135
+
// between the list marker and any following content":
2136
+
"1.Not a list item.",
2137
+
"1.2.3. Not a list item.",
2138
+
"1)Not a list item.",
2139
+
"-Not a list item.",
2140
+
"+Not a list item.",
2141
+
"+1 not a list item.",
2142
+
// https://spec.commonmark.org/0.30 says: "A start number may not be negative":
2143
+
"-1. Not a list item.",
2144
+
"-1 Not a list item.",
2145
+
];
2146
+
for line in test_inputs.iter(){
2147
+
let maybe_block = ItemizedBlock::new(line);
2148
+
assert!(
2149
+
maybe_block.is_none(),
2150
+
"The following line shouldn't be classified as a list item: {}",
0 commit comments