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
//! Rustextile is a parser of a popular [Textile](https://textile-lang.com/)
//! markup language written in stable Rust.
//!
//! It is mostly a port of the "canonical"
//! [PHP Textile](https://github.com/textile/php-textile) implementation
//! and supports all of its markup features (as of php-textile v3.7.7), including
//!
//! * Decorated text spans
//! * Images
//! * Tables
//! * Ordered/unordered lists
//! * Definition lists
//! * Complex quotations
//! * Code blocks
//! * CSS styles, classes and ID attributes
//! * Raw HTML inserts
//! * Footnotes and references
//! * "Restricted" parsing for untrusted user input
//! * Rendering in either XHTML or HTML5
//! * Extra [safety perks](Textile::set_sanitize) to ensure nothing harmful
//! can be sneaked into the output even without the use of restricted parsing.
//!
//! # Usage
//!
//! Edit your `Cargo.toml` to include
//!
//! ```toml
//! [dependencies]
//! rustextile = "1"
//! ```
//! # Code Example
//!
//! ```rust
//! use rustextile::{Textile, HtmlKind};
//! use rustextile::ammonia::{UrlRelative, url::Url};
//!
//! // Processing some ordinary Textile markup.
//! let textile = Textile::default()
//! .set_html_kind(HtmlKind::XHTML);
//! let html = textile.parse("h1. It works!");
//! assert_eq!(html, "<h1>It works!</h1>");
//!
//! // Raw HTML inserts are possible.
//! let html = textile.parse("<strong>Raw HTML insert</strong>");
//! assert_eq!(html, r#"<p><strong>Raw <span class="caps">HTML</span> insert</strong></p>"#);
//!
//! // Forcing all links to have a specific "rel" attribute.
//! let textile = textile.set_rel(Some("nofollow"));
//! let html = textile.parse(r#"This "link":https://example.com/ won't be scanned by Google"#);
//! assert_eq!(html, r#"<p>This <a href="https://example.com/" rel="nofollow">link</a> won’t be scanned by Google</p>"#);
//!
//! // The parser can be restricted from using advanced features (HTML inserts, CSS classes, etc.).
//! let textile = Textile::default().set_restricted(true);
//! let html = textile.parse("<div>Now raw HTML is restricted</div>");
//! assert_eq!(html, r#"<p><div>Now raw <span class="caps">HTML</span> is restricted</div></p>"#);
//!
//! // You can limit its capabilities to only paragraphs and blockquotes.
//! let textile = Textile::default().set_lite(true);
//! let html = textile.parse("h1. This *won't* become a header");
//! assert_eq!(html, r#"<p>h1. This <strong>won’t</strong> become a header</p>"#);
//!
//! // Extra sanitation of the output through the Ammonia library.
//! let textile = Textile::default()
//! .set_sanitize(true);
//! let html = textile.parse(r#"<script type="text/javascript">alert("Say hi!")</script>JS has been sanitized away!"#);
//! assert_eq!(html, "<p>JS has been sanitized away!</p>");
//!
//! // This sanitation can be finely tuned to do exactly what you need.
//! let textile = textile.adjust_sanitizer(|sanitizer| {
//! sanitizer
//! .rm_tags(&["p", "del"])
//! .url_relative(
//! UrlRelative::RewriteWithBase(
//! Url::parse("https://example.com").unwrap()))
//! });
//! let html = textile.parse(r#"Sanitizer -can also- be "tuned":/some-page/"#);
//! assert_eq!(html, r#"Sanitizer can also be <a href="https://example.com/some-page/">tuned</a>"#);
//!
//! ````
pub use ammonia;
pub use crate;