From 7e76d2f500b1463e1c5cb961361e770424dab713 Mon Sep 17 00:00:00 2001 From: PoiScript Date: Wed, 9 Oct 2019 11:57:25 +0800 Subject: [PATCH] feat(demos): specify theme and background in form --- orgize-demos/Cargo.toml | 6 ++-- orgize-demos/src/main.rs | 75 ++++++++++++++++++++++++++++++++-------- 2 files changed, 64 insertions(+), 17 deletions(-) diff --git a/orgize-demos/Cargo.toml b/orgize-demos/Cargo.toml index 81efc74..2aef164 100644 --- a/orgize-demos/Cargo.toml +++ b/orgize-demos/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" publish = false [dependencies] -actix-web = { version = "1.0.7", default-features = false } +actix-web = { version = "1.0.8", default-features = false } orgize = { path = "../orgize", features = ["syntect"] } -serde = { version = "1.0.100", features = ["derive"] } -serde_json = "1.0.40" +serde = { version = "1.0.101", features = ["derive"] } +serde_json = "1.0.41" diff --git a/orgize-demos/src/main.rs b/orgize-demos/src/main.rs index 325589d..f4b7228 100644 --- a/orgize-demos/src/main.rs +++ b/orgize-demos/src/main.rs @@ -4,22 +4,46 @@ use serde::Deserialize; use std::env; use std::io::Result; -use orgize::export::html::SyntectHtmlHandler; +use orgize::export::html::{DefaultHtmlHandler, SyntectHtmlHandler}; +use orgize::syntect::html::IncludeBackground; #[get("/")] fn index() -> HttpResponse { HttpResponse::Ok().content_type("text/html").body( - "

Orgize demos

\ -
\ -

Input content:

\ -
\ -

Output format:

\ - Json
\ - HTML
\ - HTML with highlight
\ - Org
\ -

\ -
", + r#"

Orgize demos

+
+

Input content:

+
+ +
+

Output format:

+ Json
+ HTML
+ Org
+ HTML with highlight
+

Highlight theme:

+ +

Highlight background:

+ +

+
"#, ) } @@ -27,6 +51,8 @@ fn index() -> HttpResponse { struct FormData { format: String, content: String, + theme: String, + background: String, } #[post("/export")] @@ -43,10 +69,31 @@ fn export(form: web::Form) -> Result { .content_type("text/html") .body(String::from_utf8(writer).unwrap())) } - "html-with-highlight" => { + "syntect" => { + let mut handler = SyntectHtmlHandler::new(DefaultHtmlHandler); + + match &*form.theme { + "InspiredGitHub" + | "base16-ocean.dark" + | "base16-eighties.dark" + | "base16-mocha.dark" + | "base16-ocean.light" + | "Solarized (dark)" + | "Solarized (light)" => handler.theme = form.theme.clone(), + _ => return Ok(HttpResponse::BadRequest().body("Unsupported theme".to_string())), + } + + match &*form.background { + "yes" => handler.background = IncludeBackground::Yes, + "no" => handler.background = IncludeBackground::No, + _ => { + return Ok(HttpResponse::BadRequest().body("Unsupported background".to_string())) + } + } + 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()))