# core/component/richtext (vanilla-engine 0.4.0)

> https://vanillapunch.com/docs/vanilla-engine/0.4.0/api/core/component/richtext/

리치텍스트 컴포넌트. (원본 core/component/richtext.js 의 RichText, parse_markup_to_segments)
- 마크업(Unity TMP 와 같은 꼴)을 풀어 조각(segment)마다 폰트, 크기, 색, 굵게, 기울임, 밑줄, 취소선을 달리해 한 줄로 잇는다.
  지원 태그: `<b>`, `<i>`, `<u>`, `<s>`, `<color=#RRGGBB[AA]>`, `<color=이름>`, `<size=N>`. 모르는 태그는 글 그대로 보인다.
- 원본은 Text 를 상속한다. 러스트 판은 Text 를 품고(UILabel 이 Text 를 품는 것과 같은 꼴) 세터를 넘긴다.
  마크업이 없으면 품은 Text 의 draw 로 그린다. (여러 줄, 줄바꿈 폭 그대로) 조각의 정하지 않은 속성은 Text 의 값을 쓴다.
- 조각 배치(layout_segments)는 Graphic 없이 재는 함수를 받아 한다. draw 는 글자 텍스처 캐시(textstringtexturecache)의 measure_text 로 잰다.
- 원본과 다른 것:
  - 조각 속성 fontFace(FontFace / FontAsset) 는 font_family(등록한 폰트 이름) 다.
  - 조각의 밑줄, 취소선, 기울임은 원본처럼 조각 속성이 없으면 Text 의 값(set_underline, set_strikethrough, set_italic)을 쓴다.
  - 잘못된 #색(16진수가 아닌 글자)은 흰색이다. (원본은 NaN 색)
  - getIntrinsicContentSize 는 재는 함수를 받는 calculate_intrinsic_content_size 다.
- 글자 방향: 조각을 이은 글로 문단 방향을 정하고(품은 Text 의 방향, Inherit 면 Graphic 의 방향), 오른쪽에서 왼쪽이면 조각을 오른쪽부터 놓는다.
  조각마다 그 방향으로 모양 짓고, 정렬 Start / End 도 그 방향으로 푼다. (원본도 같다)

## RichTextAttributes (struct) (Clone, Debug, Default, PartialEq)

조각 속성. (None / false 면 Text 의 값을 쓴다)

예제: 코드로 조각 쌓기

```rust
use vanilla::{Color, RichText, RichTextAttributes};

let mut warning_attributes = RichTextAttributes::new();
warning_attributes.text_color = Some(Color::create_from_hex("#ff0000"));
warning_attributes.font_size = Some(28.0);
warning_attributes.is_bold = true;
let mut rich_text = RichText::new();
rich_text.append_segment("HP ", RichTextAttributes::new()).append_segment("5", warning_attributes);
assert!(rich_text.has_segments());
assert_eq!(rich_text.get_segments()[0].attributes, RichTextAttributes::new());
assert_eq!(rich_text.get_segments()[1].attributes.font_size, Some(28.0));
```

- `pub text_color: Option<Color>` (field, since 0.3.2): 글자 색. (None 이면 Text 의 글자 색)
  - returns Option<Color>
- `pub font_size: Option<f64>` (field, since 0.3.2): 글자 크기. (픽셀, None 이면 Text 의 글자 크기)
  - returns Option<f64>
- `pub font_family: Option<String>` (field, since 0.3.2): 폰트 이름. (None 이면 Text 의 폰트 이름)
  - returns Option<String>
- `pub stroke_color: Option<Color>` (field, since 0.3.2): 외곽선 색. (None 이면 Text 의 외곽선 색)
  - returns Option<Color>
- `pub stroke_width: Option<f64>` (field, since 0.3.2): 외곽선 두께. (픽셀, None 이면 Text 의 외곽선 두께)
  - returns Option<f64>
- `pub is_bold: bool` (field, since 0.3.2): 굵게. (false 면 Text 의 값을 따른다)
  - returns bool
- `pub is_italic: bool` (field, since 0.3.2): 기울임. (false 면 Text 의 값을 따른다)
  - returns bool
- `pub is_underline: bool` (field, since 0.3.2): 밑줄. (false 면 Text 의 값을 따른다)
  - returns bool
- `pub is_strikethrough: bool` (field, since 0.3.2): 취소선. (false 면 Text 의 값을 따른다)
  - returns bool
- `pub fn new() -> RichTextAttributes` (constructor, since 0.3.2): 생성. (아무것도 정하지 않음)
  - returns RichTextAttributes: 아무것도 정하지 않은 속성. (default 와 같다)

## RichTextSegment (struct) (Clone, Debug, PartialEq)

조각. (글 + 속성)

예제: 겹친 태그는 속성을 합친다

```rust
use vanilla::core::component::richtext::parse_markup_to_segments;
use vanilla::Color;

let segment_list = parse_markup_to_segments("A<b>B<color=red>C</color></b>").expect("segments");
assert_eq!(segment_list.len(), 3);
assert_eq!(segment_list[0].text, "A");
assert!(!segment_list[0].attributes.is_bold);
assert!(segment_list[2].attributes.is_bold);
assert_eq!(segment_list[2].attributes.text_color, Some(Color::create_from_hex("#ff0000")));
```

- `pub text: String` (field, since 0.3.2): 조각 글. (태그를 뺀 글)
  - returns String
- `pub attributes: RichTextAttributes` (field, since 0.3.2): 조각 속성. (겹친 태그를 합친 것)
  - returns RichTextAttributes

## RichTextRun (struct) (Clone, Debug, PartialEq)

배치된 조각 하나. (그릴 자리와 모든 속성을 푼 값)

예제: 조각에 정하지 않은 속성은 Text 의 값으로 푼다

```rust
use vanilla::{Color, RichText, TextDirection, Vector2};

let mut measure_width = |_font_string: &str, text: &str| -> f64 {
	text.chars().count() as f64 * 10.0
};
let mut rich_text = RichText::create_with_text("ab<size=40><u>cd</u></size>", 20.0);
rich_text.set_text_color("#00ff00");
let layout = rich_text.layout_segments(Vector2::create(200.0, 60.0), TextDirection::Ltr, &mut measure_width);
let first_run = &layout.run_list[0];
let second_run = &layout.run_list[1];
assert_eq!(first_run.font_string, "20px default");
assert_eq!(first_run.text_color, Color::create_from_hex("#00ff00"));
assert!(!first_run.is_underline);
assert_eq!(second_run.font_size, 40.0);
assert!(second_run.is_underline);
assert_eq!(second_run.x, first_run.x + first_run.width);
```

- `pub text: String` (field, since 0.3.2): 조각 글.
  - returns String
- `pub font_string: String` (field, since 0.3.2): 폰트 문자열. (Canvas2D font 꼴)
  - returns String
- `pub font_size: f64` (field, since 0.3.2): 글자 크기. (픽셀)
  - returns f64
- `pub x: f64` (field, since 0.3.2): 그릴 왼쪽 x. (content 좌표, 정렬과 문단 방향을 반영한 값)
  - returns f64
- `pub width: f64` (field, since 0.3.2): 잰 폭.
  - returns f64
- `pub text_color: Color` (field, since 0.3.2): 글자 색.
  - returns Color
- `pub stroke_color: Color` (field, since 0.3.2): 외곽선 색.
  - returns Color
- `pub stroke_width: f64` (field, since 0.3.2): 외곽선 두께. (0 이면 외곽선을 긋지 않는다)
  - returns f64
- `pub is_underline: bool` (field, since 0.3.2): 밑줄을 긋는지.
  - returns bool
- `pub is_strikethrough: bool` (field, since 0.3.2): 취소선을 긋는지.
  - returns bool

## RichTextLayout (struct) (Clone, Debug, PartialEq)

조각 배치 결과.

예제: 가운데 정렬과 가운데 기준선

```rust
use vanilla::{RichText, TextAlign, TextBaseline, TextDirection, Vector2};

let mut measure_width = |_font_string: &str, text: &str| -> f64 {
	text.chars().count() as f64 * 10.0
};
let mut rich_text = RichText::create_with_text("ab<size=40>cd</size>", 20.0);
rich_text.set_text_align(TextAlign::Center);
rich_text.set_text_baseline(TextBaseline::Middle);
let layout = rich_text.layout_segments(Vector2::create(200.0, 60.0), TextDirection::Ltr, &mut measure_width);
assert_eq!(layout.total_width, 40.0);
assert_eq!(layout.maximum_font_size, 40.0);
assert_eq!(layout.baseline_y, 30.0);
assert_eq!(layout.run_list[0].x, 80.0);
```

- `pub run_list: Vec<RichTextRun>` (field, since 0.3.2): 배치된 조각 목록. (글이 빈 조각은 빼고 조각 차례)
  - returns Vec<RichTextRun>
- `pub total_width: f64` (field, since 0.3.2): 조각 폭의 합.
  - returns f64
- `pub maximum_font_size: f64` (field, since 0.3.2): 가장 큰 글자 크기. (픽셀, 조각이 없으면 0)
  - returns f64
- `pub baseline_y: f64` (field, since 0.3.2): 기준선 y. (content 좌표, Top 과 Hanging 은 0, Middle 은 높이의 반, 그 밖은 높이)
  - returns f64

## RichText (struct) (Default, Component)

리치텍스트 컴포넌트.
- 원본처럼 조각은 한 줄로 잇는다. 마크업이 없으면 품은 Text 로 그린다.

예제: 마크업 글 넣기

```rust
use vanilla::RichText;

let mut rich_text = RichText::create_with_text("Get <b>100</b> <color=yellow>gold</color>", 20.0);
assert!(rich_text.has_segments());
assert_eq!(rich_text.get_segments().len(), 4);
assert_eq!(rich_text.get_text(), "Get <b>100</b> <color=yellow>gold</color>");
rich_text.set_text("plain text");
assert!(!rich_text.has_segments());
```

- `pub fn new() -> RichText` (constructor, since 0.3.2): 생성. (기본값은 Text 와 같다)
  - returns RichText: 빈 글의 리치텍스트 컴포넌트.
- `pub fn create_with_text(text: &str, font_size: f64) -> RichText` (static, since 0.3.2): 글과 크기로 생성.
  - `text` &str: 처음 글. (마크업을 쓸 수 있다)
  - `font_size` f64: 기본 글자 크기. (픽셀)
  - returns RichText: 컴포넌트.
- `pub fn get_text_component(&self) -> &Text` (method, since 0.3.2): 품은 글자 컴포넌트 반환. (전역 속성과 마크업이 없을 때의 그리기)
  - returns &Text: 품은 Text.
- `pub fn get_text_component_mut(&mut self) -> &mut Text` (method, since 0.3.2): 품은 글자 컴포넌트 반환. (변경용)
  - returns &mut Text: 품은 Text.
- `pub fn set_text(&mut self, text: &str)` (method, since 0.3.2): 글 설정. (마크업을 풀어 조각으로 둔다. 알려진 태그가 없으면 조각을 비우고 일반 글로 그린다)
  - `text` &str: 글. (마크업을 쓸 수 있다)
- `pub fn get_text(&self) -> &str` (method, since 0.3.2): 글 반환. (마크업이 든 원래 글)
  - returns &str: 글.
- `pub fn append_segment(&mut self, text: &str, attributes: RichTextAttributes) -> &mut RichText` (method, since 0.3.2): 조각 하나 더하기. (마크업 없이 코드로 조각을 쌓을 때)
  - `text` &str: 조각 글. (마크업을 풀지 않고 그대로 둔다)
  - `attributes` RichTextAttributes: 조각 속성.
  - returns &mut RichText: 이 컴포넌트. (이어 부를 수 있다)
- `pub fn clear_segments(&mut self)` (method, since 0.3.2): 조각 모두 지우기.
- `pub fn get_segments(&self) -> &[RichTextSegment]` (method, since 0.3.2): 조각 목록.
  - returns &[RichTextSegment]: 조각 목록. (마크업이 없으면 비었다)
- `pub fn has_segments(&self) -> bool` (method, since 0.3.2): 글이 있는 조각이 하나라도 있는지.
  - returns bool: 글이 있는 조각이 있으면 true.
- `pub fn set_font_size(&mut self, font_size: f64)` (method, since 0.3.2): 글자 크기 설정.
  - `font_size` f64: 기본 글자 크기. (픽셀, 크기를 정하지 않은 조각이 쓴다)
- `pub fn get_font_size(&self) -> f64` (method, since 0.3.2): 글자 크기 반환.
  - returns f64: 기본 글자 크기. (픽셀)
- `pub fn set_font_family(&mut self, font_family: &str)` (method, since 0.3.2): 폰트 이름 설정.
  - `font_family` &str: 기본 폰트 이름.
- `pub fn get_font_family(&self) -> &str` (method, since 0.3.2): 폰트 이름 반환.
  - returns &str: 기본 폰트 이름.
- `pub fn set_text_color(&mut self, color: impl Into<Color>)` (method, since 0.3.2): 글자 색 설정.
  - `color` impl Into<Color>: 기본 글자 색.
- `pub fn get_text_color(&self) -> Color` (method, since 0.3.2): 글자 색 반환.
  - returns Color: 기본 글자 색.
- `pub fn set_stroke_color(&mut self, color: impl Into<Color>)` (method, since 0.3.2): 외곽선 색 설정.
  - `color` impl Into<Color>: 기본 외곽선 색.
- `pub fn get_stroke_color(&self) -> Color` (method, since 0.3.2): 외곽선 색 반환.
  - returns Color: 기본 외곽선 색.
- `pub fn set_stroke_width(&mut self, stroke_width: f64)` (method, since 0.3.2): 외곽선 두께 설정.
  - `stroke_width` f64: 기본 외곽선 두께. (픽셀, 0 이면 없음)
- `pub fn get_stroke_width(&self) -> f64` (method, since 0.3.2): 외곽선 두께 반환.
  - returns f64: 기본 외곽선 두께. (픽셀)
- `pub fn set_bold(&mut self, is_bold: bool)` (method, since 0.3.2): 굵게 설정.
  - `is_bold` bool: true 면 모든 조각을 굵게.
- `pub fn is_bold(&self) -> bool` (method, since 0.3.2): 굵게 여부.
  - returns bool: 굵게면 true.
- `pub fn set_italic(&mut self, is_italic: bool)` (method, since 0.3.2): 기울임 설정.
  - `is_italic` bool: true 면 모든 조각을 기울임.
- `pub fn is_italic(&self) -> bool` (method, since 0.3.2): 기울임 여부.
  - returns bool: 기울임이면 true.
- `pub fn set_underline(&mut self, is_underline: bool)` (method, since 0.4.0): 밑줄 설정. (조각에 `<u>` 가 없어도 모든 조각에 긋는다)
  - `is_underline` bool: true 면 밑줄을 긋는다.
- `pub fn is_underline(&self) -> bool` (method, since 0.4.0): 밑줄 여부.
  - returns bool: 밑줄을 그으면 true.
- `pub fn set_strikethrough(&mut self, is_strikethrough: bool)` (method, since 0.4.0): 취소선 설정. (조각에 `<s>` 가 없어도 모든 조각에 긋는다)
  - `is_strikethrough` bool: true 면 취소선을 긋는다.
- `pub fn is_strikethrough(&self) -> bool` (method, since 0.4.0): 취소선 여부.
  - returns bool: 취소선을 그으면 true.
- `pub fn set_wrap_mode(&mut self, wrap_mode: TextWrapMode)` (method, since 0.4.0): 줄바꿈 방식 설정. (마크업이 없을 때만 쓰인다. 조각은 원본처럼 한 줄)
  - `wrap_mode` TextWrapMode: 줄바꿈 방식.
- `pub fn get_wrap_mode(&self) -> TextWrapMode` (method, since 0.4.0): 줄바꿈 방식 반환.
  - returns TextWrapMode: 줄바꿈 방식.
- `pub fn set_text_align(&mut self, text_align: TextAlign)` (method, since 0.3.2): 가로 정렬 설정.
  - `text_align` TextAlign: 가로 정렬. (조각은 합친 폭으로 정렬한다)
- `pub fn get_text_align(&self) -> TextAlign` (method, since 0.3.2): 가로 정렬 반환.
  - returns TextAlign: 가로 정렬.
- `pub fn set_text_baseline(&mut self, text_baseline: TextBaseline)` (method, since 0.3.2): 세로 기준선 설정.
  - `text_baseline` TextBaseline: 세로 기준선.
- `pub fn get_text_baseline(&self) -> TextBaseline` (method, since 0.3.2): 세로 기준선 반환.
  - returns TextBaseline: 세로 기준선.
- `pub fn set_word_wrap_width(&mut self, word_wrap_width: f64)` (method, since 0.3.2): 줄바꿈 폭 설정. (마크업이 없을 때만 쓰인다. 조각은 원본처럼 한 줄)
  - `word_wrap_width` f64: 줄바꿈 폭. (픽셀, 0 이하면 줄바꿈 문자로만 나눈다)
- `pub fn get_word_wrap_width(&self) -> f64` (method, since 0.3.2): 줄바꿈 폭 반환.
  - returns f64: 줄바꿈 폭. (픽셀)
- `pub fn set_line_spacing(&mut self, line_spacing: f64)` (method, since 0.3.2): 줄 간격 설정.
  - `line_spacing` f64: 줄 간격. (글자 크기의 배수, 마크업이 없을 때만 쓰인다)
- `pub fn get_line_spacing(&self) -> f64` (method, since 0.3.2): 줄 간격 반환.
  - returns f64: 줄 간격. (글자 크기의 배수)
- `pub fn set_letter_spacing(&mut self, letter_spacing: f64)` (method, since 0.4.0): 글자 간격 설정.
  - `letter_spacing` f64: 글자 묶음마다 뒤에 더하는 간격. (픽셀, 마크업이 없을 때만 쓰인다)
- `pub fn get_letter_spacing(&self) -> f64` (method, since 0.4.0): 글자 간격 반환.
  - returns f64: 글자 간격. (픽셀)
- `pub fn layout_segments(&self, content_size: Vector2, text_direction: TextDirection, measure_width: &mut dyn FnMut(&str, &str) -> f64) -> RichTextLayout` (method, since 0.3.2): 조각 배치. (합친 폭과 가장 큰 글자 크기로 정렬, 기준선은 Text 와 같은 규칙. 원본 drawSegments 의 자리 계산)
  - measure_width(폰트 문자열, 글) 은 글 폭을 돌려준다.
  - text_direction 은 실제 문단 방향이다. (Ltr 또는 Rtl, Rtl 이면 조각을 오른쪽부터 놓고 Start 는 오른쪽 정렬)
  - `content_size` Vector2: 노드 content 크기. (정렬과 기준선에 쓴다)
  - `text_direction` TextDirection: 실제 문단 방향. (Rtl 밖은 모두 왼쪽에서 오른쪽으로 놓는다)
  - `measure_width` &mut dyn FnMut(&str, &str) -> f64: (폰트 문자열, 글) 을 받아 폭을 돌려주는 함수.
  - returns RichTextLayout: 배치 결과.

  예제: 오른쪽에서 왼쪽 문단은 앞 조각이 오른쪽에 온다

  ```rust
  use vanilla::{RichText, TextAlign, TextDirection, Vector2};
  
  let mut measure_width = |_font_string: &str, text: &str| -> f64 {
  	text.chars().count() as f64 * 10.0
  };
  let mut rich_text = RichText::create_with_text("ab<b>cd</b>", 20.0);
  rich_text.set_text_align(TextAlign::Start);
  let left_to_right_layout = rich_text.layout_segments(Vector2::create(200.0, 40.0), TextDirection::Ltr, &mut measure_width);
  assert_eq!(left_to_right_layout.run_list[0].x, 0.0);
  assert_eq!(left_to_right_layout.run_list[1].x, 20.0);
  assert_eq!(left_to_right_layout.run_list[1].font_string, "bold 20px default");
  let right_to_left_layout = rich_text.layout_segments(Vector2::create(200.0, 40.0), TextDirection::Rtl, &mut measure_width);
  assert_eq!(right_to_left_layout.run_list[0].x, 180.0);
  assert_eq!(right_to_left_layout.run_list[1].x, 160.0);
  ```

- `pub fn calculate_intrinsic_content_size(&self, measure_width: &mut dyn FnMut(&str, &str) -> f64) -> Vector2` (method, since 0.3.2): 글의 자연 크기. (조각이 있으면 합친 폭 x 가장 큰 글자 크기, 없으면 일반 글 폭 x 글자 크기. 원본 getIntrinsicContentSize)
  - `measure_width` &mut dyn FnMut(&str, &str) -> f64: (폰트 문자열, 글) 을 받아 폭을 돌려주는 함수.
  - returns Vector2: (너비, 높이).

  예제: 조각이 있으면 합친 폭과 가장 큰 글자 크기

  ```rust
  use vanilla::{RichText, Vector2};
  
  let mut measure_width = |_font_string: &str, text: &str| -> f64 {
  	text.chars().count() as f64 * 10.0
  };
  let mut rich_text = RichText::create_with_text("ab<size=40>cd</size>", 20.0);
  assert_eq!(rich_text.calculate_intrinsic_content_size(&mut measure_width), Vector2::create(40.0, 40.0));
  rich_text.set_text("plain");
  assert_eq!(rich_text.calculate_intrinsic_content_size(&mut measure_width), Vector2::create(50.0, 20.0));
  ```

- `pub fn resolve_segment_text_direction(&self, graphic: &Graphic) -> TextDirection` (method, since 0.4.0): 조각을 이은 글의 실제 방향. (품은 Text 의 방향, Inherit 면 Graphic 의 방향. Auto 는 이은 글의 첫 강한 글자로)
  - `graphic` &Graphic: 방향이 Inherit 일 때 볼 Graphic.
  - returns TextDirection: Ltr 또는 Rtl.
- `pub fn set_text_direction(&mut self, text_direction: TextDirection)` (method, since 0.4.0): 글자 방향 설정. (품은 Text 에 넘긴다, 원본 setTextDirection)
  - `text_direction` TextDirection: 글자 방향.
- `pub fn get_text_direction(&self) -> TextDirection` (method, since 0.4.0): 글자 방향 반환.
  - returns TextDirection: 글자 방향.
- `pub fn set_visible_character_count(&mut self, visible_character_count: i32)` (method, since 0.4.0): 보일 글자 수 설정. (품은 Text 에 넘긴다, -1 이면 전체. 마크업이 있는 글은 원본처럼 자르지 않는다)
  - `visible_character_count` i32: 보일 글자 묶음 수. (-1 이면 전체)
- `pub fn get_visible_character_count(&self) -> i32` (method, since 0.4.0): 보일 글자 수 반환.
  - returns i32: 보일 글자 묶음 수. (-1 이면 전체)
- `pub fn draw_segments(&self, graphic: &mut Graphic, content_size: Vector2)` (method, since 0.3.2): 조각 그리기. (원본 drawSegments)
  - `graphic` &mut Graphic: 그릴 Graphic. (문단 방향, 정렬, 기준선, 폰트 문자열, 색을 바꿔 가며 그린다)
  - `content_size` Vector2: 노드 content 크기.

## Functions and constants

- `pub fn build_font_string(font_family: &str, font_size: f64, is_bold: bool, is_italic: bool) -> String` (method, since 0.3.2): Canvas2D font 꼴 문자열. (원본 text.js 의 build_font_string)
  - `font_family` &str: 폰트 이름.
  - `font_size` f64: 글자 크기. (픽셀)
  - `is_bold` bool: true 면 bold 를 넣는다.
  - `is_italic` bool: true 면 italic 을 넣는다.
  - returns String: 폰트 문자열.

  예제: 기울임, 굵게, 크기, 이름 차례

  ```rust
  use vanilla::core::component::richtext::build_font_string;
  
  assert_eq!(build_font_string("default", 20.0, false, false), "20px default");
  assert_eq!(build_font_string("GameFont", 16.5, true, true), "italic bold 16.5px GameFont");
  ```

- `pub fn parse_markup_to_segments(input: &str) -> Option<Vec<RichTextSegment>>` (method, since 0.3.2): 마크업 → 조각 목록. (알려진 태그가 하나도 없으면 None. 원본 parseMarkupToSegments)
  - 모르는 여는 태그는 글로 남긴다. 닫는 태그는 짝이 없어도 글에서 빠진다. (원본과 같음)
  - `input` &str: 마크업 글.
  - returns Option<Vec<RichTextSegment>>: 조각 목록. 알려진 태그가 하나도 없으면(빈 글, `<` 가 없는 글도) None.

  예제: 모르는 태그는 글로 남는다

  ```rust
  use vanilla::core::component::richtext::parse_markup_to_segments;
  
  assert!(parse_markup_to_segments("plain text").is_none());
  assert!(parse_markup_to_segments("a < b and <unknown>tag</unknown>").is_none());
  let segment_list = parse_markup_to_segments("<u>x</u><foo>y").expect("segments");
  let text_list: Vec<&str> = segment_list.iter().map(|segment| segment.text.as_str()).collect();
  assert_eq!(text_list, vec!["x", "<foo>", "y"]);
  assert!(segment_list[0].attributes.is_underline);
  ```

