Skip to content

Commit 83ba547

Browse files
committed
update some out of date docs
1 parent 28fb84b commit 83ba547

6 files changed

Lines changed: 23 additions & 29 deletions

File tree

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ A small Dioxus component for rendering source code with proper highlighting. Par
2121

2222
Two ways to highlight:
2323

24-
- **[`code!`] macro** — parses at compile time. The runtime ships only the spans, no parser. Default.
25-
- **[`SourceCode`]** — parses at runtime. Opt in with the `runtime` feature when the source isn't known until the user types it.
24+
- **[`code!`] macro** — parses at compile time and embeds the highlighted spans. Default.
25+
- **[`SourceCode`]** — parses at runtime. Opt in with the `runtime` feature for dynamic source text.
2626

2727
## Quick start
2828

@@ -51,7 +51,7 @@ When the file extension is ambiguous, pass [`CodeOptions::builder`] with [`CodeO
5151

5252
## Runtime highlighting
5353

54-
For editor-style use cases where the source isn't known at compile time:
54+
For editor-style use cases with dynamic source text:
5555

5656
```toml
5757
[dependencies]
@@ -60,24 +60,23 @@ dioxus-code = { version = "0.1", features = ["runtime"] }
6060

6161
```rust
6262
# use dioxus::prelude::*;
63-
use dioxus_code::{Code, CodeOptions, Language, SourceCode, Theme};
63+
use dioxus_code::{Code, Language, SourceCode, Theme};
6464
# let user_input = String::new();
6565
# let _ =
6666
rsx! {
6767
Code {
68-
src: SourceCode::new(user_input)
69-
.with_options(CodeOptions::builder().with_language(Language::Rust)),
68+
src: SourceCode::new(Language::Rust, user_input),
7069
theme: Theme::GITHUB_LIGHT,
7170
}
7271
}
7372
# ;
7473
```
7574

76-
Language must be set explicitly with the same [`CodeOptions`] builder used by [`code!`]. The default `runtime` feature includes Rust; pass `lang-python`, `lang-toml`, or `all-languages` for the rest.
75+
Pass a [`Language`] variant when building [`SourceCode`]. The `runtime` feature includes Rust; enable the matching `lang-*` feature, or `all-languages`, for additional grammars.
7776

7877
## Editor
7978

80-
[`dioxus-code-editor`] is a sibling crate that pairs the highlighter with a `contenteditable` input layer:
79+
[`dioxus-code-editor`] is a sibling crate that pairs the highlighter with a textarea input layer:
8180

8281
```rust
8382
# use dioxus::prelude::*;
@@ -131,7 +130,7 @@ Code {
131130

132131
```sh
133132
dx serve --example dioxus-code-basic # macro + runtime side by side
134-
dx serve --example dioxus-code-macro-only # compile-time only, no parser in the binary
133+
dx serve --example dioxus-code-macro-only # compile-time highlighted spans
135134
dx serve --example dioxus-code-live-input # textarea bound to runtime highlighter
136135
```
137136

code-editor/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ A controlled, syntax-highlighted code editor for Dioxus. Pairs an editable input
2323

2424
```toml
2525
[dependencies]
26-
dioxus-code-editor = 0.1.0"
26+
dioxus-code-editor = "0.1.0"
2727
```
2828

2929
```rust
@@ -53,7 +53,7 @@ The component is controlled — drive [`CodeEditorProps::value`] from your own s
5353
| prop | description |
5454
|---|---|
5555
| [`CodeEditorProps::value`] | Current editor contents. |
56-
| [`CodeEditorProps::language`] | Tree-sitter grammar selection. Pass a [`Language`] variant (for example [`Language::Rust`]) or use [`Language::from_slug`] for custom slugs. |
56+
| [`CodeEditorProps::language`] | Syntax grammar selection. Pass a [`Language`] variant (for example [`Language::Rust`]) or use [`Language::from_slug`] for runtime slugs. |
5757
| [`CodeEditorProps::theme`] | Syntax theme selection shared with [`dioxus-code`](https://crates.io/crates/dioxus-code); accepts [`Theme`] or [`CodeTheme`]. |
5858
| [`CodeEditorProps::line_numbers`] | Show a one-based line gutter. Defaults to `true`. |
5959
| [`CodeEditorProps::read_only`] | Disable editing while preserving highlighting. |

dioxus-code-macro/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
Implementation crate for the [`code!`] macro re-exported by [`dioxus-code`](https://crates.io/crates/dioxus-code) under its default `macro` feature. You usually depend on `dioxus-code` instead of pulling this in directly.
2121

22-
The macro reads a source file at compile time, parses it with [`arborium`](https://crates.io/crates/arborium), and expands to a static span tree. The runtime binary ships only the spans — no parser.
22+
The macro reads a source file at compile time, parses it with [`arborium`](https://crates.io/crates/arborium), and expands to a static span tree that can be rendered by `dioxus-code`.
2323

2424
```rust
2525
use dioxus_code::code;

docsite/src/main.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ fn Hero(theme: CodeTheme, theme_label: String) -> Element {
530530
"."
531531
}
532532
p { class: "hero-lede",
533-
"A drop-in component with two source modescompile-time macro and runtime detection. No JS, no flash of unstyled code."
533+
"A drop-in component with two source modes: compile-time macro and runtime highlighting with explicit language selection."
534534
}
535535
div { class: "hero-terminal-block",
536536
div { class: "hero-terminal-bar",
@@ -626,30 +626,30 @@ fn FeatureRowReceipt() -> Element {
626626
span { class: "receipt-value", "OPT-IN" }
627627
}
628628
li { class: "receipt-item receipt-optional",
629-
span { class: "receipt-label", "Tree-sitter grammars" }
629+
span { class: "receipt-label", "Runtime grammars" }
630630
span { class: "receipt-dots" }
631631
span { class: "receipt-value", "+3.33 MiB" }
632632
}
633633
}
634634
div { class: "receipt-rule double" }
635635
div { class: "receipt-total",
636-
span { class: "receipt-total-label", "PARSER BYTES SHIPPED" }
637-
span { class: "receipt-total-value", "0" }
636+
span { class: "receipt-total-label", "COMPILE-TIME MODE" }
637+
span { class: "receipt-total-value", "STATIC" }
638638
}
639639
}
640640
aside { class: "receipt-aside",
641641
div { class: "receipt-aside-row",
642642
span { class: "receipt-aside-num", "01" }
643643
div {
644644
h3 { class: "receipt-aside-title", "code!" }
645-
p { class: "receipt-aside-text", "Tokenizes during cargo build. The runtime gets pre-styled markup with no parser bytes." }
645+
p { class: "receipt-aside-text", "Tokenizes during cargo build and embeds highlighted spans for rendering." }
646646
}
647647
}
648648
div { class: "receipt-aside-row",
649649
span { class: "receipt-aside-num", "02" }
650650
div {
651651
h3 { class: "receipt-aside-title", "SourceCode" }
652-
p { class: "receipt-aside-text", "Pull it in when input is dynamic. Tree-sitter grammars detect language automatically." }
652+
p { class: "receipt-aside-text", "Pull it in when input is dynamic and pass the language your source uses." }
653653
}
654654
}
655655
div { class: "receipt-aside-row",

src/advanced.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -784,11 +784,7 @@ impl Buffer {
784784
/// Useful for handing off to [`Code()`](crate::Code()) or any consumer
785785
/// that takes the frozen snapshot type.
786786
pub fn highlighted(&self) -> HighlightedSource {
787-
HighlightedSource::from_owned_parts(
788-
self.source.clone(),
789-
self.language,
790-
self.spans.clone(),
791-
)
787+
HighlightedSource::from_owned_parts(self.source.clone(), self.language, self.spans.clone())
792788
}
793789

794790
fn parser_for(
@@ -1381,8 +1377,8 @@ fn grammar_for(language: Language) -> (arborium_tree_sitter::LanguageFn, &'stati
13811377

13821378
/// A byte-range edit description used to drive incremental highlighting.
13831379
///
1384-
/// Build one from a real edit signal (for example a contenteditable
1385-
/// `beforeinput` event) and pass it to [`Buffer::edit`]. `start_byte` and
1380+
/// Build one from a real edit signal (for example a textarea `beforeinput`
1381+
/// event) and pass it to [`Buffer::edit`]. `start_byte` and
13861382
/// `old_end_byte` index into the buffer's previous source, while
13871383
/// `new_end_byte` indexes into the new source supplied alongside the edit.
13881384
///

src/language.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
//!
33
//! [`Language`] is a closed set of Arborium language slugs. Each named variant
44
//! is gated by the same cargo feature as the corresponding grammar in
5-
//! `dioxus-code`, so the enum only ever exposes variants whose grammar is
6-
//! actually compiled into this build.
5+
//! `dioxus-code`, so the enum exposes the variants compiled into this build.
76
87
macro_rules! define_languages {
98
(
@@ -16,8 +15,8 @@ macro_rules! define_languages {
1615
///
1716
/// Each variant maps to an Arborium language slug via
1817
/// [`Language::slug`]. Variants are gated by the same `lang-*` cargo
19-
/// features as the grammar lookup table, so unsupported builds simply
20-
/// don't expose those variants.
18+
/// features as the grammar lookup table, so each build exposes the
19+
/// variants enabled for that build.
2120
///
2221
/// ```rust
2322
/// use dioxus_code::Language;

0 commit comments

Comments
 (0)