-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(diff): pretty html diff and fixes
- Loading branch information
Showing
8 changed files
with
90 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use std::io::Cursor; | ||
|
||
use quick_xml::events::Event; | ||
use quick_xml::reader::Reader; | ||
use quick_xml::writer::Writer; | ||
|
||
pub fn fmt_html(html: &str) -> String { | ||
let mut reader = Reader::from_str(html); | ||
reader.config_mut().trim_text(true); | ||
let mut writer = Writer::new_with_indent(Cursor::new(Vec::new()), b' ', 0); | ||
loop { | ||
match reader.read_event() { | ||
Ok(Event::Eof) => break, | ||
// we can either move or borrow the event to write, depending on your use-case | ||
Ok(e) => assert!(writer.write_event(e).is_ok()), | ||
_ => {} | ||
} | ||
} | ||
|
||
let result = writer.into_inner().into_inner(); | ||
String::from_utf8(result).unwrap() | ||
} |
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 |
---|---|---|
@@ -1,23 +1,22 @@ | ||
use std::borrow::Cow; | ||
|
||
use rari_templ_func::rari_f; | ||
use rari_utils::concat_strs; | ||
|
||
use crate::error::DocError; | ||
|
||
#[rari_f] | ||
pub fn embed_youtube(video_id: String, title: Option<String>) -> Result<String, DocError> { | ||
let title = title | ||
.as_deref() | ||
.map(|s| html_escape::encode_double_quoted_attribute(s)); | ||
let mut out = String::new(); | ||
out.extend([ | ||
.map(|s| html_escape::encode_double_quoted_attribute(s)) | ||
.unwrap_or(Cow::Borrowed("YouTube video")); | ||
Ok(concat_strs!( | ||
r#"<iframe width="560" height="315" "#, | ||
r#"src="https://www.youtube-nocookie.com/embed/"#, | ||
video_id.as_str(), | ||
r#"" title=""#, | ||
&title.unwrap_or(Cow::Borrowed("Youtube video")), | ||
r#"" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>"#, | ||
r#""></iframe>"#, | ||
]); | ||
Ok(out) | ||
&title, | ||
r#"" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>"# | ||
)) | ||
} |
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