Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable GitLab multiline alerts #521

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions script/cibuild
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ python3 spec_tests.py --no-normalize --spec ../../../src/tests/fixtures/descript
|| failed=1
python3 spec_tests.py --no-normalize --spec ../../../src/tests/fixtures/alerts.md "$PROGRAM_ARG -e alerts" \
|| failed=1
python3 spec_tests.py --no-normalize --spec ../../../src/tests/fixtures/multiline_alerts.md "$PROGRAM_ARG -e alerts -e multiline-block-quotes" \
|| failed=1

python3 spec_tests.py --no-normalize --spec regression.txt "$PROGRAM_ARG" \
|| failed=1
Expand Down
6 changes: 6 additions & 0 deletions src/parser/alert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ pub struct NodeAlert {

/// Originated from a multiline blockquote.
pub multiline: bool,

/// The length of the fence (multiline only).
pub fence_length: usize,

/// The indentation level of the fence marker (multiline only)
pub fence_offset: usize,
}

/// The type of alert.
Expand Down
32 changes: 27 additions & 5 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1525,8 +1525,17 @@ where
return (false, container, should_continue);
}
}
NodeValue::Alert(..) => {
if !self.parse_block_quote_prefix(line) {
NodeValue::Alert(ref alert) => {
if alert.multiline {
if !self.parse_multiline_block_quote_prefix(
line,
container,
ast,
&mut should_continue,
) {
return (false, container, should_continue);
}
} else if !self.parse_block_quote_prefix(line) {
return (false, container, should_continue);
}
}
Expand Down Expand Up @@ -2033,20 +2042,32 @@ where

let alert_startpos = self.first_nonspace;
let mut title_startpos = self.first_nonspace;
let mut fence_length = 0;

while line[title_startpos] != b']' {
if line[title_startpos] == b'>' {
fence_length += 1
}
title_startpos += 1;
}
title_startpos += 1;

if fence_length == 2
|| (fence_length >= 3 && !self.options.extension.multiline_block_quotes)
{
return false;
}

// anything remaining on this line is considered an alert title
let mut tmp = entity::unescape_html(&line[title_startpos..]);
strings::trim(&mut tmp);
strings::unescape(&mut tmp);

let na = NodeAlert {
alert_type,
multiline: false,
multiline: fence_length >= 3,
fence_length,
fence_offset: self.first_nonspace - self.offset,
title: if tmp.is_empty() {
None
} else {
Expand Down Expand Up @@ -2077,8 +2098,8 @@ where
self.find_first_nonspace(line);
let indented = self.indent >= CODE_INDENT;

if self.handle_multiline_blockquote(container, line, indented, &mut matched)
|| self.handle_alert(container, line, indented)
if self.handle_alert(container, line, indented)
|| self.handle_multiline_blockquote(container, line, indented, &mut matched)
|| self.handle_blockquote(container, line, indented)
|| self.handle_atx_heading(container, line, indented, &mut matched)
|| self.handle_code_fence(container, line, indented, &mut matched)
Expand Down Expand Up @@ -2397,6 +2418,7 @@ where
NodeValue::MultilineBlockQuote(ref node_value) => {
(node_value.fence_length, node_value.fence_offset)
}
NodeValue::Alert(ref node_value) => (node_value.fence_length, node_value.fence_offset),
_ => unreachable!(),
};

Expand Down
11 changes: 6 additions & 5 deletions src/scanners.re
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,13 @@ pub fn alert_start(s: &[u8]) -> Option<AlertType> {
let mut cursor = 0;
let mut marker = 0;
let len = s.len();

/*!re2c
'> [!note]' { return Some(AlertType::Note); }
'> [!tip]' { return Some(AlertType::Tip); }
'> [!important]' { return Some(AlertType::Important); }
'> [!warning]' { return Some(AlertType::Warning); }
'> [!caution]' { return Some(AlertType::Caution); }
[>]{1,} ' [!note]' { return Some(AlertType::Note); }
[>]{1,} ' [!tip]' { return Some(AlertType::Tip); }
[>]{1,} ' [!important]' { return Some(AlertType::Important); }
[>]{1,} ' [!warning]' { return Some(AlertType::Warning); }
[>]{1,} ' [!caution]' { return Some(AlertType::Caution); }
* { return None; }
*/
}
Expand Down
Loading
Loading