Generate `LI`s when newlines are encountered with bullets on.
This commit is contained in:
parent
ed5f3cdd0e
commit
12495de91e
|
@ -1262,6 +1262,7 @@ impl FormatSpans {
|
|||
//Some of them nest within themselves, but we only store the last one,
|
||||
//as Flash doesn't seem to un-nest them at all.
|
||||
let mut last_text_format_element = None;
|
||||
let mut last_bullet = None;
|
||||
let mut last_paragraph = None;
|
||||
let mut last_font = None;
|
||||
let mut last_a = None;
|
||||
|
@ -1269,7 +1270,7 @@ impl FormatSpans {
|
|||
let mut last_i = None;
|
||||
let mut last_u = None;
|
||||
|
||||
for (_start, _end, text, span) in self.iter_spans() {
|
||||
for (start, _end, text, span) in self.iter_spans() {
|
||||
let ls = &last_span.unwrap();
|
||||
|
||||
if ls.left_margin != span.left_margin
|
||||
|
@ -1336,6 +1337,7 @@ impl FormatSpans {
|
|||
}
|
||||
|
||||
last_text_format_element = Some(new_tf);
|
||||
last_bullet = None;
|
||||
last_paragraph = None;
|
||||
last_font = None;
|
||||
last_a = None;
|
||||
|
@ -1346,6 +1348,27 @@ impl FormatSpans {
|
|||
root.append_child(mc, new_tf).unwrap();
|
||||
}
|
||||
|
||||
let mut can_span_create_bullets = start == 0;
|
||||
for line in text.split('\n') {
|
||||
if can_span_create_bullets && span.bullet
|
||||
|| !can_span_create_bullets && last_span.map(|ls| ls.bullet).unwrap_or(false)
|
||||
{
|
||||
let new_li = XMLNode::new_element(mc, "LI", document);
|
||||
|
||||
last_bullet = Some(new_li);
|
||||
last_paragraph = None;
|
||||
last_font = None;
|
||||
last_a = None;
|
||||
last_b = None;
|
||||
last_i = None;
|
||||
last_u = None;
|
||||
|
||||
last_text_format_element
|
||||
.unwrap_or(root)
|
||||
.append_child(mc, new_li)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
if ls.align != span.align || last_paragraph.is_none() {
|
||||
let new_p = XMLNode::new_element(mc, "P", document);
|
||||
|
||||
|
@ -1360,7 +1383,8 @@ impl FormatSpans {
|
|||
},
|
||||
);
|
||||
|
||||
last_text_format_element
|
||||
last_bullet
|
||||
.or(last_text_format_element)
|
||||
.unwrap_or(root)
|
||||
.append_child(mc, new_p)
|
||||
.unwrap();
|
||||
|
@ -1422,6 +1446,7 @@ impl FormatSpans {
|
|||
|
||||
last_font
|
||||
.or(last_paragraph)
|
||||
.or(last_bullet)
|
||||
.or(last_text_format_element)
|
||||
.unwrap_or(root)
|
||||
.append_child(mc, new_font)
|
||||
|
@ -1445,6 +1470,7 @@ impl FormatSpans {
|
|||
|
||||
last_font
|
||||
.or(last_paragraph)
|
||||
.or(last_bullet)
|
||||
.or(last_text_format_element)
|
||||
.unwrap_or(root)
|
||||
.append_child(mc, new_a)
|
||||
|
@ -1466,6 +1492,7 @@ impl FormatSpans {
|
|||
last_a
|
||||
.or(last_font)
|
||||
.or(last_paragraph)
|
||||
.or(last_bullet)
|
||||
.or(last_text_format_element)
|
||||
.unwrap_or(root)
|
||||
.append_child(mc, new_b)
|
||||
|
@ -1487,6 +1514,7 @@ impl FormatSpans {
|
|||
.or(last_a)
|
||||
.or(last_font)
|
||||
.or(last_paragraph)
|
||||
.or(last_bullet)
|
||||
.or(last_text_format_element)
|
||||
.unwrap_or(root)
|
||||
.append_child(mc, new_i)
|
||||
|
@ -1507,6 +1535,7 @@ impl FormatSpans {
|
|||
.or(last_a)
|
||||
.or(last_font)
|
||||
.or(last_paragraph)
|
||||
.or(last_bullet)
|
||||
.or(last_text_format_element)
|
||||
.unwrap_or(root)
|
||||
.append_child(mc, new_u)
|
||||
|
@ -1517,19 +1546,34 @@ impl FormatSpans {
|
|||
last_u = None;
|
||||
}
|
||||
|
||||
let span_text = XMLNode::new_text(mc, text, document);
|
||||
let span_text = if last_bullet.is_some() {
|
||||
XMLNode::new_text(mc, line, document)
|
||||
} else {
|
||||
let line_start = line.as_ptr() as usize - text.as_ptr() as usize;
|
||||
let line_with_newline = if line_start > 0 {
|
||||
text.get(line_start - 1..line.len() + 1).unwrap_or(line)
|
||||
} else {
|
||||
line
|
||||
};
|
||||
|
||||
XMLNode::new_text(mc, line_with_newline, document)
|
||||
};
|
||||
|
||||
last_u
|
||||
.or(last_i)
|
||||
.or(last_b)
|
||||
.or(last_a)
|
||||
.or(last_font)
|
||||
.or(last_paragraph)
|
||||
.or(last_bullet)
|
||||
.or(last_text_format_element)
|
||||
.unwrap_or(root)
|
||||
.append_child(mc, span_text)
|
||||
.unwrap();
|
||||
|
||||
last_span = Some(span);
|
||||
can_span_create_bullets = true;
|
||||
}
|
||||
}
|
||||
|
||||
document
|
||||
|
|
Loading…
Reference in New Issue