text_view: Fix HTML render to support blockquote. (#703)
<img width="850" alt="image" src="https://github.com/user-attachments/assets/4d8f662f-aebe-4c40-bc56-828627f16064" />
This commit is contained in:
parent
81e6da503b
commit
6a00cfcc4a
3 changed files with 29 additions and 7 deletions
|
|
@ -10,6 +10,12 @@
|
||||||
>, <strong>bold</strong>, <em>italic</em>, and
|
>, <strong>bold</strong>, <em>italic</em>, and
|
||||||
<code>code</code> text.
|
<code>code</code> text.
|
||||||
</p>
|
</p>
|
||||||
|
<p>This is a text before blockquote.</p>
|
||||||
|
<blockquote>
|
||||||
|
This is before paragraph in blockquote.
|
||||||
|
<p>This is a second blockquote paragraph.</p>
|
||||||
|
<p>This is after paragraph in blockquote.</p>
|
||||||
|
</blockquote>
|
||||||
<p>
|
<p>
|
||||||
<img
|
<img
|
||||||
src="https://is1-ssl.mzstatic.com/image/thumb/avICmr1PbBRB-PAeplGreA/1378x774.jpg"
|
src="https://is1-ssl.mzstatic.com/image/thumb/avICmr1PbBRB-PAeplGreA/1378x774.jpg"
|
||||||
|
|
|
||||||
|
|
@ -602,14 +602,11 @@ impl Node {
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
Node::Root { children } => div()
|
Node::Root { children } => div()
|
||||||
.children({
|
.children(
|
||||||
let children_len = children.len();
|
children.into_iter().map(move |c| {
|
||||||
|
c.render(None, false, text_view_style, window, cx)
|
||||||
children.into_iter().enumerate().map(move |(ix, c)| {
|
|
||||||
let is_last_child = ix == children_len - 1;
|
|
||||||
c.render(None, is_last_child, text_view_style, window, cx)
|
|
||||||
})
|
})
|
||||||
})
|
)
|
||||||
.into_any_element(),
|
.into_any_element(),
|
||||||
Node::Paragraph(paragraph) => div().mb(mb).child(paragraph).into_any_element(),
|
Node::Paragraph(paragraph) => div().mb(mb).child(paragraph).into_any_element(),
|
||||||
Node::Heading { level, children } => {
|
Node::Heading { level, children } => {
|
||||||
|
|
|
||||||
|
|
@ -499,6 +499,7 @@ fn parse_paragraph(
|
||||||
title: title.map(Into::into),
|
title: title.map(Into::into),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
// All unknown tags to as text
|
// All unknown tags to as text
|
||||||
let mut child_paragraph = Paragraph::default();
|
let mut child_paragraph = Paragraph::default();
|
||||||
|
|
@ -697,6 +698,24 @@ fn parse_node(node: &Rc<Node>, paragraph: &mut Paragraph) -> element::Node {
|
||||||
table
|
table
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
local_name!("blockquote") => {
|
||||||
|
let mut children = vec![];
|
||||||
|
if !paragraph.is_empty() {
|
||||||
|
children.push(element::Node::Paragraph(paragraph.clone()));
|
||||||
|
paragraph.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut blockquote = Paragraph::default();
|
||||||
|
for (i, child) in node.children.borrow().iter().enumerate() {
|
||||||
|
if i > 0 {
|
||||||
|
blockquote.push_str("\n");
|
||||||
|
}
|
||||||
|
parse_paragraph(&mut blockquote, child);
|
||||||
|
}
|
||||||
|
children.push(element::Node::Blockquote(blockquote));
|
||||||
|
|
||||||
|
element::Node::Root { children: children }
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
if BLOCK_ELEMENTS.contains(&name.local.trim()) {
|
if BLOCK_ELEMENTS.contains(&name.local.trim()) {
|
||||||
let mut children: Vec<element::Node> = vec![];
|
let mut children: Vec<element::Node> = vec![];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue