feat(demos): html with syntax highlighting
This commit is contained in:
parent
53c28fb463
commit
505d7307f2
|
@ -7,6 +7,6 @@ publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = { version = "1.0.7", default-features = false }
|
actix-web = { version = "1.0.7", default-features = false }
|
||||||
orgize = { path = "../orgize" }
|
orgize = { path = "../orgize", features = ["syntect"] }
|
||||||
serde = { version = "1.0.100", features = ["derive"] }
|
serde = { version = "1.0.100", features = ["derive"] }
|
||||||
serde_json = "1.0.40"
|
serde_json = "1.0.40"
|
||||||
|
|
|
@ -4,6 +4,8 @@ use serde::Deserialize;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::io::Result;
|
use std::io::Result;
|
||||||
|
|
||||||
|
use orgize::export::html::SyntectHtmlHandler;
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
fn index() -> HttpResponse {
|
fn index() -> HttpResponse {
|
||||||
HttpResponse::Ok().content_type("text/html").body(
|
HttpResponse::Ok().content_type("text/html").body(
|
||||||
|
@ -14,6 +16,7 @@ fn index() -> HttpResponse {
|
||||||
<p>Output format:</p>\
|
<p>Output format:</p>\
|
||||||
<input type=\"radio\" name=\"format\" value=\"json\" checked> Json<br>\
|
<input type=\"radio\" name=\"format\" value=\"json\" checked> Json<br>\
|
||||||
<input type=\"radio\" name=\"format\" value=\"html\"> HTML<br>\
|
<input type=\"radio\" name=\"format\" value=\"html\"> HTML<br>\
|
||||||
|
<input type=\"radio\" name=\"format\" value=\"html-with-highlight\"> HTML with highlight<br>\
|
||||||
<input type=\"radio\" name=\"format\" value=\"org\"> Org<br>\
|
<input type=\"radio\" name=\"format\" value=\"org\"> Org<br>\
|
||||||
<p><input type=\"submit\" value=\"Submit\"></p>\
|
<p><input type=\"submit\" value=\"Submit\"></p>\
|
||||||
</form>",
|
</form>",
|
||||||
|
@ -40,6 +43,14 @@ fn export(form: web::Form<FormData>) -> Result<HttpResponse> {
|
||||||
.content_type("text/html")
|
.content_type("text/html")
|
||||||
.body(String::from_utf8(writer).unwrap()))
|
.body(String::from_utf8(writer).unwrap()))
|
||||||
}
|
}
|
||||||
|
"html-with-highlight" => {
|
||||||
|
let mut writer = Vec::new();
|
||||||
|
let mut handler = SyntectHtmlHandler::default();
|
||||||
|
org.html_with_handler(&mut writer, &mut handler)?;
|
||||||
|
Ok(HttpResponse::Ok()
|
||||||
|
.content_type("text/html")
|
||||||
|
.body(String::from_utf8(writer).unwrap()))
|
||||||
|
}
|
||||||
"org" => {
|
"org" => {
|
||||||
let mut writer = Vec::new();
|
let mut writer = Vec::new();
|
||||||
org.org(&mut writer)?;
|
org.org(&mut writer)?;
|
||||||
|
|
Loading…
Reference in a new issue