feat(demos): html with syntax highlighting

This commit is contained in:
PoiScript 2019-09-13 23:52:05 +08:00
parent 53c28fb463
commit 505d7307f2
2 changed files with 12 additions and 1 deletions

View file

@ -7,6 +7,6 @@ publish = false
[dependencies]
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_json = "1.0.40"

View file

@ -4,6 +4,8 @@ use serde::Deserialize;
use std::env;
use std::io::Result;
use orgize::export::html::SyntectHtmlHandler;
#[get("/")]
fn index() -> HttpResponse {
HttpResponse::Ok().content_type("text/html").body(
@ -14,6 +16,7 @@ fn index() -> HttpResponse {
<p>Output format:</p>\
<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-with-highlight\"> HTML with highlight<br>\
<input type=\"radio\" name=\"format\" value=\"org\"> Org<br>\
<p><input type=\"submit\" value=\"Submit\"></p>\
</form>",
@ -40,6 +43,14 @@ fn export(form: web::Form<FormData>) -> Result<HttpResponse> {
.content_type("text/html")
.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" => {
let mut writer = Vec::new();
org.org(&mut writer)?;