mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Retain text spans during regex matching
This commit is contained in:
parent
ddada45097
commit
7c7b830225
@ -390,12 +390,19 @@ impl Recipe {
|
|||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
|
|
||||||
let make = item!(text);
|
let make = |s| {
|
||||||
|
let mut content = item!(text)(s);
|
||||||
|
if let Some(span) = target.span() {
|
||||||
|
content = content.spanned(span);
|
||||||
|
}
|
||||||
|
content
|
||||||
|
};
|
||||||
|
|
||||||
let mut result = vec![];
|
let mut result = vec![];
|
||||||
let mut cursor = 0;
|
let mut cursor = 0;
|
||||||
|
|
||||||
for mat in regex.find_iter(text) {
|
for m in regex.find_iter(text) {
|
||||||
let start = mat.start();
|
let start = m.start();
|
||||||
if cursor < start {
|
if cursor < start {
|
||||||
result.push(make(text[cursor..start].into()));
|
result.push(make(text[cursor..start].into()));
|
||||||
}
|
}
|
||||||
@ -403,11 +410,11 @@ impl Recipe {
|
|||||||
let transformed = self.transform.apply(
|
let transformed = self.transform.apply(
|
||||||
world,
|
world,
|
||||||
self.span,
|
self.span,
|
||||||
make(mat.as_str().into()).guard(sel),
|
make(m.as_str().into()).guard(sel),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
result.push(transformed);
|
result.push(transformed);
|
||||||
cursor = mat.end();
|
cursor = m.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
if result.is_empty() {
|
if result.is_empty() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user