10 releases

0.0.12 Mar 28, 2024
0.0.11 Mar 19, 2024
0.0.9 Feb 9, 2024
0.0.8 Nov 19, 2023
0.0.3 Jul 31, 2023

#549 in Web programming

Download history 1/week @ 2024-02-03 1/week @ 2024-02-10 72/week @ 2024-02-17 31/week @ 2024-02-24 151/week @ 2024-03-16 157/week @ 2024-03-23 44/week @ 2024-03-30 2/week @ 2024-04-06

354 downloads per month

Apache-2.0 OR MIT

460KB
4.5K SLoC

JavaScript 3.5K SLoC // 0.0% comments Rust 657 SLoC // 0.0% comments FreeMarker 4 SLoC

PageTop HighlightJS

PageTop package to display beautiful code snippets on web pages.

License API Docs Crates.io Downloads

Overview

  • Utilizes the versatile highlight.js JavaScript library.
  • Supports 90+ coding languages.
  • Choose from all 95+ available themes.
  • Provides a component for adding code snippets.
  • Highlight multi-line blocks of code.
  • Detects language- and lang- class prefixes.
  • Customize the highlight.js init JavaScript.
  • Smart loading of CSS & JS assets.

Usage

Add the following to your Cargo.toml:

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

Add the dependency pagetop_hljs::HighlightJS to your module:

use pagetop::prelude::*;

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

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

Now you can put 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()
}

📦 About PageTop

PageTop is an opinionated web framework to build modular Server-Side Rendering web solutions.

🚧 Warning

PageTop framework is currently in active development. The API is unstable and subject to frequent changes. Production use is not recommended until version 0.1.0.

📜 License

All code in this project is dual-licensed under either:

at your option. This means you can select the license you prefer! This dual-licensing approach is the de-facto standard in the Rust ecosystem.

Dependencies

~25–40MB
~673K SLoC