BlueGit

ict rusty-teams

Files

rusty-teams / crates / core / src / spans.rs

spans.rs

spans.rs 23.1 KiB Download Raw
1use scraper::{ElementRef, Html, Node};
2
3use crate::ams_video::video_thumbnail_url;
4use crate::jumbo::without_repeated_skin_tone;
5use crate::stored::quote_time;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum FontSize {
9 Small,
10 Large,
11 Hidden,
12 Pixels(u16),
13}
14
15#[derive(Debug, Clone, PartialEq, Eq)]
16pub enum Span {
17 Text(String),
18 Bold(Vec<Span>),
19 Italic(Vec<Span>),
20 Code(String),
21 CodeBlock {
22 language: Option<String>,
23 code: String,
24 },
25 Link {
26 url: String,
27 children: Vec<Span>,
28 },
29 Mention {
30 name: String,
31 id: Option<String>,
32 },
33 Strike(Vec<Span>),
34 Superscript(Vec<Span>),
35 Subscript(Vec<Span>),
36 Sized(FontSize, Vec<Span>),
37 Underline(Vec<Span>),
38 Colored {
39 color: Option<u32>,
40 background: Option<u32>,
41 children: Vec<Span>,
42 },
43 Heading {
44 level: u8,
45 children: Vec<Span>,
46 },
47 LineBreak,
48 Rule,
49 List {
50 ordered: bool,
51 start: u32,
52 items: Vec<Vec<Span>>,
53 },
54 Table {
55 header: bool,
56 rows: Vec<Vec<Vec<Span>>>,
57 },
58 Image {
59 hosted_content_url: String,
60 },
61 CustomEmoji {
62 name: String,
63 url: String,
64 },
65 Quote {
66 message_id: Option<String>,
67 children: Vec<Span>,
68 },
69 BlockQuote(Vec<Span>),
70 Indent {
71 level: u8,
72 children: Vec<Span>,
73 },
74}
75
76const BLOCK_ELEMENTS: [&str; 12] = [
77 "p", "div", "h1", "h2", "h3", "h4", "h5", "h6", "tr", "ul", "ol", "hr",
78];
79const SKIPPED_ELEMENTS: [&str; 4] = ["script", "style", "attachment", "head"];
80const LANGUAGE_PREFIX: &str = "language-";
81const EMOJI_ITEMTYPE: &str = "schema.skype.com/Emoji";
82const CUSTOM_EMOJI_ITEMTYPE: &str = "schema.skype.com/CustomEmoji";
83const REPLY_ITEMTYPE: &str = "schema.skype.com/Reply";
84pub const CODE_BLOCK_ITEMTYPE: &str = "http://schema.skype.com/CodeBlockEditor";
85const MAX_HEADING_LEVEL: u8 = 3;
86const MARK_BACKGROUND: u32 = 0xffff00;
87const MAX_CONSECUTIVE_BREAKS: usize = 2;
88const INDENTED_ELEMENTS: [&str; 8] = ["p", "div", "h1", "h2", "h3", "h4", "h5", "h6"];
89const INDENT_STEP_PIXELS: f32 = 40.;
90const MAX_INDENT_LEVEL: u8 = 8;
91use crate::code_languages::PLAIN_LANGUAGE;
92
93pub fn html_to_spans(html: &str) -> Vec<Span> {
94 let fragment = Html::parse_fragment(html);
95 let mut spans = convert_children(fragment.root_element());
96 tidy(&mut spans);
97 spans
98}
99
100fn convert_children(element: ElementRef<'_>) -> Vec<Span> {
101 let mut spans = Vec::new();
102 let mut break_pending = false;
103 for child in element.children() {
104 match child.value() {
105 Node::Text(text) => {
106 let text: &str = text;
107 if break_pending && text.trim().is_empty() {
108 continue;
109 }
110 if break_pending && !spans.is_empty() {
111 spans.push(Span::LineBreak);
112 }
113 break_pending = false;
114 push_text(&mut spans, text);
115 }
116 Node::Element(_) => {
117 let Some(child_element) = ElementRef::wrap(child) else {
118 continue;
119 };
120 // The empty paragraph Teams puts before a code block only links it to its editor.
121 if child_element.value().attr("itemtype") == Some(CODE_BLOCK_ITEMTYPE)
122 && raw_text(child_element).trim().is_empty()
123 {
124 continue;
125 }
126 let is_block = BLOCK_ELEMENTS.contains(&child_element.value().name());
127 if (is_block || break_pending) && !spans.is_empty() {
128 spans.push(Span::LineBreak);
129 }
130 convert_element(child_element, &mut spans);
131 break_pending = is_block;
132 }
133 _ => {}
134 }
135 }
136 spans
137}
138
139fn convert_element(element: ElementRef<'_>, spans: &mut Vec<Span>) {
140 let name = element.value().name();
141 if SKIPPED_ELEMENTS.contains(&name) {
142 return;
143 }
144 match block_indent(element) {
145 Some(level) => {
146 let mut children = Vec::new();
147 convert_unindented(element, &mut children);
148 spans.push(Span::Indent { level, children });
149 }
150 None => convert_unindented(element, spans),
151 }
152}
153
154fn block_indent(element: ElementRef<'_>) -> Option<u8> {
155 let value = element.value();
156 if !INDENTED_ELEMENTS.contains(&value.name()) {
157 return None;
158 }
159 let margin = style_value(value.attr("style")?, "margin-left")?;
160 let pixels: f32 = margin.trim().strip_suffix("px")?.trim().parse().ok()?;
161 let level = (pixels / INDENT_STEP_PIXELS).round();
162 (level >= 1.).then(|| level.min(f32::from(MAX_INDENT_LEVEL)) as u8)
163}
164
165fn convert_unindented(element: ElementRef<'_>, spans: &mut Vec<Span>) {
166 let name = element.value().name();
167 match name {
168 "b" | "strong" => spans.push(Span::Bold(convert_children(element))),
169 "h1" | "h2" | "h3" | "h4" | "h5" | "h6" => spans.push(Span::Heading {
170 level: name[1..].parse::<u8>().unwrap_or(1).min(MAX_HEADING_LEVEL),
171 children: convert_children(element),
172 }),
173 "i" | "em" => spans.push(Span::Italic(convert_children(element))),
174 "s" | "strike" | "del" => spans.push(Span::Strike(convert_children(element))),
175 "sup" => spans.push(Span::Superscript(convert_children(element))),
176 "sub" => spans.push(Span::Subscript(convert_children(element))),
177 "u" | "ins" => spans.push(Span::Underline(convert_children(element))),
178 "span" if element.value().attr("itemprop") == Some("time") => {
179 push_quote_time(element, spans)
180 }
181 "span" | "font" | "mark" => push_colored(element, spans),
182 "ul" | "ol" => spans.push(list(element)),
183 "table" => spans.push(table(element)),
184 "code" => spans.push(Span::Code(raw_text(element))),
185 "pre" | "codeblock" => spans.push(code_block(element)),
186 "a" => push_link(element, spans),
187 "at" => spans.push(Span::Mention {
188 name: raw_text(element).trim().to_owned(),
189 id: element.value().attr("id").map(str::to_owned),
190 }),
191 "br" => spans.push(Span::LineBreak),
192 "hr" => spans.push(Span::Rule),
193 "li" => spans.push(Span::List {
194 ordered: false,
195 start: 1,
196 items: vec![convert_children(element)],
197 }),
198 "blockquote" if is_reply(element) => spans.push(Span::Quote {
199 message_id: element.value().attr("itemid").map(str::to_owned),
200 children: convert_children(element),
201 }),
202 "blockquote" => spans.push(Span::BlockQuote(convert_children(element))),
203 "emoji" => push_emoji(element, spans),
204 "customemoji" => push_custom_emoji(element, spans),
205 "img" => push_image(element, spans),
206 "video" => push_video(element, spans),
207 _ => spans.extend(convert_children(element)),
208 }
209}
210
211fn is_reply(element: ElementRef<'_>) -> bool {
212 element
213 .value()
214 .attr("itemtype")
215 .is_some_and(|itemtype| itemtype.contains(REPLY_ITEMTYPE))
216}
217
218fn list(element: ElementRef<'_>) -> Span {
219 let mut items: Vec<Vec<Span>> = Vec::new();
220 for child in element.children().filter_map(ElementRef::wrap) {
221 match child.value().name() {
222 "li" => items.push(convert_children(child)),
223 "ul" | "ol" => match items.last_mut() {
224 Some(previous) => previous.push(list(child)),
225 None => items.push(vec![list(child)]),
226 },
227 _ => {}
228 }
229 }
230 Span::List {
231 ordered: element.value().name() == "ol",
232 start: element
233 .value()
234 .attr("start")
235 .and_then(|start| start.trim().parse().ok())
236 .unwrap_or(1),
237 items,
238 }
239}
240
241fn table(element: ElementRef<'_>) -> Span {
242 let rows: Vec<ElementRef<'_>> = element
243 .descendants()
244 .filter_map(ElementRef::wrap)
245 .filter(|row| row.value().name() == "tr" && belongs_to(*row, element))
246 .collect();
247 let header = rows.first().is_some_and(|row| {
248 let in_head = row
249 .parent()
250 .and_then(ElementRef::wrap)
251 .is_some_and(|parent| parent.value().name() == "thead");
252 let mut cells = cells_of(*row).peekable();
253 in_head || (cells.peek().is_some() && cells.all(|cell| cell.value().name() == "th"))
254 });
255 Span::Table {
256 header,
257 rows: rows
258 .into_iter()
259 .map(|row| cells_of(row).map(convert_children).collect())
260 .filter(|cells: &Vec<Vec<Span>>| !cells.is_empty())
261 .collect(),
262 }
263}
264
265fn belongs_to(row: ElementRef<'_>, table: ElementRef<'_>) -> bool {
266 row.ancestors()
267 .filter_map(ElementRef::wrap)
268 .find(|ancestor| ancestor.value().name() == "table")
269 .is_some_and(|owner| owner.id() == table.id())
270}
271
272fn cells_of<'a>(row: ElementRef<'a>) -> impl Iterator<Item = ElementRef<'a>> {
273 row.children()
274 .filter_map(ElementRef::wrap)
275 .filter(|cell| matches!(cell.value().name(), "td" | "th"))
276}
277
278fn push_colored(element: ElementRef<'_>, spans: &mut Vec<Span>) {
279 let value = element.value();
280 let style = value.attr("style").unwrap_or_default();
281 let color = style_value(style, "color")
282 .or_else(|| value.attr("color"))
283 .and_then(parse_color);
284 let background = style_value(style, "background-color")
285 .or_else(|| style_value(style, "background"))
286 .and_then(parse_color)
287 .or((value.name() == "mark").then_some(MARK_BACKGROUND));
288 let size = style_value(style, "font-size").and_then(parse_font_size);
289 let mut children = convert_children(element);
290 if color.is_some() || background.is_some() {
291 children = vec![Span::Colored {
292 color,
293 background,
294 children,
295 }];
296 }
297 match size {
298 Some(size) => spans.push(Span::Sized(size, children)),
299 None => spans.extend(children),
300 }
301}
302
303fn parse_font_size(value: &str) -> Option<FontSize> {
304 let value = value.trim().to_ascii_lowercase();
305 match value.as_str() {
306 "xx-small" => Some(FontSize::Small),
307 "x-large" => Some(FontSize::Large),
308 "x-small" => Some(FontSize::Pixels(10)),
309 "small" | "smaller" => Some(FontSize::Pixels(13)),
310 "large" | "larger" => Some(FontSize::Pixels(18)),
311 "xx-large" => Some(FontSize::Pixels(32)),
312 "0" => Some(FontSize::Hidden),
313 _ => {
314 let pixels: f32 = value.strip_suffix("px")?.trim().parse().ok()?;
315 if pixels <= 0. {
316 Some(FontSize::Hidden)
317 } else {
318 Some(FontSize::Pixels(
319 pixels.round().min(f32::from(u16::MAX)) as u16
320 ))
321 }
322 }
323 }
324}
325
326fn style_value<'a>(style: &'a str, property: &str) -> Option<&'a str> {
327 style.split(';').find_map(|declaration| {
328 let (name, value) = declaration.split_once(':')?;
329 (name.trim().eq_ignore_ascii_case(property)).then(|| value.trim())
330 })
331}
332
333pub fn parse_color(value: &str) -> Option<u32> {
334 let value = value.trim().to_ascii_lowercase();
335 if let Some(hex) = value.strip_prefix('#') {
336 return match hex.len() {
337 3 => {
338 let expanded: String = hex.chars().flat_map(|digit| [digit, digit]).collect();
339 u32::from_str_radix(&expanded, 16).ok()
340 }
341 6 => u32::from_str_radix(hex, 16).ok(),
342 _ => None,
343 };
344 }
345 if let Some(arguments) = value
346 .strip_prefix("rgba(")
347 .or_else(|| value.strip_prefix("rgb("))
348 .and_then(|rest| rest.strip_suffix(')'))
349 {
350 let channels: Vec<u32> = arguments
351 .split(',')
352 .take(3)
353 .map(|channel| {
354 channel
355 .trim()
356 .parse::<f32>()
357 .ok()
358 .map(|level| level.clamp(0., 255.) as u32)
359 })
360 .collect::<Option<_>>()?;
361 let [red, green, blue] = channels[..] else {
362 return None;
363 };
364 return Some(red << 16 | green << 8 | blue);
365 }
366 NAMED_COLORS
367 .iter()
368 .find(|(name, _)| *name == value)
369 .map(|(_, hex)| *hex)
370}
371
372const NAMED_COLORS: [(&str, u32); 14] = [
373 ("black", 0x000000),
374 ("white", 0xffffff),
375 ("red", 0xff0000),
376 ("green", 0x008000),
377 ("lime", 0x00ff00),
378 ("blue", 0x0000ff),
379 ("yellow", 0xffff00),
380 ("orange", 0xffa500),
381 ("purple", 0x800080),
382 ("fuchsia", 0xff00ff),
383 ("aqua", 0x00ffff),
384 ("teal", 0x008080),
385 ("gray", 0x808080),
386 ("grey", 0x808080),
387];
388
389fn code_block(element: ElementRef<'_>) -> Span {
390 let language = language_of(element).or_else(|| {
391 element
392 .descendants()
393 .filter_map(ElementRef::wrap)
394 .find_map(language_of)
395 });
396 Span::CodeBlock {
397 language: language.filter(|language| language != PLAIN_LANGUAGE),
398 code: code_text(element).trim_end_matches('\n').to_owned(),
399 }
400}
401
402fn code_text(element: ElementRef<'_>) -> String {
403 let mut text = String::new();
404 for node in element.descendants() {
405 match node.value() {
406 Node::Text(piece) => text.push_str(piece),
407 Node::Element(child) if child.name() == "br" => text.push('\n'),
408 _ => {}
409 }
410 }
411 text
412}
413
414fn language_of(element: ElementRef<'_>) -> Option<String> {
415 element
416 .value()
417 .classes()
418 .filter_map(|class| class.strip_prefix(LANGUAGE_PREFIX))
419 // Teams marks a language it guessed with this second class.
420 .find(|language| !language.is_empty() && *language != "was-auto-selected")
421 .map(str::to_owned)
422}
423
424fn push_link(element: ElementRef<'_>, spans: &mut Vec<Span>) {
425 let children = convert_children(element);
426 match element.value().attr("href") {
427 Some(url) if !url.is_empty() => spans.push(Span::Link {
428 url: url.to_owned(),
429 children,
430 }),
431 _ => spans.extend(children),
432 }
433}
434
435fn push_emoji(element: ElementRef<'_>, spans: &mut Vec<Span>) {
436 let glyph = element
437 .value()
438 .attr("alt")
439 .map(str::to_owned)
440 .filter(|alt| !alt.is_empty())
441 .unwrap_or_else(|| raw_text(element));
442 push_text(spans, &without_repeated_skin_tone(&glyph));
443}
444
445fn push_custom_emoji(element: ElementRef<'_>, spans: &mut Vec<Span>) {
446 let value = element.value();
447 let name = value.attr("alt").unwrap_or_default().to_owned();
448 match value.attr("source").filter(|source| !source.is_empty()) {
449 Some(source) => spans.push(Span::CustomEmoji {
450 name,
451 url: source.to_owned(),
452 }),
453 None if !name.is_empty() => push_text(spans, &format!(":{name}:")),
454 None => {}
455 }
456}
457
458fn push_image(element: ElementRef<'_>, spans: &mut Vec<Span>) {
459 let value = element.value();
460 let itemtype = value.attr("itemtype").unwrap_or("");
461 if itemtype.contains(CUSTOM_EMOJI_ITEMTYPE) {
462 let name = value
463 .attr("alt")
464 .or_else(|| {
465 value
466 .attr("itemid")
467 .and_then(|itemid| itemid.split_once(';').map(|(name, _)| name))
468 })
469 .unwrap_or_default()
470 .to_owned();
471 if let Some(source) = value.attr("src").filter(|source| !source.is_empty()) {
472 spans.push(Span::CustomEmoji {
473 name,
474 url: source.to_owned(),
475 });
476 } else if !name.is_empty() {
477 push_text(spans, &format!(":{name}:"));
478 }
479 return;
480 }
481 let is_emoji = itemtype.contains(EMOJI_ITEMTYPE);
482 if is_emoji {
483 if let Some(alt) = value.attr("alt") {
484 push_text(spans, &without_repeated_skin_tone(alt));
485 }
486 return;
487 }
488 if let Some(source) = value.attr("src").filter(|source| !source.is_empty()) {
489 spans.push(Span::Image {
490 hosted_content_url: source.to_owned(),
491 });
492 }
493}
494
495/// A Teams video clip draws as its thumbnail; other videos keep only their fallback content.
496fn push_video(element: ElementRef<'_>, spans: &mut Vec<Span>) {
497 match element.value().attr("src").and_then(video_thumbnail_url) {
498 Some(thumbnail) => spans.push(Span::Image {
499 hosted_content_url: thumbnail,
500 }),
501 None => spans.extend(convert_children(element)),
502 }
503}
504
505fn raw_text(element: ElementRef<'_>) -> String {
506 element.text().collect()
507}
508
509/// The service sends the reply time as an empty span that only carries the quoted message id.
510fn push_quote_time(element: ElementRef<'_>, spans: &mut Vec<Span>) {
511 if !raw_text(element).trim().is_empty() {
512 push_colored(element, spans);
513 return;
514 }
515 if let Some(time) = element.value().attr("itemid").and_then(quote_time) {
516 push_text(spans, &format!(" {time}"));
517 }
518}
519
520fn push_text(spans: &mut Vec<Span>, text: &str) {
521 if text.is_empty() {
522 return;
523 }
524 if let Some(Span::Text(existing)) = spans.last_mut() {
525 existing.push_str(text);
526 } else {
527 spans.push(Span::Text(text.to_owned()));
528 }
529}
530
531fn tidy(spans: &mut Vec<Span>) {
532 tidy_children(spans, true);
533}
534
535fn tidy_children(spans: &mut Vec<Span>, block: bool) {
536 for span in spans.iter_mut() {
537 match span {
538 Span::Bold(children)
539 | Span::Italic(children)
540 | Span::Strike(children)
541 | Span::Superscript(children)
542 | Span::Subscript(children)
543 | Span::Sized(_, children)
544 | Span::Underline(children)
545 | Span::Colored { children, .. }
546 | Span::Link { children, .. } => tidy_children(children, false),
547 Span::Heading { children, .. }
548 | Span::Quote { children, .. }
549 | Span::BlockQuote(children)
550 | Span::Indent { children, .. } => tidy(children),
551 Span::List { items, .. } => items.iter_mut().for_each(tidy),
552 Span::Table { rows, .. } => rows.iter_mut().flatten().for_each(tidy),
553 _ => {}
554 }
555 }
556 collapse_whitespace(spans, block);
557 if block {
558 trim_inline_edge(spans, true);
559 trim_inline_edge(spans, false);
560 }
561 limit_breaks(spans);
562 trim_breaks(spans);
563}
564
565fn trim_inline_edge(spans: &mut Vec<Span>, leading: bool) {
566 let edge = if leading {
567 spans.first_mut()
568 } else {
569 spans.last_mut()
570 };
571 let emptied = match edge {
572 Some(Span::Text(text)) => {
573 *text = if leading {
574 text.trim_start().to_owned()
575 } else {
576 text.trim_end().to_owned()
577 };
578 text.is_empty()
579 }
580 Some(
581 Span::Bold(children)
582 | Span::Italic(children)
583 | Span::Strike(children)
584 | Span::Superscript(children)
585 | Span::Subscript(children)
586 | Span::Sized(_, children)
587 | Span::Underline(children)
588 | Span::Colored { children, .. }
589 | Span::Link { children, .. },
590 ) => {
591 trim_inline_edge(children, leading);
592 false
593 }
594 _ => false,
595 };
596 if emptied {
597 if leading {
598 spans.remove(0);
599 } else {
600 spans.pop();
601 }
602 }
603}
604
605fn collapse_whitespace(spans: &mut Vec<Span>, block: bool) {
606 let mut collapsed: Vec<Span> = Vec::with_capacity(spans.len());
607 let count = spans.len();
608 for (index, span) in std::mem::take(spans).into_iter().enumerate() {
609 let Span::Text(text) = span else {
610 collapsed.push(span);
611 continue;
612 };
613 let mut text = squeeze_spaces(&text);
614 let at_edge = |neighbour: Option<&Span>| {
615 matches!(
616 neighbour,
617 None if block
618 ) || matches!(
619 neighbour,
620 Some(
621 Span::LineBreak
622 | Span::Rule
623 | Span::List { .. }
624 | Span::Table { .. }
625 | Span::Heading { .. }
626 | Span::Quote { .. }
627 | Span::BlockQuote(_)
628 | Span::Indent { .. }
629 )
630 )
631 };
632 if at_edge(collapsed.last()) {
633 text = text.trim_start().to_owned();
634 }
635 if block && index + 1 == count {
636 text = text.trim_end().to_owned();
637 }
638 if !text.is_empty() {
639 collapsed.push(Span::Text(text));
640 }
641 }
642 for index in 0..collapsed.len() {
643 let followed_by_break = matches!(collapsed.get(index + 1), Some(Span::LineBreak));
644 if followed_by_break && let Span::Text(text) = &mut collapsed[index] {
645 *text = text.trim_end().to_owned();
646 }
647 }
648 collapsed.retain(|span| !matches!(span, Span::Text(text) if text.is_empty()));
649 *spans = collapsed;
650}
651
652fn squeeze_spaces(text: &str) -> String {
653 let mut squeezed = String::with_capacity(text.len());
654 let mut previous_space = false;
655 for character in text.chars() {
656 let is_space = character.is_whitespace() && character != '\u{a0}';
657 if is_space {
658 if !previous_space {
659 squeezed.push(' ');
660 }
661 } else {
662 squeezed.push(character);
663 }
664 previous_space = is_space;
665 }
666 squeezed
667}
668
669fn limit_breaks(spans: &mut Vec<Span>) {
670 let mut run = 0;
671 spans.retain(|span| {
672 if matches!(span, Span::LineBreak) {
673 run += 1;
674 run <= MAX_CONSECUTIVE_BREAKS
675 } else {
676 run = 0;
677 true
678 }
679 });
680}
681
682fn trim_breaks(spans: &mut Vec<Span>) {
683 while matches!(spans.last(), Some(Span::LineBreak)) {
684 spans.pop();
685 }
686 let leading = spans
687 .iter()
688 .take_while(|span| matches!(span, Span::LineBreak))
689 .count();
690 spans.drain(..leading);
691}
692
693#[cfg(test)]
694mod tests {
695 use super::*;
696
697 #[test]
698 fn an_empty_reply_time_shows_the_time_of_the_quoted_message() {
699 let quoted = r#"<blockquote itemscope="" itemtype="http://schema.skype.com/Reply" itemid="1751975663649"><strong itemprop="mri">Ann</strong><span itemprop="time" itemid="1751975663649"></span><p itemprop="preview">old</p></blockquote>"#;
700 let expected = quote_time("1751975663649").unwrap();
701 let spans = html_to_spans(quoted);
702 let [Span::Quote { children, .. }] = spans.as_slice() else {
703 panic!("expected a quote");
704 };
705 assert!(
706 children.contains(&Span::Text(format!(" {expected}"))),
707 "{children:?}"
708 );
709 }
710
711 #[test]
712 fn spaces_at_the_edge_of_inline_formatting_survive() {
713 assert_eq!(
714 html_to_spans("Hello<b> world</b>"),
715 vec![
716 Span::Text("Hello".into()),
717 Span::Bold(vec![Span::Text(" world".into())])
718 ]
719 );
720 assert_eq!(
721 html_to_spans("<b> Note </b>"),
722 vec![Span::Bold(vec![Span::Text("Note".into())])]
723 );
724 assert_eq!(
725 html_to_spans("<strong>Note: </strong>text"),
726 vec![
727 Span::Bold(vec![Span::Text("Note: ".into())]),
728 Span::Text("text".into())
729 ]
730 );
731 }
732}