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
22 changes: 21 additions & 1 deletion crates/typst-library/src/text/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,11 @@ impl PlainText for Packed<RawElem> {
}

/// The content of the raw text.
#[derive(Debug, Clone, Hash, PartialEq)]
#[derive(Debug, Clone, Hash)]
#[allow(
clippy::derived_hash_with_manual_eq,
reason = "https://github.com/typst/typst/pull/6560#issuecomment-3045393640"
)]
pub enum RawContent {
/// From a string.
Text(EcoString),
Expand All @@ -525,6 +529,22 @@ impl RawContent {
}
}

impl PartialEq for RawContent {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(RawContent::Text(a), RawContent::Text(b)) => a == b,
(lines @ RawContent::Lines(_), RawContent::Text(text))
| (RawContent::Text(text), lines @ RawContent::Lines(_)) => {
*text == lines.get()
}
(RawContent::Lines(a), RawContent::Lines(b)) => Iterator::eq(
a.iter().map(|(line, _)| line),
b.iter().map(|(line, _)| line),
),
}
}
}

cast! {
RawContent,
self => self.get().into_value(),
Expand Down
5 changes: 5 additions & 0 deletions tests/suite/text/raw.typ
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,11 @@ a b c --------------------
#let hi = "你好world"
```

--- issue-6559-equality-between-raws ---

#test(`foo`, `foo`)
#assert.ne(`foo`, `bar`)

--- raw-theme-set-to-auto ---
```typ
#let hi = "Hello World"
Expand Down