renderer_selection/
renderer_selection.rs1#[cfg(any(feature = "ariadne", feature = "annotate-snippets"))]
14use quarto_error_reporting::SourceRenderer;
15use quarto_error_reporting::{DiagnosticMessageBuilder, TextRenderOptions};
16use quarto_source_map::{SourceContext, SourceInfo};
17
18fn main() {
19 let mut ctx = SourceContext::new();
20 let source = "title: My Document\nformat:\n html:\n theme: nosuchtheme\n";
21 let file_id = ctx.add_file("_quarto.yml".to_string(), Some(source.to_string()));
22
23 let start = source.find("nosuchtheme").unwrap();
25 let location = SourceInfo::original(file_id, start, start + "nosuchtheme".len());
26
27 let diag = DiagnosticMessageBuilder::error("Unknown theme")
28 .with_code("Q-14-1")
29 .with_location(location)
30 .problem("`nosuchtheme` is not a known Quarto theme")
31 .add_hint("Did you mean `cosmo`, `darkly`, or `flatly`?")
32 .build();
33
34 let opts = TextRenderOptions {
36 enable_hyperlinks: false,
37 };
38
39 println!("=== default renderer (None) ===\n");
41 println!("{}", diag.to_text_with_renderer(Some(&ctx), &opts, None));
42
43 #[cfg(feature = "ariadne")]
44 {
45 println!("=== SourceRenderer::Ariadne ===\n");
46 println!(
47 "{}",
48 diag.to_text_with_renderer(Some(&ctx), &opts, Some(SourceRenderer::Ariadne))
49 );
50 }
51
52 #[cfg(feature = "annotate-snippets")]
53 {
54 println!("=== SourceRenderer::AnnotateSnippets ===\n");
55 println!(
56 "{}",
57 diag.to_text_with_renderer(Some(&ctx), &opts, Some(SourceRenderer::AnnotateSnippets),)
58 );
59 }
60}