1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762
//! Defines the `HtmlContainer` Trait
use crate::attributes::Attributes;
use crate::content;
use crate::Container;
use crate::Html;
use crate::Table;
/// An HTML element that can contain other HTML elements
///
/// The methods on this trait are implemented generically, allowing any type (or combination of
/// types) implementing [`ToString`] to be passed in. Thanks to monomorphization, this can happen
/// without incurring any runtime cost. For example, we can pass an `Ipv4Addr` object into
/// `with_paragraph` directly:
///
/// ```
/// # use build_html::*;
/// # use std::net::Ipv4Addr;
/// let content = Container::default()
/// .with_paragraph(Ipv4Addr::new(127, 0, 0, 1))
/// .to_html_string();
/// assert_eq!(content, "<div><p>127.0.0.1</p></div>")
/// ```
///
/// Attributes can be passed in using any type that implements [`IntoIterator`] for 2-tuples of
/// objects implementing `ToString`. That includes (as of Rust 1.53) arrays of `&str`s, which are
/// very handy when content is known. For more dynamic attribute action,
/// [`HashMap`](std::collections::HashMap)s can also be used.
///
/// ```
/// # use build_html::*;
/// let content = Container::default()
/// .with_paragraph_attr("123", [("id", "paragraph"), ("class", "action")])
/// .to_html_string();
/// assert_eq!(content, r#"<div><p id="paragraph" class="action">123</p></div>"#)
/// ```
///
/// There are two different ways of interacting with `HtmlContainer` objects which will suit
/// different use cases. The first is using the *with* API, which consumes the calling container.
/// Because the calling container is consumed and returned, it can be chained effectively. This
/// makes it very useful for building containers whose content is known ahead of time, and for
/// building content using iterators. For example:
///
/// ```
/// # use build_html::*;
/// // Aggregating content
/// let list_items = (0..3)
/// .map(|x| format!("List item {}", x))
/// .fold(Container::new(ContainerType::OrderedList), |a, n| a.with_paragraph(n));
///
/// // Defining content literally
/// let content = Container::default()
/// .with_paragraph("paragraph text")
/// .with_container(list_items)
/// .to_html_string();
///
/// assert_eq!(
/// content,
/// concat!(
/// "<div><p>paragraph text</p><ol>",
/// "<li><p>List item 0</p></li>",
/// "<li><p>List item 1</p></li>",
/// "<li><p>List item 2</p></li></ol></div>"
/// )
/// )
/// ```
///
/// The other is using the *add* API, which acts on mutable references. This method is effective for
/// more imperative programming and more delicate control flow.
///
/// ```
/// # use build_html::*;
/// let mut container = Container::default();
/// if true {
/// container.add_paragraph("optional content");
/// }
/// for i in 0..3 {
/// container.add_paragraph(format!("Item: {}", i));
/// }
/// assert_eq!(
/// container.to_html_string(),
/// concat!(
/// "<div><p>optional content</p>",
/// "<p>Item: 0</p><p>Item: 1</p>",
/// "<p>Item: 2</p></div>"
/// )
/// );
/// ```
pub trait HtmlContainer: Html + Sized {
/// Adds the specified HTML element to this container
///
/// This method can be used as an escape hatch to insert arbitrary types into the HTML document,
/// helping to make up for those types which are not supported natively by this library. This
/// can be done by defining your own types that implement the [`Html`] trait.
///
/// If you need a simple one-off, it may be more convenient to insert the element as a raw
/// string using [`add_raw`](HtmlContainer::add_raw) method instead
///
/// # Example
/// ```
/// # use build_html::*;
/// #[derive(Debug)]
/// struct Span {
/// content: String
/// }
///
/// impl Span {
/// pub fn new(content: impl ToString) -> Self {
/// Span { content: content.to_string() }
/// }
/// }
///
/// impl Html for Span {
/// fn to_html_string(&self) -> String {
/// format!("<span>{}</span>", self.content)
/// }
/// }
///
/// let mut content = Container::default();
/// content.add_html(Span::new("inner"));
/// assert_eq!(content.to_html_string(), "<div><span>inner</span></div>");
/// ```
fn add_html<H: Html>(&mut self, html: H);
/// Consumes the container, returning it with the specified HTML element added to it
///
/// This method can be used as an escape hatch to insert arbitrary types into the HTML document,
/// helping to make up for those types which are not supported natively by this library. This
/// can be done by defining your own types that implement the [`Html`] trait.
///
/// If you need a simple one-off, it may be more convenient to insert the element as a raw
/// string using [`with_raw`](HtmlContainer::with_raw) method instead
///
/// # Example
/// ```
/// # use build_html::*;
/// #[derive(Debug)]
/// struct Span {
/// content: String
/// }
///
/// impl Span {
/// pub fn new(content: impl ToString) -> Self {
/// Span { content: content.to_string() }
/// }
/// }
///
/// impl Html for Span {
/// fn to_html_string(&self) -> String {
/// format!("<span>{}</span>", self.content)
/// }
/// }
///
/// let content = Container::default()
/// .with_html(Span::new("inner"))
/// .to_html_string();
/// assert_eq!(content, "<div><span>inner</span></div>");
/// ```
#[inline]
fn with_html<H: Html>(mut self, html: H) -> Self {
self.add_html(html);
self
}
/// Add the container to this HTML Container
///
/// Under the covers, this is simply an alias for [`add_html`](HtmlContainer::add_html).
/// Upon hearing this, you might be asking yourself "Why is this useful?". The answer is simply
/// that this function should be preferred because it is more descriptive. `add_html` is
/// intended to be more of an escape hatch than something used in everyday programs.
///
/// # Example
/// ```
/// # use build_html::*;
/// let mut content = Container::default();
/// content.add_container(Container::new(ContainerType::Main).with_paragraph("Inside"));
/// assert_eq!(content.to_html_string(), "<div><main><p>Inside</p></main></div>");
/// ```
#[inline]
fn add_container(&mut self, container: Container) {
self.add_html(container)
}
/// Nest the specified container within this container
///
/// Under the covers, this is simply an alias for [`with_html`](HtmlContainer::with_html).
/// Upon hearing this, you might be asking yourself "Why is this useful?". The answer is simply
/// that this function should be preferred because it is more descriptive. `with_html` is
/// intended to be more of an escape hatch than something used in everyday programs.
///
/// # Example
/// ```
/// # use build_html::*;
/// let content = Container::default()
/// .with_header(1, "Content Outside")
/// .with_container(
/// Container::new(ContainerType::Main)
/// .with_paragraph("Content Inside")
/// )
/// .to_html_string();
///
/// assert_eq!(
/// content,
/// "<div><h1>Content Outside</h1><main><p>Content Inside</p></main></div>"
/// );
/// ```
#[inline]
fn with_container(self, container: Container) -> Self {
self.with_html(container)
}
/// Add the specified `Table` to this container
///
/// # Example
/// ```
/// # use build_html::*;
/// let table = Table::from([
/// [1, 2, 3],
/// [4, 5, 6]
/// ]).with_header_row(['A', 'B', 'C']);
/// let mut container = Container::default();
/// container.add_table(table);
///
/// assert_eq!(
/// container.to_html_string(),
/// concat!(
/// "<div><table><thead>",
/// "<tr><th>A</th><th>B</th><th>C</th></tr>",
/// "</thead><tbody>",
/// "<tr><td>1</td><td>2</td><td>3</td></tr>",
/// "<tr><td>4</td><td>5</td><td>6</td></tr>",
/// "</tbody></table></div>"
/// )
/// );
/// ```
fn add_table(&mut self, table: Table) {
self.add_html(table);
}
/// Nest the specified `Table` within this container
///
/// # Example
/// ```
/// # use build_html::*;
/// let content = Container::default()
/// .with_table(
/// Table::from(&[
/// [1, 2, 3],
/// [4, 5, 6]
/// ])
/// .with_header_row(&['A', 'B', 'C'])
/// )
/// .to_html_string();
///
/// assert_eq!(
/// content,
/// concat!(
/// "<div><table><thead>",
/// "<tr><th>A</th><th>B</th><th>C</th></tr>",
/// "</thead><tbody>",
/// "<tr><td>1</td><td>2</td><td>3</td></tr>",
/// "<tr><td>4</td><td>5</td><td>6</td></tr>",
/// "</tbody></table></div>"
/// )
/// );
/// ```
fn with_table(self, table: Table) -> Self {
self.with_html(table)
}
/// Adds a header tag with the designated level to this container
///
/// # Example
/// ```
/// # use build_html::*;
/// let mut content = Container::default();
/// content.add_header(1, "Header Text");
/// assert_eq!(content.to_html_string(), r#"<div><h1>Header Text</h1></div>"#);
/// ```
fn add_header(&mut self, level: u8, text: impl ToString) {
let content = content::Header {
level,
content: text.to_string(),
attr: Attributes::default(),
};
self.add_html(content);
}
/// Adds a header tag with the designated level to this container
///
/// # Example
/// ```
/// # use build_html::*;
/// let content = Container::default()
/// .with_header(1, "Header Text")
/// .to_html_string();
///
/// assert_eq!(content, r#"<div><h1>Header Text</h1></div>"#);
/// ```
fn with_header(self, level: u8, text: impl ToString) -> Self {
let content = content::Header {
level,
content: text.to_string(),
attr: Attributes::default(),
};
self.with_html(content)
}
/// Adds a header tag with the designated level and attributes to this container.
///
/// # Example
/// ```
/// # use build_html::*;
/// let mut content = Container::default();
/// content.add_header_attr(1, "Header Text", std::iter::once(("id", "main-header")));
/// assert_eq!(content.to_html_string(), r#"<div><h1 id="main-header">Header Text</h1></div>"#);
/// ```
fn add_header_attr<A, S>(&mut self, level: u8, text: impl ToString, attr: A)
where
A: IntoIterator<Item = (S, S)>,
S: ToString,
{
let content = content::Header {
level,
content: text.to_string(),
attr: attr.into(),
};
self.add_html(content);
}
/// Adds a header tag with the designated level and attributes to this container.
///
/// # Example
/// ```
/// # use build_html::*;
/// let content = Container::default()
/// .with_header_attr(1, "Header Text", std::iter::once(("id", "main-header")))
/// .to_html_string();
///
/// assert_eq!(content, r#"<div><h1 id="main-header">Header Text</h1></div>"#);
/// ```
fn with_header_attr<A, S>(self, level: u8, text: impl ToString, attr: A) -> Self
where
A: IntoIterator<Item = (S, S)>,
S: ToString,
{
let content = content::Header {
level,
content: text.to_string(),
attr: attr.into(),
};
self.with_html(content)
}
/// Adds an `<img>` tag to this container
///
/// # Example
/// ```
/// # use build_html::*;
/// let mut content = Container::default();
/// content.add_image("myimage.png", "a test image");
/// assert_eq!(
/// content.to_html_string(),
/// r#"<div><img src="myimage.png" alt="a test image"></div>"#
/// );
/// ```
fn add_image(&mut self, src: impl ToString, alt: impl ToString) {
let content = content::Image {
src: src.to_string(),
alt: alt.to_string(),
attr: Attributes::default(),
};
self.add_html(content);
}
/// Adds an `<img>` tag to this container
///
/// # Example
/// ```
/// # use build_html::*;
/// let content = Container::default()
/// .with_image("myimage.png", "a test image")
/// .to_html_string();
///
/// assert_eq!(content, r#"<div><img src="myimage.png" alt="a test image"></div>"#);
/// ```
fn with_image(self, src: impl ToString, alt: impl ToString) -> Self {
let content = content::Image {
src: src.to_string(),
alt: alt.to_string(),
attr: Attributes::default(),
};
self.with_html(content)
}
/// Adds an `<img>` tag with the specified attributes to this container
///
/// # Example
/// ```
/// # use build_html::*;
/// # use std::collections::BTreeMap;
/// let mut attrs = BTreeMap::new();
/// attrs.insert("id", "sample-image");
/// let mut content = Container::default();
/// content.add_image_attr("myimage.png", "a test image", attrs);
///
/// assert_eq!(
/// content.to_html_string(),
/// r#"<div><img src="myimage.png" alt="a test image" id="sample-image"></div>"#
/// );
/// ```
fn add_image_attr<A, S>(&mut self, src: impl ToString, alt: impl ToString, attr: A)
where
A: IntoIterator<Item = (S, S)>,
S: ToString,
{
let content = content::Image {
src: src.to_string(),
alt: alt.to_string(),
attr: attr.into(),
};
self.add_html(content);
}
/// Adds an `<img>` tag with the specified attributes to this container
///
/// # Example
/// ```
/// # use build_html::*;
/// # use std::collections::BTreeMap;
/// let mut attrs = BTreeMap::new();
/// attrs.insert("id", "sample-image");
/// let content = Container::default()
/// .with_image_attr("myimage.png", "a test image", attrs)
/// .to_html_string();
///
/// assert_eq!(
/// content,
/// r#"<div><img src="myimage.png" alt="a test image" id="sample-image"></div>"#
/// );
/// ```
fn with_image_attr<A, S>(self, src: impl ToString, alt: impl ToString, attr: A) -> Self
where
A: IntoIterator<Item = (S, S)>,
S: ToString,
{
let content = content::Image {
src: src.to_string(),
alt: alt.to_string(),
attr: attr.into(),
};
self.with_html(content)
}
/// Adds an `<a>` tag to this container
///
/// # Example
/// ```
/// # use build_html::*;
/// let mut content = Container::default();
/// content.add_link("https://rust-lang.org/", "Rust Homepage");
///
/// assert_eq!(
/// content.to_html_string(),
/// r#"<div><a href="https://rust-lang.org/">Rust Homepage</a></div>"#
/// );
/// ```
fn add_link(&mut self, href: impl ToString, text: impl ToString) {
let content = content::Link {
href: href.to_string(),
content: text.to_string(),
attr: Attributes::default(),
};
self.add_html(content)
}
/// Adds an `<a>` tag to this container
///
/// # Example
/// ```
/// # use build_html::*;
/// let content = Container::default()
/// .with_link("https://rust-lang.org/", "Rust Homepage")
/// .to_html_string();
///
/// assert_eq!(content, r#"<div><a href="https://rust-lang.org/">Rust Homepage</a></div>"#)
/// ```
fn with_link(self, href: impl ToString, text: impl ToString) -> Self {
let content = content::Link {
href: href.to_string(),
content: text.to_string(),
attr: Attributes::default(),
};
self.with_html(content)
}
/// Adds an `<a>` tag with the specified attributes to this container
///
/// # Example
/// ```
/// # use build_html::*;
/// let mut content = Container::default();
/// content.add_link_attr("https://rust-lang.org/", "Rust Homepage", [("class", "links")]);
///
/// assert_eq!(
/// content.to_html_string(),
/// r#"<div><a href="https://rust-lang.org/" class="links">Rust Homepage</a></div>"#
/// );
/// ```
fn add_link_attr<A, S>(&mut self, href: impl ToString, text: impl ToString, attr: A)
where
A: IntoIterator<Item = (S, S)>,
S: ToString,
{
let content = content::Link {
href: href.to_string(),
content: text.to_string(),
attr: attr.into(),
};
self.add_html(content);
}
/// Adds an `<a>` tag with the specified attributes to this container
///
/// # Example
/// ```
/// # use build_html::*;
/// let content = Container::default()
/// .with_link_attr("https://rust-lang.org/", "Rust Homepage", [("class", "links")])
/// .to_html_string();
///
/// assert_eq!(
/// content,
/// r#"<div><a href="https://rust-lang.org/" class="links">Rust Homepage</a></div>"#
/// )
/// ```
fn with_link_attr<A, S>(self, href: impl ToString, text: impl ToString, attr: A) -> Self
where
A: IntoIterator<Item = (S, S)>,
S: ToString,
{
let content = content::Link {
href: href.to_string(),
content: text.to_string(),
attr: attr.into(),
};
self.with_html(content)
}
/// Adds a `<p>` tag element to this Container
///
/// # Example
/// ```
/// # use build_html::*;
/// let mut content = Container::default();
/// content.add_paragraph("This is sample paragraph text");
/// assert_eq!(content.to_html_string(), r#"<div><p>This is sample paragraph text</p></div>"#);
/// ```
fn add_paragraph(&mut self, text: impl ToString) {
let content = content::Paragraph {
content: text.to_string(),
attr: Attributes::default(),
};
self.add_html(content)
}
/// Adds a `<p>` tag element to this Container
///
/// # Example
/// ```
/// # use build_html::*;
/// let content = Container::default()
/// .with_paragraph("This is sample paragraph text")
/// .to_html_string();
///
/// assert_eq!(content, r#"<div><p>This is sample paragraph text</p></div>"#);
/// ```
fn with_paragraph(self, text: impl ToString) -> Self {
let content = content::Paragraph {
content: text.to_string(),
attr: Attributes::default(),
};
self.with_html(content)
}
/// Adds a `<p>` tag element with the specified attributes to this Container
///
/// # Example
/// ```
/// # use build_html::*;
/// let mut content = Container::default();
/// content.add_paragraph_attr("This is sample paragraph text", [("class", "text")]);
/// assert_eq!(
/// content.to_html_string(),
/// r#"<div><p class="text">This is sample paragraph text</p></div>"#
/// );
/// ```
fn add_paragraph_attr<A, S>(&mut self, text: impl ToString, attr: A)
where
A: IntoIterator<Item = (S, S)>,
S: ToString,
{
let content = content::Paragraph {
content: text.to_string(),
attr: attr.into(),
};
self.add_html(content);
}
/// Adds a `<p>` tag element with the specified attributes to this Container
///
/// # Example
/// ```
/// # use build_html::*;
/// let content = Container::default()
/// .with_paragraph_attr("This is sample paragraph text", [("class", "text")])
/// .to_html_string();
///
/// assert_eq!(content, r#"<div><p class="text">This is sample paragraph text</p></div>"#)
/// ```
fn with_paragraph_attr<A, S>(self, text: impl ToString, attr: A) -> Self
where
A: IntoIterator<Item = (S, S)>,
S: ToString,
{
let content = content::Paragraph {
content: text.to_string(),
attr: attr.into(),
};
self.with_html(content)
}
/// Adds a `<pre>` tag element to this container
///
/// # Example
/// ```
/// # use build_html::*;
/// let mut content = Container::default();
/// content.add_preformatted("This | is preformatted => text");
/// assert_eq!(
/// content.to_html_string(),
/// r#"<div><pre>This | is preformatted => text</pre></div>"#
/// );
/// ```
fn add_preformatted(&mut self, text: impl ToString) {
let content = content::Preformatted {
content: text.to_string(),
attr: Attributes::default(),
};
self.add_html(content);
}
/// Adds a `<pre>` tag element to this container
///
/// # Example
/// ```
/// # use build_html::*;
/// let content = Container::default()
/// .with_preformatted("This | is preformatted => text")
/// .to_html_string();
///
/// assert_eq!(content, r#"<div><pre>This | is preformatted => text</pre></div>"#);
/// ```
fn with_preformatted(self, text: impl ToString) -> Self {
let content = content::Preformatted {
content: text.to_string(),
attr: Attributes::default(),
};
self.with_html(content)
}
/// Adds a `<pre>` tag element with the specified attributes to this container
///
/// # Example
/// ```
/// # use build_html::*;
/// let mut content = Container::default();
/// content.add_preformatted_attr("This | is preformatted => text", [("id", "code")]);
/// assert_eq!(
/// content.to_html_string(),
/// r#"<div><pre id="code">This | is preformatted => text</pre></div>"#
/// );
/// ```
fn add_preformatted_attr<A, S>(&mut self, text: impl ToString, attr: A)
where
A: IntoIterator<Item = (S, S)>,
S: ToString,
{
let content = content::Preformatted {
content: text.to_string(),
attr: attr.into(),
};
self.add_html(content);
}
/// Adds a `<pre>` tag element with the specified attributes to this container
///
/// # Example
/// ```
/// # use build_html::*;
/// let content = Container::default()
/// .with_preformatted_attr("This | is preformatted => text", [("id", "code")])
/// .to_html_string();
///
/// assert_eq!(content, r#"<div><pre id="code">This | is preformatted => text</pre></div>"#)
/// ```
fn with_preformatted_attr<A, S>(self, text: impl ToString, attr: A) -> Self
where
A: IntoIterator<Item = (S, S)>,
S: ToString,
{
let content = content::Preformatted {
content: text.to_string(),
attr: attr.into(),
};
self.with_html(content)
}
/// Add raw content to the container. This content is pasted directly into the HTML
///
/// This is intended to be used as an escape hatch for one-off insertions. If you want a more
/// reusable escape hatch, consider writing your own type implementing the [`Html`] trait. You
/// can then use [`add_html`](HtmlContainer::add_html) to insert boxed instances into the
/// container. See the documentation for that method for examples.
///
/// # Example
/// ```
/// # use build_html::*;
/// let mut content = Container::default();
/// content.add_raw(r#"<video width="250"><source src="video.mp4" type="video/mp4"></video>"#);
/// assert_eq!(
/// content.to_html_string(),
/// r#"<div><video width="250"><source src="video.mp4" type="video/mp4"></video></div>"#
/// );
/// ```
fn add_raw(&mut self, content: impl ToString) {
self.add_html(content.to_string());
}
/// Add raw content to this container. The content is pasted directly into the HTML
///
/// This is intended to be used as an escape hatch for one-off insertions. If you want a more
/// reusable escape hatch, consider writing your own type implementing the [`Html`] trait. You
/// can then use [`with_html`](HtmlContainer::with_html) to insert boxed instances into the
/// container. See the documentation for that method for examples.
///
/// # Example
/// ```
/// # use build_html::*;
/// let content = Container::default()
/// .with_raw(r#"<video width="250"><source src="video.mp4" type="video/mp4"></video>"#)
/// .to_html_string();
///
/// assert_eq!(
/// content,
/// r#"<div><video width="250"><source src="video.mp4" type="video/mp4"></video></div>"#
/// );
/// ```
fn with_raw(self, content: impl ToString) -> Self {
self.with_html(content.to_string())
}
}