Crate pagetop_hljs

source ·
Expand description

HighlightJS

PageTop package to display beautiful code snippets on web pages using the versatile highlight.js JavaScript library.

License API Docs Crates.io Downloads


§Usage

Add pagetop-hljs to your Cargo.toml:

[dependencies]
pagetop-hljs = "<Version>"

Add pagetop_hljs::HighlightJS to your dependencies package:

use pagetop::prelude::*;

impl PackageTrait for MyPackage {
    // ...
    fn dependencies(&self) -> Vec<PackageRef> {
        vec![
            // ...
            &pagetop_hljs::HighlightJS,
            // ...
        ]
    }

    fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
        cfg.route("/", service::web::get().to(hljs_sample));
    }
    // ...
}

And put your code snippets on web pages:

use pagetop_hljs::prelude::*;

#[service::get("/")]
async fn hljs_sample(request: HttpRequest) -> ResultPage<Markup, ErrorPage> {
    Page::new(request)
        .with_component(Snippet::with(
            HljsLang::Rust,
            r###"
// This is the main function.
fn main() {
    // Print text to the console.
    println!("Hello World!");
}
            "###,
        ))
        .render()
}

Modules§

  • Configuration settings for package.
  • The package Prelude.

Structs§

Enums§

Traits§