add cowstr
This commit is contained in:
parent
f74ea7a138
commit
903578b04d
2 changed files with 75 additions and 36 deletions
53
src/html.rs
53
src/html.rs
|
|
@ -162,34 +162,37 @@ impl<'s, I: Iterator<Item = Event<'s>>, W: std::fmt::Write> Writer<I, W> {
|
|||
Container::DoubleQuoted => self.out.write_str("”")?,
|
||||
}
|
||||
}
|
||||
Event::Str(mut s) => match self.raw {
|
||||
Raw::None => {
|
||||
let mut ent = "";
|
||||
while let Some(i) = s.chars().position(|c| {
|
||||
if let Some(s) = match c {
|
||||
'<' => Some("<"),
|
||||
'>' => Some(">"),
|
||||
'&' => Some("&"),
|
||||
'"' => Some("""),
|
||||
_ => None,
|
||||
} {
|
||||
ent = s;
|
||||
true
|
||||
} else {
|
||||
false
|
||||
Event::Str(s) => {
|
||||
let mut s: &str = s.as_ref();
|
||||
match self.raw {
|
||||
Raw::None => {
|
||||
let mut ent = "";
|
||||
while let Some(i) = s.chars().position(|c| {
|
||||
if let Some(s) = match c {
|
||||
'<' => Some("<"),
|
||||
'>' => Some(">"),
|
||||
'&' => Some("&"),
|
||||
'"' => Some("""),
|
||||
_ => None,
|
||||
} {
|
||||
ent = s;
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}) {
|
||||
self.out.write_str(&s[..i])?;
|
||||
self.out.write_str(ent)?;
|
||||
s = &s[i + 1..];
|
||||
}
|
||||
}) {
|
||||
self.out.write_str(&s[..i])?;
|
||||
self.out.write_str(ent)?;
|
||||
s = &s[i + 1..];
|
||||
self.out.write_str(s)?;
|
||||
}
|
||||
self.out.write_str(s)?;
|
||||
Raw::Html => {
|
||||
self.out.write_str(s)?;
|
||||
}
|
||||
Raw::Other => {}
|
||||
}
|
||||
Raw::Html => {
|
||||
self.out.write_str(s)?;
|
||||
}
|
||||
Raw::Other => {}
|
||||
},
|
||||
}
|
||||
|
||||
Event::Atom(a) => match a {
|
||||
Atom::Ellipsis => self.out.write_str("…")?,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue