#[cfg(any(feature = "ariadne", feature = "annotate-snippets"))]
use quarto_error_reporting::SourceRenderer;
use quarto_error_reporting::{DiagnosticMessageBuilder, TextRenderOptions};
use quarto_source_map::{SourceContext, SourceInfo};
fn main() {
let mut ctx = SourceContext::new();
let source = "title: My Document\nformat:\n html:\n theme: nosuchtheme\n";
let file_id = ctx.add_file("_quarto.yml".to_string(), Some(source.to_string()));
let start = source.find("nosuchtheme").unwrap();
let location = SourceInfo::original(file_id, start, start + "nosuchtheme".len());
let diag = DiagnosticMessageBuilder::error("Unknown theme")
.with_code("Q-14-1")
.with_location(location)
.problem("`nosuchtheme` is not a known Quarto theme")
.add_hint("Did you mean `cosmo`, `darkly`, or `flatly`?")
.build();
let opts = TextRenderOptions {
enable_hyperlinks: false,
};
println!("=== default renderer (None) ===\n");
println!("{}", diag.to_text_with_renderer(Some(&ctx), &opts, None));
#[cfg(feature = "ariadne")]
{
println!("=== SourceRenderer::Ariadne ===\n");
println!(
"{}",
diag.to_text_with_renderer(Some(&ctx), &opts, Some(SourceRenderer::Ariadne))
);
}
#[cfg(feature = "annotate-snippets")]
{
println!("=== SourceRenderer::AnnotateSnippets ===\n");
println!(
"{}",
diag.to_text_with_renderer(Some(&ctx), &opts, Some(SourceRenderer::AnnotateSnippets),)
);
}
}