mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-06 02:09:46 -06:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d2f5445cc |
+2
-2
File diff suppressed because one or more lines are too long
@@ -474,14 +474,17 @@ fn parse_blocks(lines: &[String], depth: usize, level: u8, refs: &Refs) -> Vec<F
|
||||
let p = Para { align: a, inlines: parse_inlines(s, &Fmt::default(), depth, refs), ..Default::default() };
|
||||
Cell { blocks: vec![FBlock::Para(p)], header, ..Default::default() }
|
||||
};
|
||||
table.rows.push(head.iter().zip(&aligns).map(|(s, a)| cell(s, true, *a)).collect());
|
||||
// A document row keeps MAX_COLS cells: only those are built, so a wide header
|
||||
// doesn't pad every sparse row below it out to its width.
|
||||
let cols = aligns.len().min(wordcraft_doc::table::MAX_COLS);
|
||||
table.rows.push(head.iter().zip(&aligns).take(cols).map(|(s, a)| cell(s, true, *a)).collect());
|
||||
i += 2;
|
||||
while let Some(l) = lines.get(i) {
|
||||
if is_blank(l) || !l.contains('|') || interrupts(l) {
|
||||
break;
|
||||
}
|
||||
let mut cells = split_row(l);
|
||||
cells.resize(aligns.len(), String::new());
|
||||
cells.resize(cols, String::new());
|
||||
table.rows.push(cells.iter().zip(&aligns).map(|(s, a)| cell(s, false, *a)).collect());
|
||||
i += 1;
|
||||
}
|
||||
|
||||
@@ -714,3 +714,17 @@ fn exported_link_destinations_read_back_unchanged() {
|
||||
assert_eq!(md("https://example.com/a b"), "[x](<https://example.com/a b>)");
|
||||
assert_eq!(md("https://e.com/x\ny"), "[x](https://e.com/xy)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_wide_table_builds_only_the_cells_a_row_keeps() {
|
||||
// A 5,000-column header padded every one-cell row below it to 5,000 cells.
|
||||
let n = 5000;
|
||||
let md = format!("{}|\n{}|\n{}", "|h".repeat(n), "|-".repeat(n), "|x|\n".repeat(200));
|
||||
let flow = parse(&md);
|
||||
let FBlock::Table(t) = &flow.blocks[0] else { panic!("expected table") };
|
||||
assert_eq!(t.rows.len(), 201);
|
||||
assert!(t.rows.iter().all(|r| r.len() == wordcraft_doc::table::MAX_COLS));
|
||||
// A narrow table is unchanged.
|
||||
let FBlock::Table(t) = &parse("| a | b |\n| - | - |\n| x |\n").blocks[0] else { panic!("expected table") };
|
||||
assert_eq!(t.rows[1].len(), 2);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::balloons::over_balloon;
|
||||
use super::links::{field_showing_code, for_launcher, is_followable_link, is_generated_bookmark_link, link_under};
|
||||
use super::links::{field_showing_code, is_followable_link, is_generated_bookmark_link, link_under};
|
||||
use super::navigation::page_at;
|
||||
use super::story::{enters_header_footer, in_text_box, part_kind, text_box_host};
|
||||
use super::{CanvasState, DocLayout, PartKind, Pos, Pos2, Rect, StoryRef, Ui, WordApp, json};
|
||||
@@ -335,7 +335,7 @@ fn handle_primary_press(
|
||||
let _ = app.run("select.collapse", json!({}));
|
||||
}
|
||||
} else if is_followable_link(&link) {
|
||||
app.canvas.open_url = Some(for_launcher(&link));
|
||||
app.canvas.open_url = Some(link);
|
||||
} else {
|
||||
app.status(tl!("Only web (http, https) and email (mailto) links can be followed"));
|
||||
}
|
||||
|
||||
@@ -48,19 +48,3 @@ pub(super) fn is_generated_bookmark_link(link: &str) -> bool {
|
||||
pub(super) fn is_followable_link(url: &str) -> bool {
|
||||
wordcraft_doc::link::is_web_or_mail_link(url)
|
||||
}
|
||||
|
||||
/// `url` as it is handed to the system to open: the characters a Windows command line acts on
|
||||
/// (`|`, `<`, `>`, `(`, `)`, `^`, `!`, `"`, and spaces) percent-encoded, which a browser reads the
|
||||
/// same. Under WSL the browser crate starts the link through `cmd.exe /c start`, escaping only
|
||||
/// `^` and `&`, so `https://x/a|calc` would run `calc`. `&` is left alone: it separates a query's
|
||||
/// fields, and that launcher escapes it.
|
||||
pub(super) fn for_launcher(url: &str) -> String {
|
||||
let mut out = String::with_capacity(url.len());
|
||||
for c in url.chars() {
|
||||
match c {
|
||||
'|' | '<' | '>' | '(' | ')' | '^' | '!' | '"' | ' ' => out.push_str(&format!("%{:02X}", c as u32)),
|
||||
c => out.push(c),
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
@@ -2646,17 +2646,6 @@ fn only_web_and_email_links_are_followed() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn followed_links_reach_the_launcher_without_command_line_syntax() {
|
||||
use super::links::for_launcher;
|
||||
assert_eq!(for_launcher("https://x.example/a|calc"), "https://x.example/a%7Ccalc");
|
||||
assert_eq!(for_launcher("https://x.example/a^b<c>d(e)f!g\"h i"), "https://x.example/a%5Eb%3Cc%3Ed%28e%29f%21g%22h%20i");
|
||||
// Ordinary links, queries and existing escapes are unchanged.
|
||||
for ok in ["https://example.com/a?b=1&c=2#d", "mailto:someone@example.com", "https://example.com/caf%C3%A9"] {
|
||||
assert_eq!(for_launcher(ok), ok);
|
||||
}
|
||||
}
|
||||
|
||||
/// Ctrl+click on a link to a bookmark puts the caret at the bookmark's start, as Word does;
|
||||
/// only Go To selects the bookmark's text (#1236).
|
||||
#[test]
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user