Skip to content
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
29 changes: 29 additions & 0 deletions crates/pampa/resources/error-corpus/Q-2-37.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"code": "Q-2-37",
"title": "Line break in link destination",
"message": "An inline link destination cannot contain a line break.",
"notes": [],
"hints": [
"Remove the line break inside the link's `(...)` destination and keep the URL on a single line."
],
"cases": [
{
"name": "after-scheme",
"description": "Newline immediately after the scheme `://` of an inline link destination.",
"content": "[text](https://\nexample.com/path)\n",
"captures": []
},
{
"name": "mid-destination",
"description": "Newline within the host portion of an inline link destination.",
"content": "[text](https://example.\ncom/path)\n",
"captures": []
},
{
"name": "before-close-paren",
"description": "Newline immediately before the closing `)` of an inline link destination.",
"content": "[text](https://example.com/path\n)\n",
"captures": []
}
]
}
51 changes: 51 additions & 0 deletions crates/pampa/resources/error-corpus/_autogen-table.json
Original file line number Diff line number Diff line change
Expand Up @@ -17762,6 +17762,57 @@
},
"name": "Q-2-36/comma-and-kv"
},
{
"state": 2619,
"sym": "shortcode_name",
"row": 1,
"column": 0,
"errorInfo": {
"code": "Q-2-37",
"title": "Line break in link destination",
"message": "An inline link destination cannot contain a line break.",
"captures": [],
"notes": [],
"hints": [
"Remove the line break inside the link's `(...)` destination and keep the URL on a single line."
]
},
"name": "Q-2-37/after-scheme"
},
{
"state": 2619,
"sym": "shortcode_name",
"row": 1,
"column": 0,
"errorInfo": {
"code": "Q-2-37",
"title": "Line break in link destination",
"message": "An inline link destination cannot contain a line break.",
"captures": [],
"notes": [],
"hints": [
"Remove the line break inside the link's `(...)` destination and keep the URL on a single line."
]
},
"name": "Q-2-37/mid-destination"
},
{
"state": 2619,
"sym": "_close_block",
"row": 1,
"column": 0,
"errorInfo": {
"code": "Q-2-37",
"title": "Line break in link destination",
"message": "An inline link destination cannot contain a line break.",
"captures": [],
"notes": [],
"hints": [
"Remove the line break inside the link's `(...)` destination and keep the URL on a single line."
]
},
"name": "Q-2-37/before-close-paren"
},
{
"state": 1671,
"sym": "_close_block",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[text](https://
example.com/path)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[text](https://example.com/path
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[text](https://example.
com/path)
80 changes: 80 additions & 0 deletions crates/pampa/tests/test_link_destination_linebreak.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
use pampa::readers;

fn render_diagnostics(input: &str, filename: &str) -> String {
let mut content = input.to_string();
if !content.ends_with('\n') {
content.push('\n');
}

let result = readers::qmd::read(
content.as_bytes(),
false,
filename,
&mut std::io::sink(),
true,
None,
);

let diagnostics = match result {
Ok(_) => panic!("Expected diagnostics for input:\n{content}"),
Err(d) => d,
};

let mut source_context = quarto_source_map::SourceContext::new();
source_context.add_file(filename.to_string(), Some(content));

let render_options = quarto_error_reporting::TextRenderOptions {
enable_hyperlinks: false,
};

let mut output = String::new();
for diagnostic in &diagnostics {
output.push_str(&diagnostic.to_text_with_options(Some(&source_context), &render_options));
output.push('\n');
}
output
}

#[test]
fn line_break_after_scheme_emits_q_2_37() {
let input = "[text](https://\nexample.com/path)\n";
let output = render_diagnostics(input, "linebreak-after-scheme.qmd");

assert!(
output.contains("Q-2-37") || output.contains("Line break in link destination"),
"Diagnostic should identify line-break-in-link-destination case. Got:\n{output}"
);
}

#[test]
fn line_break_mid_destination_emits_q_2_37() {
let input = "[text](https://example.\ncom/path)\n";
let output = render_diagnostics(input, "linebreak-mid-dest.qmd");

assert!(
output.contains("Q-2-37") || output.contains("Line break in link destination"),
"Diagnostic should identify line-break-in-link-destination case. Got:\n{output}"
);
}

#[test]
fn line_break_before_close_paren_emits_q_2_37() {
let input = "[text](https://example.com/path\n)\n";
let output = render_diagnostics(input, "linebreak-before-close-paren.qmd");

assert!(
output.contains("Q-2-37") || output.contains("Line break in link destination"),
"Diagnostic should identify line-break-in-link-destination case. Got:\n{output}"
);
}

#[test]
fn quarto_web_penguins_example_emits_q_2_37() {
let input = "A simple example based on Allison Horst's [Palmer Penguins](https://\nallisonhorst.github.io/palmerpenguins/) dataset. Here we look at how penguin body mass varies across both sex and species.\n";
let output = render_diagnostics(input, "penguins.qmd");

assert!(
output.contains("Q-2-37") || output.contains("Line break in link destination"),
"Diagnostic should identify line-break-in-link-destination case. Got:\n{output}"
);
}