Convert action attribute to full URL for FORM tags
This commit is contained in:
parent
cc09c2ba01
commit
ffa60a0ce2
3 changed files with 25 additions and 5 deletions
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "monolith"
|
name = "monolith"
|
||||||
version = "2.0.1"
|
version = "2.0.2"
|
||||||
authors = ["Sunshine <sunshine@uberspace.net>"]
|
authors = ["Sunshine <sunshine@uberspace.net>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
22
src/html.rs
22
src/html.rs
|
@ -2,7 +2,7 @@ extern crate html5ever;
|
||||||
|
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::io;
|
use std::io;
|
||||||
use http::{retrieve_asset, resolve_url};
|
use http::{is_url, retrieve_asset, resolve_url};
|
||||||
|
|
||||||
use self::html5ever::parse_document;
|
use self::html5ever::parse_document;
|
||||||
use self::html5ever::rcdom::{Handle, NodeData, RcDom};
|
use self::html5ever::rcdom::{Handle, NodeData, RcDom};
|
||||||
|
@ -15,6 +15,7 @@ enum NodeMatch {
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
Anchor,
|
Anchor,
|
||||||
Script,
|
Script,
|
||||||
|
Form,
|
||||||
Other,
|
Other,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,6 +79,8 @@ pub fn walk_and_embed_assets(url: &str, node: &Handle, opt_no_js: bool) {
|
||||||
found = NodeMatch::Anchor;
|
found = NodeMatch::Anchor;
|
||||||
} else if &name.local == "script" {
|
} else if &name.local == "script" {
|
||||||
found = NodeMatch::Script;
|
found = NodeMatch::Script;
|
||||||
|
} else if &name.local == "form" {
|
||||||
|
found = NodeMatch::Form;
|
||||||
}
|
}
|
||||||
|
|
||||||
match found {
|
match found {
|
||||||
|
@ -145,6 +148,20 @@ pub fn walk_and_embed_assets(url: &str, node: &Handle, opt_no_js: bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
NodeMatch::Form => {
|
||||||
|
for attr in attrs_mut.iter_mut() {
|
||||||
|
if &attr.name.local == "action" {
|
||||||
|
// Do not touch action props which are set to a URL
|
||||||
|
if is_url(&attr.value) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let href_full_url = resolve_url(&url, &attr.value.to_string());
|
||||||
|
attr.value.clear();
|
||||||
|
attr.value.push_slice(href_full_url.unwrap().as_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
NodeMatch::Other => {},
|
NodeMatch::Other => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,7 +191,8 @@ pub fn html_to_dom(data: &str) -> html5ever::rcdom::RcDom {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_dom(handle: &Handle) {
|
pub fn print_dom(handle: &Handle, _opt_isolate: bool) {
|
||||||
|
// TODO: append <meta http-equiv="Access-Control-Allow-Origin" content="'self'"/> to the <head> if opt_isolate
|
||||||
serialize(&mut io::stdout(), handle, SerializeOpts::default()).unwrap();
|
serialize(&mut io::stdout(), handle, SerializeOpts::default()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ use monolith::html::{walk_and_embed_assets, html_to_dom, print_dom};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let command = App::new("monolith")
|
let command = App::new("monolith")
|
||||||
.version("2.0.1")
|
.version("2.0.2")
|
||||||
.author("Sunshine <sunshine@uberspace.net>")
|
.author("Sunshine <sunshine@uberspace.net>")
|
||||||
.about("CLI tool to save web pages as single HTML files")
|
.about("CLI tool to save web pages as single HTML files")
|
||||||
.arg(Arg::with_name("url")
|
.arg(Arg::with_name("url")
|
||||||
|
@ -16,11 +16,13 @@ fn main() {
|
||||||
.index(1)
|
.index(1)
|
||||||
.help("URL to download"))
|
.help("URL to download"))
|
||||||
.args_from_usage("-j, --nojs 'Remove JavaScript'")
|
.args_from_usage("-j, --nojs 'Remove JavaScript'")
|
||||||
|
// .args_from_usage("-i, --isolate 'Isolate the document'")
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
// Process the command
|
// Process the command
|
||||||
let arg_target = command.value_of("url").unwrap();
|
let arg_target = command.value_of("url").unwrap();
|
||||||
let opt_no_js = command.is_present("nojs");
|
let opt_no_js = command.is_present("nojs");
|
||||||
|
let opt_isolate = command.is_present("isolate");
|
||||||
|
|
||||||
if is_url(arg_target) {
|
if is_url(arg_target) {
|
||||||
let data = retrieve_asset(&arg_target, false, "");
|
let data = retrieve_asset(&arg_target, false, "");
|
||||||
|
@ -28,6 +30,6 @@ fn main() {
|
||||||
|
|
||||||
walk_and_embed_assets(&arg_target, &dom.document, opt_no_js);
|
walk_and_embed_assets(&arg_target, &dom.document, opt_no_js);
|
||||||
|
|
||||||
print_dom(&dom.document);
|
print_dom(&dom.document, opt_isolate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue