Update the render context to use the new src block format.

This commit is contained in:
Tom Alexander
2025-02-22 16:04:47 -05:00
parent 7e934cd360
commit 4cc04bda46
3 changed files with 61 additions and 27 deletions

View File

@@ -3,6 +3,7 @@ use serde::Serialize;
use super::render_context::RenderContext;
use crate::error::CustomError;
use crate::intermediate::ISrcBlock;
use crate::intermediate::ISrcSegment;
use super::macros::render;
@@ -10,15 +11,51 @@ use super::macros::render;
#[serde(tag = "type")]
#[serde(rename = "src_block")]
pub(crate) struct RenderSrcBlock {
lines: Vec<String>,
lines: Vec<RenderSrcLine>,
language: Option<String>,
post_blank: organic::types::PostBlank,
}
#[derive(Debug, Serialize)]
#[serde(tag = "type")]
#[serde(rename = "src_block")]
pub(crate) struct RenderSrcLine {
children: Vec<RenderSrcSegment>,
}
#[derive(Debug, Serialize)]
pub(crate) enum RenderSrcSegment {
#[serde(rename = "raw_text")]
RawText(String),
#[serde(rename = "highlight_start")]
HighlightStart { name: String },
#[serde(rename = "highlight_end")]
HighlightEnd,
}
render!(RenderSrcBlock, ISrcBlock, original, _render_context, {
let lines = original
.lines
.iter()
.map(|original_line| {
let children = original_line
.children
.iter()
.map(|original_segment| match original_segment {
ISrcSegment::RawText(body) => RenderSrcSegment::RawText(body.to_owned()),
ISrcSegment::HighlightStart { name } => RenderSrcSegment::HighlightStart {
name: name.to_owned(),
},
ISrcSegment::HighlightEnd => RenderSrcSegment::HighlightEnd,
})
.collect();
RenderSrcLine { children }
})
.collect();
Ok(RenderSrcBlock {
// lines: original.lines.clone(),
lines: Vec::new(),
lines,
language: original.language.clone(),
post_blank: original.post_blank,
})