// Copyright ยฉ 2024 MDX Gen. All rights reserved. // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT // See LICENSE-APACHE.md and LICENSE-MIT.md in the repository root for full license information. //! # MDX Gen Extensions Examples //! //! This example demonstrates the usage of extension functionality in the MDX Gen library. //! It covers syntax highlighting, table formatting, and custom block handling. #![allow(missing_docs)] use mdx_gen::extensions::{ apply_syntax_highlighting, process_custom_blocks, process_tables, ColumnAlignment, CustomBlockType, }; /// Entry point for the MDX Gen extensions examples. /// /// This function runs various examples demonstrating the extension functionality /// of the MDX Gen library. /// /// # Errors /// /// Returns an error if any of the example functions fail. #[tokio::main] pub(crate) async fn main() -> Result<(), Box> { println!("\n๐Ÿงช MDX Gen Extensions Examples\n"); syntax_highlighting_example()?; table_processing_example()?; custom_block_example()?; column_alignment_example()?; custom_block_type_example()?; println!("\n๐ŸŽ‰ All extensions examples completed successfully!"); Ok(()) } /// Demonstrates the syntax highlighting functionality. /// /// This function shows how to apply syntax highlighting to code blocks. /// /// # Errors /// /// Returns an error if syntax highlighting fails. fn syntax_highlighting_example( ) -> Result<(), Box> { println!("๐Ÿฆ€ Syntax Highlighting Example"); println!("---------------------------------------------"); let code = r#"fn main() { println!("Hello, world!"); }"#; let language = "rust"; let highlighted = apply_syntax_highlighting(code, language)?; println!(" โœ… Highlighted Rust code:\n{}", highlighted); Ok(()) } /// Demonstrates the enhanced table processing functionality. /// /// This function shows how tables are processed and formatted. /// /// # Errors /// /// Returns an error if table processing fails. fn table_processing_example() -> Result<(), Box> { println!("\n๐Ÿฆ€ Table Processing Example"); println!("---------------------------------------------"); let table_html = r#"
LeftCenterRight
"#; let processed_table = process_tables(table_html); println!(" โœ… Processed table HTML:\n{}", processed_table); Ok(()) } /// Demonstrates the custom block processing functionality. /// /// This function shows how custom blocks are processed and transformed. /// /// # Errors /// /// Returns an error if custom block processing fails. fn custom_block_example() -> Result<(), Box> { println!("\n๐Ÿฆ€ Custom Block Example"); println!("---------------------------------------------"); let content = r#"
This is a note.
This is a warning.
This is a tip.
"#; let processed_content = process_custom_blocks(content); println!(" โœ… Processed custom blocks:\n{}", processed_content); Ok(()) } /// Demonstrates the usage of column alignment functionality. /// /// This function shows how column alignments are represented and used. /// /// # Errors /// /// Returns an error if the example fails. fn column_alignment_example() -> Result<(), Box> { println!("\n๐Ÿฆ€ Column Alignment Example"); println!("---------------------------------------------"); let alignments = vec![ ColumnAlignment::Left, ColumnAlignment::Center, ColumnAlignment::Right, ]; for alignment in alignments { println!(" โœ… Column alignment: {:?}", alignment); } Ok(()) } /// Demonstrates the usage of custom block types. /// /// This function shows how different custom block types are represented and used. /// /// # Errors /// /// Returns an error if the example fails. fn custom_block_type_example() -> Result<(), Box> { println!("\n๐Ÿฆ€ Custom Block Type Example"); println!("---------------------------------------------"); let block_types = vec![ CustomBlockType::Note, CustomBlockType::Warning, CustomBlockType::Tip, CustomBlockType::Info, CustomBlockType::Important, CustomBlockType::Caution, ]; for block_type in block_types { println!( " โœ… Block type: {:?}, Alert class: {}, Title: {}", block_type, block_type.get_alert_class(), block_type.get_title() ); } Ok(()) }