Skip to content
Closed
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
8 changes: 4 additions & 4 deletions src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn strip_trailing_attr(src: &str, defs: &HashMap<String, Attr>) -> (String,
};
let body = &trimmed[open + 1..trimmed.len() - 1];
let body = body.strip_prefix(':').unwrap_or(body).trim();
if !looks_like_attrs(body) {
if !looks_like_attrs(body, defs) {
return (src.trim().to_string(), Attr::default());
}
(
Expand Down Expand Up @@ -73,7 +73,7 @@ pub fn parse_braced_attr(src: &str, defs: &HashMap<String, Attr>) -> Option<(Att
if ch == '}' {
let body = &src[1..i];
let body = body.strip_prefix(':').unwrap_or(body).trim();
if looks_like_attrs(body) {
if looks_like_attrs(body, defs) {
return Some((parse_attrs_body(body, defs), i + 1));
}
return None;
Expand Down Expand Up @@ -396,13 +396,13 @@ fn last_attr_open(s: &str) -> Option<usize> {
last
}

fn looks_like_attrs(body: &str) -> bool {
fn looks_like_attrs(body: &str, defs: &HashMap<String, Attr>) -> bool {
let b = body.trim();
b.starts_with('#')
|| b.starts_with('.')
|| b.contains('=')
|| b.split_whitespace()
.any(|t| t.starts_with('#') || t.starts_with('.') || t.contains('='))
.any(|t| t.starts_with('#') || t.starts_with('.') || t.contains('=') || defs.contains_key(t))
}

fn attr_tokens(body: &str) -> Vec<String> {
Expand Down
14 changes: 14 additions & 0 deletions tests/test_focused.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ def test_balance_ignores_rawtext_and_voids():
assert "</div>" not in html
assert "<br />" in html

def test_ald_reference_alone_in_block_ial():
expected = '<p id="id" class="cls">Some text</p>\n'
assert to_xhtml("{:note: #id .cls}\n\nSome text\n{: note}\n") == expected
assert to_xhtml("{:note: #id .cls}\n\nSome text\n{:note}\n") == expected
assert to_xhtml("{:note: #id .cls}\nSome text\n{: note}\n") == expected

def test_ald_reference_alone_in_span_ial():
html = to_xhtml("{:note: .cls}\n\nA [word]{: note} here\n")
assert '<span class="cls">word</span>' in html

def test_undefined_ald_reference_stays_literal():
assert to_xhtml("Some text\n{: nope}\n") == "<p>Some text\n{: nope}</p>\n"
assert "[word]{nope}" in to_xhtml("A [word]{nope} here\n")

def test_long_nonascii_words_near_autolink_cap_do_not_error():
for boundary in ("(", "a: ", "x '"):
for count in (126, 127, 128, 129, 130, 200):
Expand Down
Loading