Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
A small Dioxus component for rendering source code with proper highlighting. Parsing is powered by arborium; themes ship as scoped CSS so you can mix several on one page.
Two ways to highlight:
code!macro — parses at compile time and embeds the highlighted spans. Default.SourceCode— parses at runtime. Opt in with theruntimefeature for dynamic source text.
Quick start
[]
= "0.1"
use *;
use ;
The path is resolved from the consumer's CARGO_MANIFEST_DIR. concat! and env! work too.
When the file extension is ambiguous, pass CodeOptions::builder with CodeOptions::with_language.
Runtime highlighting
For editor-style use cases with dynamic source text:
[]
= { = "0.1", = ["runtime"] }
# use *;
use ;
# let user_input = Stringnew;
# let _ =
rsx!
# ;
Pass a [Language] variant when building SourceCode. The runtime feature includes Rust; enable the matching lang-* feature, or all-languages, for additional grammars.
Editor
dioxus-code-editor is a sibling crate that pairs the highlighter with a textarea input layer:
# use *;
use ;
use Theme;
#
It is controlled — drive CodeEditorProps::value from your own signal and update it inside CodeEditorProps::oninput.
Themes
Thirty-odd built-ins, including Tokyo Night, Catppuccin (all four), Dracula, GitHub Light/Dark, Gruvbox, Nord, One Dark, Rosé Pine, Solarized, the Rustdoc themes, and others. Each is exposed as a Theme constant; pages with multiple themes render side-by-side without leaking styles.
# use *;
# use ;
# let _ = rsx! ;
Use CodeTheme::system to select a light and dark theme with CSS media
queries. This is JavaScript-free and works during SSR:
# use *;
use ;
# let _ = rsx! ;
Examples
Workspace layout
| crate | purpose |
|---|---|
dioxus-code |
The Code component, themes, and runtime/macro entry points. |
dioxus-code-editor |
Editable code surface built on Code. |
dioxus-code-macro |
Implementation of code!. Re-exported by dioxus-code under the macro feature. |
License
MIT. See the repository LICENSE file.