katana_render_runtime/markdown/
types.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
4pub enum DiagramKind {
5 Mermaid,
6 PlantUml,
7 DrawIo,
8 MathJax,
9}
10
11#[derive(Debug, Clone)]
12pub struct DiagramBlock {
13 pub kind: DiagramKind,
14 pub source: String,
15}
16
17#[derive(Debug, thiserror::Error)]
18pub enum DiagramValidationError {
19 #[error("{kind} block has empty source")]
20 EmptySource { kind: &'static str },
21
22 #[error("{kind} block is missing required delimiters: {message}")]
23 MissingDelimiters { kind: &'static str, message: String },
24
25 #[error("{kind} block uses an unsupported encoding: {message}")]
26 UnsupportedEncoding { kind: &'static str, message: String },
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
30pub enum DiagramResult {
31 Ok(String),
32 OkPng(Vec<u8>),
33 RawCode {
34 source: String,
35 warning: String,
36 },
37 Err {
38 source: String,
39 error: String,
40 },
41 CommandNotFound {
42 tool_name: String,
43 install_hint: String,
44 source: String,
45 },
46 NotInstalled {
47 kind: String,
48 download_url: String,
49 install_path: std::path::PathBuf,
50 },
51}
52
53pub struct NoOpRenderer;
54
55pub struct RenderOptions {
56 pub allow_raw_html: bool,
57 pub convert_diagrams: bool,
58}
59
60#[derive(Debug, thiserror::Error)]
61pub enum MarkdownError {
62 #[error("Rendering failed: {0}")]
63 RenderFailed(String),
64 #[error("Parse error: {0}")]
65 ParseError(String),
66}
67
68#[derive(Debug, Clone)]
69pub struct RenderOutput {
70 pub html: String,
71}
72
73pub struct RasterizeOps;
74pub struct MarkdownRenderOps;
75
76pub trait DiagramRenderer: Send + Sync {
77 fn render(&self, block: &DiagramBlock) -> DiagramResult;
78}
79
80#[derive(Debug, Default)]
81pub struct KatanaRenderer;