Fixes various issues on HTML export.

This commit is contained in:
jcamiel 2023-01-11 12:14:32 +01:00
parent 18f4ba1afe
commit 79b2fcd099
No known key found for this signature in database
GPG Key ID: 07FF11CFD55356CC
9 changed files with 136 additions and 89 deletions

View File

@ -10,13 +10,13 @@
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
<span class="line"><span class="method">POST</span> <span class="url">http://localhost:8000/post-file</span></span>
<span class="line section-header">[MultipartFormData]</span>
<span class="line"><span class="string"><span class="string">file1</span></span>: file,<span class="string"><span class="filename">/secret.txt</span></span>;</span>
<span class="line"><span class="string">file1</span>: file,<span class="filename">/secret.txt</span>;</span>
</span><span class="response"><span class="line"></span>
<span class="line"><span class="version">HTTP</span> <span class="number">200</span></span>
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
<span class="line"><span class="method">POST</span> <span class="url">http://localhost:8000/post-file</span></span>
<span class="line section-header">[MultipartFormData]</span>
<span class="line"><span class="string"><span class="string">file1</span></span>: file,<span class="string"><span class="filename">../secret.txt</span></span>;</span>
<span class="line"><span class="string">file1</span>: file,<span class="filename">../secret.txt</span>;</span>
</span><span class="response"><span class="line"></span>
<span class="line"><span class="version">HTTP</span> <span class="number">200</span></span>
</span></span></code></pre>

View File

@ -1,7 +1,7 @@
<pre><code class="language-hurl"><span class="hurl-entry"><span class="request"><span class="line"><span class="method">POST</span> <span class="url">http://localhost:8000/unused</span></span>
<span class="line section-header">[MultipartFormData]</span>
<span class="line"><span class="string">key1</span><span>:</span> <span class="string">value1</span></span>
<span class="line"><span class="string"><span class="string">upload1</span></span>: file,<span class="string"><span class="filename">unknown</span></span>;</span>
<span class="line"><span class="string">upload1</span>: file,<span class="filename">unknown</span>;</span>
</span></span><span class="line"></span>
<span class="line"></span>
<span class="line"></span>

View File

@ -2,7 +2,7 @@
<span class="line"></span>
<span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/cookies/set-request-cookie1-valueA</span></span>
<span class="line section-header">[Cookies]</span>
<span class="line"><span class="name">cookie1</span><span>:</span> valueA</span>
<span class="line"><span class="name">cookie1</span><span>:</span> <span class="string">valueA</span></span>
</span><span class="response"><span class="line"><span class="version">HTTP</span> <span class="number">200</span></span>
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
<span class="line"></span><span class="comment"># The cookie is not added in the cookie storage</span>
@ -11,9 +11,9 @@
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
<span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/cookies/set-multiple-request-cookies</span></span>
<span class="line section-header">[Cookies]</span>
<span class="line"><span class="name">user1</span><span>:</span> Bob</span>
<span class="line"><span class="name">user2</span><span>:</span> Bill</span>
<span class="line"><span class="name">user3</span><span>:</span> {{name}}</span>
<span class="line"><span class="name">user1</span><span>:</span> <span class="string">Bob</span></span>
<span class="line"><span class="name">user2</span><span>:</span> <span class="string">Bill</span></span>
<span class="line"><span class="name">user3</span><span>:</span> <span class="string">{{name}}</span></span>
</span><span class="response"><span class="line"><span class="version">HTTP</span> <span class="number">200</span></span>
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
<span class="line"></span>
@ -29,7 +29,7 @@
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
<span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/cookies/assert-that-cookie2-is-valueA-and-valueB</span></span>
<span class="line section-header">[Cookies]</span>
<span class="line"><span class="name">cookie2</span><span>:</span> valueB</span>
<span class="line"><span class="name">cookie2</span><span>:</span> <span class="string">valueB</span></span>
</span><span class="response"><span class="line"><span class="version">HTTP</span> <span class="number">200</span></span>
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
<span class="line"></span>

View File

@ -20,8 +20,8 @@
<span class="line"><span class="query-type">variable</span> <span class="string">"text"</span> <span class="filter-type">htmlEscape</span> <span class="filter-type">htmlUnescape</span> <span class="predicate-type">==</span> <span class="string">"{{text}}"</span></span>
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.id"</span> <span class="filter-type">toInt</span> <span class="predicate-type">==</span> <span class="number">123</span></span>
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.score"</span> <span class="filter-type">toInt</span> <span class="predicate-type">==</span> <span class="number">1</span></span>
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.ips"</span> <span class="filter-type">split</span> ", " <span class="filter-type">count</span> <span class="predicate-type">==</span> <span class="number">3</span></span>
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.ips"</span> <span class="filter-type">replace</span> <span class="string">", "</span> "|" <span class="predicate-type">==</span> <span class="string">"192.168.2.1|10.0.0.20|10.0.0.10"</span></span>
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.ips"</span> <span class="filter-type">split</span> <span class="string">", "</span> <span class="filter-type">count</span> <span class="predicate-type">==</span> <span class="number">3</span></span>
<span class="line"><span class="query-type">jsonpath</span> <span class="string">"$.ips"</span> <span class="filter-type">replace</span> <span class="string">", "</span> <span class="string">"|"</span> <span class="predicate-type">==</span> <span class="string">"192.168.2.1|10.0.0.20|10.0.0.10"</span></span>
<span class="json"><span class="line">{</span>
<span class="line"> "list": [1,2,3],</span>
<span class="line"> "message": "Hello Bob!",</span>

View File

@ -1,9 +1,9 @@
<pre><code class="language-hurl"><span class="hurl-entry"><span class="request"><span class="line"><span class="method">POST</span> <span class="url">http://localhost:8000/multipart-form-data</span></span>
<span class="line section-header">[MultipartFormData]</span>
<span class="line"><span class="string">key1</span><span>:</span> <span class="string">value1</span></span>
<span class="line"><span class="string"><span class="string">upload1</span></span>: file,<span class="string"><span class="filename">data.txt</span></span>;</span>
<span class="line"><span class="string"><span class="string">upload2</span></span>: file,<span class="string"><span class="filename">data.html</span></span>;</span>
<span class="line"><span class="string"><span class="string">upload3</span></span>: file,<span class="string"><span class="filename">data.txt</span></span>; <span class="string">text/html</span></span>
<span class="line"><span class="string">upload1</span>: file,<span class="filename">data.txt</span>;</span>
<span class="line"><span class="string">upload2</span>: file,<span class="filename">data.html</span>;</span>
<span class="line"><span class="string">upload3</span>: file,<span class="filename">data.txt</span>; <span class="string">text/html</span></span>
</span><span class="response"><span class="line"></span>
<span class="line"><span class="version">HTTP</span> <span class="number">200</span></span>
</span></span><span class="line"></span>

View File

@ -17,7 +17,7 @@
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
<span class="line"><span class="method">POST</span> <span class="url">http://localhost:8000/very-verbose/update-cat</span></span>
<span class="line section-header">[MultipartFormData]</span>
<span class="line"><span class="string"><span class="string">cat</span></span>: file,<span class="string"><span class="filename">cat.jpg</span></span>; <span class="string">image/jpeg</span></span>
<span class="line"><span class="string">cat</span>: file,<span class="filename">cat.jpg</span>; <span class="string">image/jpeg</span></span>
</span><span class="response"><span class="line"><span class="version">HTTP</span> <span class="number">200</span></span>
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
<span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/very-verbose/done</span></span>

View File

@ -563,6 +563,7 @@ pub struct Template {
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum TemplateElement {
// TODO: explain the difference between value and encoded
String { value: String, encoded: String },
Expression(Expr),
}

View File

@ -79,7 +79,7 @@ impl fmt::Display for StatusValue {
impl fmt::Display for Template {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut buffer = String::from("");
for element in self.elements.clone() {
for element in self.elements.iter() {
buffer.push_str(element.to_string().as_str());
}
write!(f, "{}", buffer)
@ -111,7 +111,7 @@ impl fmt::Display for Expr {
impl fmt::Display for CookiePath {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut buf = self.name.to_string();
if let Some(attribute) = self.attribute.clone() {
if let Some(attribute) = &self.attribute {
let s = format!("[{}]", attribute);
buf.push_str(s.as_str());
}

View File

@ -17,11 +17,23 @@
*/
use crate::ast::*;
pub trait Htmlable {
trait Htmlable {
fn to_html(&self) -> String;
}
pub fn format_standalone(hurl_file: HurlFile) -> String {
/// Returns an HTML string of the Hurl file `hurl_file`.
///
/// If `standalone` is true, a complete HTML body with inline styling is returned.
/// Otherwise, a `<pre>` HTML tag is returned, without styling.
pub fn format(hurl_file: HurlFile, standalone: bool) -> String {
if standalone {
format_standalone(hurl_file)
} else {
hurl_file.to_html()
}
}
fn format_standalone(hurl_file: HurlFile) -> String {
let css = include_str!("hurl.css");
let body = hurl_file.to_html();
@ -44,14 +56,6 @@ pub fn format_standalone(hurl_file: HurlFile) -> String {
)
}
pub fn format(hurl_file: HurlFile, standalone: bool) -> String {
if standalone {
format_standalone(hurl_file)
} else {
hurl_file.to_html()
}
}
impl Htmlable for HurlFile {
fn to_html(&self) -> String {
let mut buffer = String::from("");
@ -88,7 +92,7 @@ impl Htmlable for Request {
buffer.push_str(self.space0.to_html().as_str());
buffer.push_str(self.method.to_html().as_str());
buffer.push_str(self.space1.to_html().as_str());
buffer.push_str(format!("<span class=\"url\">{}</span>", self.url.to_html()).as_str());
buffer.push_str(self.url.span_with_class("url").as_str());
buffer.push_str("</span>");
buffer.push_str(self.line_terminator0.to_html().as_str());
@ -219,11 +223,11 @@ impl Htmlable for KeyValue {
add_line_terminators(&mut buffer, &self.line_terminators);
buffer.push_str("<span class=\"line\">");
buffer.push_str(self.space0.to_html().as_str());
buffer.push_str(format!("<span class=\"string\">{}</span>", self.key.encoded).as_str());
buffer.push_str(self.key.encoded.to_html().as_str());
buffer.push_str(self.space1.to_html().as_str());
buffer.push_str("<span>:</span>");
buffer.push_str(self.space2.to_html().as_str());
buffer.push_str(format!("<span class=\"string\">{}</span>", self.value.to_html()).as_str());
buffer.push_str(self.value.to_html().as_str());
buffer.push_str("</span>");
buffer.push_str(self.line_terminator0.to_html().as_str());
buffer
@ -256,11 +260,11 @@ impl Htmlable for CompressedOption {
add_line_terminators(&mut buffer, &self.line_terminators);
buffer.push_str("<span class=\"line\">");
buffer.push_str(self.space0.to_html().as_str());
buffer.push_str("<span class=\"string\">compressed</span>");
buffer.push_str("compressed".to_html().as_str());
buffer.push_str(self.space1.to_html().as_str());
buffer.push_str("<span>:</span>");
buffer.push_str(self.space2.to_html().as_str());
buffer.push_str(format!("<span class=\"boolean\">{}</span>", self.value).as_str());
buffer.push_str(self.value.to_html().as_str());
buffer.push_str("</span>");
buffer.push_str(self.line_terminator0.to_html().as_str());
buffer
@ -273,11 +277,11 @@ impl Htmlable for InsecureOption {
add_line_terminators(&mut buffer, &self.line_terminators);
buffer.push_str("<span class=\"line\">");
buffer.push_str(self.space0.to_html().as_str());
buffer.push_str("<span class=\"string\">insecure</span>");
buffer.push_str("insecure".to_html().as_str());
buffer.push_str(self.space1.to_html().as_str());
buffer.push_str("<span>:</span>");
buffer.push_str(self.space2.to_html().as_str());
buffer.push_str(format!("<span class=\"boolean\">{}</span>", self.value).as_str());
buffer.push_str(self.value.to_html().as_str());
buffer.push_str("</span>");
buffer.push_str(self.line_terminator0.to_html().as_str());
buffer
@ -290,7 +294,7 @@ impl Htmlable for CaCertificateOption {
add_line_terminators(&mut buffer, &self.line_terminators);
buffer.push_str("<span class=\"line\">");
buffer.push_str(self.space0.to_html().as_str());
buffer.push_str("<span class=\"string\">cacert</span>");
buffer.push_str("cacert".to_html().as_str());
buffer.push_str(self.space1.to_html().as_str());
buffer.push_str("<span>:</span>");
buffer.push_str(self.space2.to_html().as_str());
@ -307,7 +311,7 @@ impl Htmlable for ClientCertOption {
add_line_terminators(&mut buffer, &self.line_terminators);
buffer.push_str("<span class=\"line\">");
buffer.push_str(self.space0.to_html().as_str());
buffer.push_str("<span class=\"string\">cert</span>");
buffer.push_str("cert".to_html().as_str());
buffer.push_str(self.space1.to_html().as_str());
buffer.push_str("<span>:</span>");
buffer.push_str(self.space2.to_html().as_str());
@ -324,7 +328,7 @@ impl Htmlable for ClientKeyOption {
add_line_terminators(&mut buffer, &self.line_terminators);
buffer.push_str("<span class=\"line\">");
buffer.push_str(self.space0.to_html().as_str());
buffer.push_str("<span class=\"string\">key</span>");
buffer.push_str("key".to_html().as_str());
buffer.push_str(self.space1.to_html().as_str());
buffer.push_str("<span>:</span>");
buffer.push_str(self.space2.to_html().as_str());
@ -341,11 +345,11 @@ impl Htmlable for FollowLocationOption {
add_line_terminators(&mut buffer, &self.line_terminators);
buffer.push_str("<span class=\"line\">");
buffer.push_str(self.space0.to_html().as_str());
buffer.push_str("<span class=\"string\">location</span>");
buffer.push_str("location".to_html().as_str());
buffer.push_str(self.space1.to_html().as_str());
buffer.push_str("<span>:</span>");
buffer.push_str(self.space2.to_html().as_str());
buffer.push_str(format!("<span class=\"boolean\">{}</span>", self.value).as_str());
buffer.push_str(self.value.to_html().as_str());
buffer.push_str("</span>");
buffer.push_str(self.line_terminator0.to_html().as_str());
buffer
@ -358,11 +362,11 @@ impl Htmlable for MaxRedirectOption {
add_line_terminators(&mut buffer, &self.line_terminators);
buffer.push_str("<span class=\"line\">");
buffer.push_str(self.space0.to_html().as_str());
buffer.push_str("<span class=\"string\">max-redirs</span>");
buffer.push_str("max-redirs".to_html().as_str());
buffer.push_str(self.space1.to_html().as_str());
buffer.push_str("<span>:</span>");
buffer.push_str(self.space2.to_html().as_str());
buffer.push_str(format!("<span class=\"number\">{}</span>", self.value).as_str());
buffer.push_str(self.value.to_html().as_str());
buffer.push_str("</span>");
buffer.push_str(self.line_terminator0.to_html().as_str());
buffer
@ -375,11 +379,11 @@ impl Htmlable for RetryOption {
add_line_terminators(&mut buffer, &self.line_terminators);
buffer.push_str("<span class=\"line\">");
buffer.push_str(self.space0.to_html().as_str());
buffer.push_str("<span class=\"string\">retry</span>");
buffer.push_str("retry".to_html().as_str());
buffer.push_str(self.space1.to_html().as_str());
buffer.push_str("<span>:</span>");
buffer.push_str(self.space2.to_html().as_str());
buffer.push_str(format!("<span class=\"boolean\">{}</span>", self.value).as_str());
buffer.push_str(self.value.to_html().as_str());
buffer.push_str("</span>");
buffer.push_str(self.line_terminator0.to_html().as_str());
buffer
@ -392,11 +396,11 @@ impl Htmlable for RetryIntervalOption {
add_line_terminators(&mut buffer, &self.line_terminators);
buffer.push_str("<span class=\"line\">");
buffer.push_str(self.space0.to_html().as_str());
buffer.push_str("<span class=\"string\">retry-interval</span>");
buffer.push_str("retry-interval".to_html().as_str());
buffer.push_str(self.space1.to_html().as_str());
buffer.push_str("<span>:</span>");
buffer.push_str(self.space2.to_html().as_str());
buffer.push_str(format!("<span class=\"number\">{}</span>", self.value).as_str());
buffer.push_str(self.value.to_html().as_str());
buffer.push_str("</span>");
buffer.push_str(self.line_terminator0.to_html().as_str());
buffer
@ -409,11 +413,11 @@ impl Htmlable for RetryMaxCountOption {
add_line_terminators(&mut buffer, &self.line_terminators);
buffer.push_str("<span class=\"line\">");
buffer.push_str(self.space0.to_html().as_str());
buffer.push_str("<span class=\"string\">retry-max-count</span>");
buffer.push_str("retry-max-count".to_html().as_str());
buffer.push_str(self.space1.to_html().as_str());
buffer.push_str("<span>:</span>");
buffer.push_str(self.space2.to_html().as_str());
buffer.push_str(format!("<span class=\"number\">{}</span>", self.value).as_str());
buffer.push_str(self.value.to_html().as_str());
buffer.push_str("</span>");
buffer.push_str(self.line_terminator0.to_html().as_str());
buffer
@ -426,7 +430,7 @@ impl Htmlable for VariableOption {
add_line_terminators(&mut buffer, &self.line_terminators);
buffer.push_str("<span class=\"line\">");
buffer.push_str(self.space0.to_html().as_str());
buffer.push_str("<span class=\"string\">variable</span>");
buffer.push_str("variable".to_html().as_str());
buffer.push_str(self.space1.to_html().as_str());
buffer.push_str("<span>:</span>");
buffer.push_str(self.space2.to_html().as_str());
@ -452,10 +456,10 @@ impl Htmlable for VariableValue {
fn to_html(&self) -> String {
match self {
VariableValue::Null { .. } => "<span class=\"null\">null</span>".to_string(),
VariableValue::Bool(v) => format!("<span class=\"boolean\">{}</span>", v),
VariableValue::Integer(v) => format!("<span class=\"number\">{}</span>", v),
VariableValue::Float(v) => format!("<span class=\"number\">{}</span>", v),
VariableValue::String(t) => format!("<span class=\"string\">{}</span>", t.to_html()),
VariableValue::Bool(v) => v.to_html(),
VariableValue::Integer(v) => v.to_html(),
VariableValue::Float(v) => v.to_html(),
VariableValue::String(t) => t.to_html(),
}
}
}
@ -466,11 +470,11 @@ impl Htmlable for VerboseOption {
add_line_terminators(&mut buffer, &self.line_terminators);
buffer.push_str("<span class=\"line\">");
buffer.push_str(self.space0.to_html().as_str());
buffer.push_str("<span class=\"string\">verbose</span>");
buffer.push_str("verbose".to_html().as_str());
buffer.push_str(self.space1.to_html().as_str());
buffer.push_str("<span>:</span>");
buffer.push_str(self.space2.to_html().as_str());
buffer.push_str(format!("<span class=\"boolean\">{}</span>", self.value).as_str());
buffer.push_str(self.value.to_html().as_str());
buffer.push_str("</span>");
buffer.push_str(self.line_terminator0.to_html().as_str());
buffer
@ -483,11 +487,11 @@ impl Htmlable for VeryVerboseOption {
add_line_terminators(&mut buffer, &self.line_terminators);
buffer.push_str("<span class=\"line\">");
buffer.push_str(self.space0.to_html().as_str());
buffer.push_str("<span class=\"string\">very-verbose</span>");
buffer.push_str("very-verbose".to_html().as_str());
buffer.push_str(self.space1.to_html().as_str());
buffer.push_str("<span>:</span>");
buffer.push_str(self.space2.to_html().as_str());
buffer.push_str(format!("<span class=\"boolean\">{}</span>", self.value).as_str());
buffer.push_str(self.value.to_html().as_str());
buffer.push_str("</span>");
buffer.push_str(self.line_terminator0.to_html().as_str());
buffer
@ -509,7 +513,7 @@ impl Htmlable for FileParam {
add_line_terminators(&mut buffer, &self.line_terminators);
buffer.push_str("<span class=\"line\">");
buffer.push_str(self.space0.to_html().as_str());
buffer.push_str(format!("<span class=\"string\">{}</span>", self.key.to_html()).as_str());
buffer.push_str(self.key.to_html().as_str());
buffer.push_str(self.space1.to_html().as_str());
buffer.push(':');
buffer.push_str(self.space2.to_html().as_str());
@ -525,14 +529,12 @@ impl Htmlable for FileValue {
let mut buffer = String::from("");
buffer.push_str("file,");
buffer.push_str(self.space0.to_html().as_str());
buffer.push_str(
format!("<span class=\"string\">{}</span>", self.filename.to_html()).as_str(),
);
buffer.push_str(self.filename.to_html().as_str());
buffer.push_str(self.space1.to_html().as_str());
buffer.push(';');
buffer.push_str(self.space2.to_html().as_str());
if let Some(content_type) = &self.content_type {
buffer.push_str(format!("<span class=\"string\">{}</span>", content_type).as_str());
buffer.push_str(content_type.to_html().as_str());
}
buffer
}
@ -607,15 +609,12 @@ impl Htmlable for QueryValue {
QueryValue::Header { space0, name } => {
buffer.push_str("<span class=\"query-type\">header</span>");
buffer.push_str(space0.to_html().as_str());
buffer
.push_str(format!("<span class=\"string\">{}</span>", name.to_html()).as_str());
buffer.push_str(name.to_html().as_str());
}
QueryValue::Cookie { space0, expr } => {
buffer.push_str("<span class=\"query-type\">cookie</span>");
buffer.push_str(space0.to_html().as_str());
buffer.push_str(
format!("<span class=\"string\">\"{}\"</span>", expr.to_html()).as_str(),
);
buffer.push_str(expr.to_html().as_str());
}
QueryValue::Body {} => {
buffer.push_str("<span class=\"query-type\">body</span>");
@ -623,14 +622,12 @@ impl Htmlable for QueryValue {
QueryValue::Xpath { space0, expr } => {
buffer.push_str("<span class=\"query-type\">xpath</span>");
buffer.push_str(space0.to_html().as_str());
buffer
.push_str(format!("<span class=\"string\">{}</span>", expr.to_html()).as_str());
buffer.push_str(expr.to_html().as_str());
}
QueryValue::Jsonpath { space0, expr } => {
buffer.push_str("<span class=\"query-type\">jsonpath</span>");
buffer.push_str(space0.to_html().as_str());
buffer
.push_str(format!("<span class=\"string\">{}</span>", expr.to_html()).as_str());
buffer.push_str(expr.to_html().as_str());
}
QueryValue::Regex { space0, value } => {
buffer.push_str("<span class=\"query-type\">regex</span>");
@ -640,8 +637,7 @@ impl Htmlable for QueryValue {
QueryValue::Variable { space0, name } => {
buffer.push_str("<span class=\"query-type\">variable</span>");
buffer.push_str(space0.to_html().as_str());
buffer
.push_str(format!("<span class=\"string\">{}</span>", name.to_html()).as_str());
buffer.push_str(name.to_html().as_str());
}
QueryValue::Duration {} => {
buffer.push_str("<span class=\"query-type\">duration</span>");
@ -663,9 +659,7 @@ impl Htmlable for QueryValue {
impl Htmlable for RegexValue {
fn to_html(&self) -> String {
match self {
RegexValue::Template(template) => {
format!("<span class=\"string\">{}</span>", template.to_html())
}
RegexValue::Template(template) => template.to_html(),
RegexValue::Regex(regex) => regex.to_html(),
}
}
@ -674,13 +668,15 @@ impl Htmlable for RegexValue {
impl Htmlable for CookiePath {
fn to_html(&self) -> String {
let mut buffer = String::from("");
buffer.push_str(self.name.to_html().as_str());
buffer.push('"');
buffer.push_str(self.name.to_encoded_string().as_str());
if let Some(attribute) = &self.attribute {
buffer.push('[');
buffer.push_str(attribute.to_html().as_str());
buffer.push(']');
}
buffer
buffer.push('"');
buffer.to_html()
}
}
@ -873,13 +869,11 @@ impl Htmlable for PredicateFuncValue {
impl Htmlable for PredicateValue {
fn to_html(&self) -> String {
match self {
PredicateValue::String(value) => {
format!("<span class=\"string\">{}</span>", value.to_html())
}
PredicateValue::String(value) => value.to_html(),
PredicateValue::MultilineString(value) => value.to_html(),
PredicateValue::Integer(value) => format!("<span class=\"number\">{}</span>", value),
PredicateValue::Float(value) => format!("<span class=\"number\">{}</span>", value),
PredicateValue::Bool(value) => format!("<span class=\"boolean\">{}</span>", value),
PredicateValue::Integer(value) => value.to_html(),
PredicateValue::Float(value) => value.to_html(),
PredicateValue::Bool(value) => value.to_html(),
PredicateValue::Hex(value) => value.to_html(),
PredicateValue::Base64(value) => value.to_html(),
PredicateValue::Expression(value) => value.to_html(),
@ -923,17 +917,58 @@ impl Htmlable for Bytes {
Bytes::Base64(value) => format!("<span class=\"line\">{}</span>", value.to_html()),
Bytes::File(value) => format!("<span class=\"line\">{}</span>", value.to_html()),
Bytes::Hex(value) => format!("<span class=\"line\">{}</span>", value.to_html()),
Bytes::OnelineString(value) => {
format!("<span class=\"line\">{}</span>", value.to_html())
}
Bytes::Json(value) => value.to_html(),
Bytes::OnelineString(value) => format!(
"<span class=\"line\"><span class=\"string\">{}</span></span>",
value.to_html()
),
Bytes::MultilineString(value) => value.to_html(),
Bytes::Xml(value) => xml_html(value),
}
}
}
impl Htmlable for String {
fn to_html(&self) -> String {
format!("<span class=\"string\">{}</span>", self)
}
}
impl Htmlable for &str {
fn to_html(&self) -> String {
format!("<span class=\"string\">{}</span>", self)
}
}
impl Htmlable for bool {
fn to_html(&self) -> String {
format!("<span class=\"boolean\">{}</span>", self)
}
}
impl Htmlable for u64 {
fn to_html(&self) -> String {
format!("<span class=\"number\">{}</span>", self)
}
}
impl Htmlable for Float {
fn to_html(&self) -> String {
format!("<span class=\"number\">{}</span>", self.encoded)
}
}
impl Htmlable for i64 {
fn to_html(&self) -> String {
format!("<span class=\"number\">{}</span>", self)
}
}
impl Htmlable for usize {
fn to_html(&self) -> String {
format!("<span class=\"number\">{}</span>", self)
}
}
// you should probably define for XML value to be consistent with the other types
fn xml_html(value: &str) -> String {
let mut buffer = String::from("<span class=\"xml\">");
@ -1033,12 +1068,18 @@ impl Htmlable for Regex {
impl Htmlable for EncodedString {
fn to_html(&self) -> String {
format!("<span class=\"string\">{}</span>", self.encoded)
self.encoded.to_html()
}
}
impl Htmlable for Template {
fn to_html(&self) -> String {
self.span_with_class("string")
}
}
impl Template {
fn to_encoded_string(&self) -> String {
let mut s = "".to_string();
if let Some(d) = self.delimiter {
s.push(d);
@ -1053,7 +1094,12 @@ impl Htmlable for Template {
if let Some(d) = self.delimiter {
s.push(d);
}
xml_escape(&s)
s
}
fn span_with_class(&self, class: &str) -> String {
let s = self.to_encoded_string();
format!("<span class=\"{}\">{}</span>", class, xml_escape(&s))
}
}
@ -1084,7 +1130,7 @@ impl Htmlable for FilterValue {
FilterValue::Nth { space0, n: value } => {
let mut buffer = "<span class=\"filter-type\">nth</span>".to_string();
buffer.push_str(space0.to_html().as_str());
buffer.push_str(format!("<span class=\"number\">{}</span>", value).as_str());
buffer.push_str(value.to_html().as_str());
buffer
}
FilterValue::Regex { space0, value } => {