diff --git a/src/attrs.rs b/src/attrs.rs index d599508..becd77b 100644 --- a/src/attrs.rs +++ b/src/attrs.rs @@ -36,7 +36,7 @@ pub fn strip_trailing_attr(src: &str, defs: &HashMap) -> (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()); } ( @@ -73,7 +73,7 @@ pub fn parse_braced_attr(src: &str, defs: &HashMap) -> 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; @@ -396,13 +396,13 @@ fn last_attr_open(s: &str) -> Option { last } -fn looks_like_attrs(body: &str) -> bool { +fn looks_like_attrs(body: &str, defs: &HashMap) -> 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 { diff --git a/tests/test_focused.py b/tests/test_focused.py index c0bca57..1963290 100644 --- a/tests/test_focused.py +++ b/tests/test_focused.py @@ -90,6 +90,20 @@ def test_balance_ignores_rawtext_and_voids(): assert "" not in html assert "
" in html +def test_ald_reference_alone_in_block_ial(): + expected = '

Some text

\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 'word' in html + +def test_undefined_ald_reference_stays_literal(): + assert to_xhtml("Some text\n{: nope}\n") == "

Some text\n{: nope}

\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):