Skip to content

Commit

Permalink
add crate-level docs for syntax highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
erratic-pattern committed Nov 11, 2023
1 parent 558cea6 commit 3a2df73
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
//! - [... delayed source code](#-delayed-source-code)
//! - [... handler options](#-handler-options)
//! - [... dynamic diagnostics](#-dynamic-diagnostics)
//! - [... syntax highlighting](#-syntax-highlighting)
//! - [Acknowledgements](#acknowledgements)
//! - [License](#license)
//!
Expand Down Expand Up @@ -625,6 +626,33 @@
//! println!("{:?}", report)
//! ```
//!
//! ### ... syntax highlighting
//!
//! `miette` can be configured to highlight syntax in source code snippets.
//!
//! <!-- TODO: screenshot goes here once default Theme is decided -->
//!
//! To use the built-in highlighting functionality, you must enable the
//! `syntect-highlighter` crate feature. When this feature is enabled, `miette` will
//! automatically use the [`syntect`] crate to highlight the `#[source_code]`
//! field of your [`Diagnostic`].
//!
//! Syntax detection with [`syntect`] is handled by checking 2 methods on the [`SourceCode`] trait, in order:
//! * [language()](SourceCode::language) - Provides the name of the language
//! as a string. For example `"Rust"` will indicate Rust syntax highlighting.
//! You can set the language of a [`NamedSource`] via the
//! [`with_language`](NamedSource::with_language) method.
//! * [name()](SourceCode::name) - In the absence of an explicitly set
//! language, the source code's name is assumed to contain a file name or file path.
//! The highlighter will check for a file extension at the end of the name and
//! try to guess the syntax from that.
//!
//! If you want to use a custom highlighter, you can provide a custom
//! implementation of the [`Highlighter`](highlighters::Highlighter)
//! trait to [`MietteHandlerOpts`] by calling the
//! [`with_syntax_highlighting`](MietteHandlerOpts::with_syntax_highlighting)
//! method. See the [`highlighters`] module docs for more details.
//!
//! ## Acknowledgements
//!
//! `miette` was not developed in a void. It owes enormous credit to various
Expand Down

0 comments on commit 3a2df73

Please sign in to comment.