Skip to content
Open
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ codegen-units = 1
[dependencies]
html-escape = ">=0.2"
pyo3 = ">=0.28"
unicode-properties = "0.1"
unicode-width = "0.2"

[features]
Expand Down
10 changes: 8 additions & 2 deletions src/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::entity::decode_entities as decode_html_entities;
use crate::tagfilter::tagfilter_html;
use crate::{MathMode, Options};
use std::collections::{HashMap, HashSet};
use unicode_properties::{GeneralCategoryGroup, UnicodeGeneralCategory};

const ESCAPED_AMP: char = '\u{E000}';

Expand Down Expand Up @@ -601,11 +602,16 @@ struct Delimiter {
active: bool,
}

// Spec "punctuation character": ASCII punctuation or Unicode general category P.
fn is_flanking_punct(ch: char) -> bool {
ch.is_ascii_punctuation() || ch.general_category_group() == GeneralCategoryGroup::Punctuation
}

fn delimiter_run_flags(ch: char, before: char, after: char) -> (bool, bool) {
let before_ws = before == '\0' || before.is_whitespace();
let after_ws = after == '\0' || after.is_whitespace();
let before_punct = before.is_ascii_punctuation();
let after_punct = after.is_ascii_punctuation();
let before_punct = is_flanking_punct(before);
let after_punct = is_flanking_punct(after);
let left = !after_ws && (!after_punct || before_ws || before_punct);
let right = !before_ws && (!before_punct || after_ws || after_punct);
match ch {
Expand Down
6 changes: 6 additions & 0 deletions tests/test_focused.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ def test_dialect_fixture():
expected = (FIX / "dialect.xhtml").read_text()
assert _norm(to_xhtml(md)) == _norm(expected)

def test_flanking_treats_unicode_punctuation_as_punctuation():
html = to_xhtml("(“***{{company_common_name}}***”)")
assert "“<em><strong>{{company_common_name}}</strong></em>”" in html
html = to_xhtml("“__{{x}}__”")
assert "“<strong>{{x}}</strong>”" in html

def test_default_math_mode_is_brackets():
html = to_xhtml("\\(y\\)\n\n\\[\nx^2\n\\]\n\n$x$")
assert '<span class="math inline">y</span>' in html
Expand Down
Loading