update imageocclusion.rs

This commit is contained in:
llama 2025-06-19 23:12:23 +08:00
parent bb363cced6
commit 27182c32e6
No known key found for this signature in database
GPG key ID: 0B7543854B9413C3

View file

@ -13,6 +13,7 @@ use nom::character::complete::char;
use nom::error::ErrorKind;
use nom::sequence::preceded;
use nom::sequence::separated_pair;
use nom::Parser;
fn unescape(text: &str) -> String {
text.replace("\\:", ":")
@ -22,11 +23,12 @@ pub fn parse_image_cloze(text: &str) -> Option<ImageOcclusionShape> {
if let Some((shape, _)) = text.split_once(':') {
let mut properties = vec![];
let mut remaining = &text[shape.len()..];
while let Ok((rem, (name, value))) = separated_pair::<_, _, _, _, (_, ErrorKind), _, _, _>(
while let Ok((rem, (name, value))) = separated_pair::<_, _, _, (_, ErrorKind), _, _, _>(
preceded(tag(":"), is_not("=")),
tag("="),
escaped(is_not("\\:"), '\\', char(':')),
)(remaining)
)
.parse(remaining)
{
remaining = rem;
let value = unescape(value);