|
| 1 | +/* |
| 2 | + * note_definition_fenced_block.rs |
| 3 | + * |
| 4 | + * Functions for processing note definition fenced block nodes in the tree-sitter AST. |
| 5 | + * |
| 6 | + * Copyright (c) 2025 Posit, PBC |
| 7 | + */ |
| 8 | + |
| 9 | +use crate::pandoc::block::{Block, Blocks, NoteDefinitionFencedBlock}; |
| 10 | +use crate::pandoc::location::node_source_info; |
| 11 | + |
| 12 | +use super::pandocnativeintermediate::PandocNativeIntermediate; |
| 13 | + |
| 14 | +pub fn process_note_definition_fenced_block( |
| 15 | + node: &tree_sitter::Node, |
| 16 | + children: Vec<(String, PandocNativeIntermediate)>, |
| 17 | +) -> PandocNativeIntermediate { |
| 18 | + let mut id = String::new(); |
| 19 | + let mut content: Blocks = Vec::new(); |
| 20 | + |
| 21 | + for (node_name, child) in children { |
| 22 | + if node_name == "fenced_div_note_id" { |
| 23 | + if let PandocNativeIntermediate::IntermediateBaseText(text, _) = child { |
| 24 | + // The text includes the ^ prefix, strip it |
| 25 | + id = text.strip_prefix('^').unwrap_or(&text).to_string(); |
| 26 | + } else { |
| 27 | + panic!("Expected BaseText in fenced_div_note_id, got {:?}", child); |
| 28 | + } |
| 29 | + } else if node_name == "block_continuation" { |
| 30 | + // This is a marker node, we don't need to do anything with it |
| 31 | + } else { |
| 32 | + match child { |
| 33 | + PandocNativeIntermediate::IntermediateBlock(block) => { |
| 34 | + content.push(block); |
| 35 | + } |
| 36 | + PandocNativeIntermediate::IntermediateSection(blocks) => { |
| 37 | + content.extend(blocks); |
| 38 | + } |
| 39 | + _ => { |
| 40 | + // Ignore other intermediate nodes |
| 41 | + } |
| 42 | + } |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + PandocNativeIntermediate::IntermediateBlock(Block::NoteDefinitionFencedBlock( |
| 47 | + NoteDefinitionFencedBlock { |
| 48 | + id, |
| 49 | + content, |
| 50 | + source_info: node_source_info(node), |
| 51 | + }, |
| 52 | + )) |
| 53 | +} |
0 commit comments