-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
373 additions
and
325 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use crate::{extract_html, extract_stylistic_html}; | ||
|
||
/// Test if given input is likely HTML, based on the difference between the parsed style/inline tags vs. the sanitized HTML. | ||
pub fn likely_html(src: &str) -> bool { | ||
let stylistic = extract_stylistic_html(src, ""); | ||
let html = extract_html(src, ""); | ||
|
||
stylistic != html | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
fn returns_true_for_html() { | ||
assert_eq!(likely_html(r#"<p>Some HTML</p>"#), true); | ||
assert_eq!(likely_html(r#"<div>Some HTML</div>"#), true); | ||
assert_eq!(likely_html(r#"<div>Some <em>HTML</em></div>"#), true); | ||
} | ||
|
||
#[test] | ||
fn returns_false_for_non_html() { | ||
assert_eq!(likely_html(r#"Some HTML"#), false); | ||
assert_eq!(likely_html(r#"Some <em>HTML</em>"#), false); | ||
assert_eq!( | ||
likely_html(r#"<strike><strong>Some</strong> <em>HTML</em></strike>"#), | ||
false | ||
); | ||
} | ||
|
||
#[test] | ||
fn it_works_on_real_example() { | ||
let src = r#" | ||
<p class="feature-image"> | ||
<a href="https://example.com"> | ||
<img width="1600" height="840" src="https://example.com/image.jpg" class="attachment-card-large size-card-large wp-post-image" alt="Some image." decoding="async" /> | ||
</a> | ||
</p> | ||
<p>Some long description.</p> | ||
<p class="read-more"> | ||
[<a href="https://example.com">Read More</a>] | ||
</p> | ||
"#; | ||
|
||
assert_eq!(likely_html(src), true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mod likely_html; | ||
mod request; | ||
|
||
pub use likely_html::*; | ||
pub use request::*; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.