From 505d7307f25e5b9959f9e9e0dc4bacdcb2208631 Mon Sep 17 00:00:00 2001 From: PoiScript Date: Fri, 13 Sep 2019 23:52:05 +0800 Subject: [PATCH] feat(demos): html with syntax highlighting --- orgize-demos/Cargo.toml | 2 +- orgize-demos/src/main.rs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/orgize-demos/Cargo.toml b/orgize-demos/Cargo.toml index 54c0d27..81efc74 100644 --- a/orgize-demos/Cargo.toml +++ b/orgize-demos/Cargo.toml @@ -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" diff --git a/orgize-demos/src/main.rs b/orgize-demos/src/main.rs index 3f24937..325589d 100644 --- a/orgize-demos/src/main.rs +++ b/orgize-demos/src/main.rs @@ -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 {

Output format:

\ Json
\ HTML
\ + HTML with highlight
\ Org
\

\ ", @@ -40,6 +43,14 @@ fn export(form: web::Form) -> Result { .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)?;