htmlize/
lib.rs

1//! # Which `escape` function to use
2//!
3//! Generally, if the text goes in an attribute, use [`escape_attribute()`],
4//! otherwise, use [`escape_text()`]. If you need bytes (`[u8]`) instead of a
5//! `String`, use the `_bytes` version of the functions:
6//! [`escape_attribute_bytes()`] and [`escape_text_bytes()`].
7//!
8//! |                         | `&` | `<` | `>` | `"` | `'` |
9//! |-------------------------|:---:|:---:|:---:|:---:|:---:|
10//! | [`escape_text()`]       |  ✓  |  ✓  |  ✓  |     |     |
11//! | [`escape_attribute()`]  |  ✓  |  ✓  |  ✓  |  ✓  |     |
12//! | [`escape_all_quotes()`] |  ✓  |  ✓  |  ✓  |  ✓  |  ✓  |
13//!
14//! You should almost never need [`escape_all_quotes()`], but it’s included
15//! because sometimes it’s convenient to wrap attribute values in single quotes.
16//!
17//! # Which `unescape` function to use
18//!
19//! [`unescape()`] is probably fine for most uses. To be strictly correct, you
20//! should use [`unescape_attribute()`] for attribute values.
21//!
22//! [`unescape_in()`] handles either depending on the value of the `context`
23//! parameter. See its documentation for a discussion of the differences between
24//! expanding attribute values and general text.
25//!
26//! [`unescape_bytes_in()`] is just like [`unescape_in()`] except that it works
27//! on `[u8]` rather than strings.
28//!
29//! # Features
30//!
31//! The `escape` functions are all available with no features enabled.
32//!
33//!   * `unescape_fast`: provide fast version of [`unescape()`]. This does _not_
34//!     enable the `entities` feature automatically.
35//!
36//!     This takes perhaps 30 seconds longer to build than `unescape`, but the
37//!     performance is significantly better in the worst cases. That said, the
38//!     performance of of the `unescape` version is already pretty good, so I
39//!     don’t recommend enabling this unless you really need it.
40//!
41//!   * `unescape`: provide normal version of [`unescape()`]. This will
42//!     automatically enable the `entities` feature.
43//!
44//!   * `entities`: build [`ENTITIES`] map. Enabling this will add a dependency
45//!     on [phf] and may slow builds by a few seconds.
46//!
47//! ### Internal features
48//!
49//!   * `iai`: enable [iai] benchmarks. This should only be used when running
50//!     benchmarks. See the [Benchmarks section in the README][benchmarks].
51//!
52//!   * `bench`: enable unescape benchmarks by making internal functions like
53//!     `unescape_fast()` public. This must only be used when running
54//!     benchmarks. It is required to run unescape benchmarks. See the
55//!     [Benchmarks section in the README][benchmarks].
56//!
57//!   * `_unescape_either`: used internally to configure benchmarks. You should
58//!     not specify this directly. It is automatically enabled when
59//!     `unescape_fast` or `unescape` are enabled.
60//!
61//! # Minimum supported Rust version
62//!
63//! Currently the minimum supported Rust version (MSRV) is **1.60**. Future
64//! increases in the MSRV will require a major version bump.
65//!
66//! [phf]: https://crates.io/crates/phf
67//! [iai]: https://crates.io/crates/iai
68//! [benchmarks]: https://github.com/danielparks/htmlize#benchmarks
69
70// Lint configuration in Cargo.toml isn’t supported by cargo-geiger.
71#![forbid(unsafe_code)]
72// Enable doc_cfg on docsrs so that we get feature markers.
73#![cfg_attr(docsrs, feature(doc_cfg))]
74
75/// Mark items as requiring a feature on docs.rs.
76///
77/// Thanks to Tokio for this macro (via nix).
78macro_rules! feature {
79    (
80        #![$meta:meta]
81        $($item:item)*
82    ) => {
83        $(
84            #[cfg($meta)]
85            #[cfg_attr(docsrs, doc(cfg($meta)))]
86            $item
87        )*
88    }
89}
90
91mod escape;
92pub use escape::*;
93
94feature! {
95    #![any(feature = "unescape", feature = "unescape_fast")]
96
97    mod unescape;
98    pub use unescape::*;
99}
100
101feature! {
102    #![feature = "entities"]
103
104    mod entities;
105    pub use entities::*;
106}