mirror of https://github.com/zkat/miette.git
add crate-level docs for syntax highlighting
This commit is contained in:
parent
6a856f428e
commit
c679d87bef
28
src/lib.rs
28
src/lib.rs
|
|
@ -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)
|
||||
//!
|
||||
|
|
@ -643,6 +644,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
|
||||
|
|
|
|||
Loading…
Reference in New Issue