Skip to main content

Crate dioxus_code_macro

Crate dioxus_code_macro 

Source
Expand description

dioxus-code-macro

Compile-time syntax highlighting macro for dioxus-code.


Implementation crate for the code! macro re-exported by dioxus-code under its default macro feature. You usually depend on dioxus-code instead of pulling this in directly.

The macro reads a source file at compile time, parses it with arborium, and expands to a static span tree that can be rendered by dioxus-code.

use dioxus_code::code;

let _tree = code!("/snippets/demo.rs");

§Path resolution

Paths are resolved relative to the consumer’s CARGO_MANIFEST_DIR. A leading / anchors to that directory; bare paths resolve from it as well. concat!(...) and env!(...) expressions are also accepted.

let _tree = code!(concat!(env!("CARGO_MANIFEST_DIR"), "/snippets/demo.rs"));

§Explicit language

When the file extension isn’t enough to infer the language, pass CodeOptions::builder with CodeOptions::with_language:

use dioxus_code::{CodeOptions, Language, code};

let _tree = code!(
    "/snippets/demo.rs",
    CodeOptions::builder().with_language(Language::Rust)
);

§License

MIT.

Macros§

code
Compile-time syntax highlighting.