Enhanced AstroMarkdown with New Block Types and Improved Code Block Display
Summary
Enhanced AstroMarkdown.astro component with comprehensive block type support and improved BaseCodeblock.astro to resolve language display duplication issues.
Why Care
These changes significantly improve the markdown rendering capabilities by adding support for 8 new block types (emphasis, alert, warning, quote, info, success, error, tip, note) with elegant styling, while fixing the duplicate language display issue in code blocks. This enhances content presentation and developer experience across the documentation system.
Implementation
Changes Made
Enhanced AstroMarkdown.astro Component
File:
site/src/components/markdown/AstroMarkdown.astro
New Block Type Support
- Refactored code block handling from multiple if statements to switch statement for better maintainability
- Added support for 8 new block types:
emphasis
/em
- Blue gradient with lightbulb iconalert
/warning
- Orange/yellow gradient with warning iconquote
/blockquote
- Subtle background with decorative quote markinfo
/information
- Blue gradient with info iconsuccess
/check
- Green gradient with checkmark iconerror
/danger
- Red gradient with error icontip
/hint
- Purple gradient with lightbulb iconnote
- Gray gradient with note icon
Switch Statement Refactor
- Replaced multiple if-else blocks with switch statement for better performance and readability
- Improved maintainability with centralized block type handling
- Enhanced code organization with logical case grouping
Inline Code Styling Enhancement
- Added comprehensive styling for inline code elements
- Modern typography with monospace font stack
- Interactive hover effects with smooth transitions
- Accessibility improvements with focus states and high contrast support
- Responsive design with dark theme and print support
BaseCodeblock.astro Component Improvements
File:
site/src/components/codeblocks/BaseCodeblock.astro
Language Display Fix
- Resolved duplicate language display issue where language appeared both in header and inside code block
- Added comprehensive CSS rules to hide language indicators inside Shiki code blocks
- Preserved language display in header while removing internal duplication
CSS Enhancements
css
/* Hide language display inside the Shiki code block */
.codeblock-content pre::before,
.codeblock-content code::before,
.codeblock-content pre::after,
.codeblock-content code::after {
content: none !important;
}
/* Hide any language indicators that might appear inside the code block */
.codeblock-content .language-identifier,
.codeblock-content .lang-label,
.codeblock-content .shiki .language-id,
.codeblock-content .shiki::before,
.codeblock-content .shiki::after {
display: none !important;
}
Documentation and Examples
File:
content/vocabulary/ExampleMD.md
Comprehensive Examples File
- Created complete documentation for all new block types
- Usage syntax examples with practical demonstrations
- Design features overview and accessibility considerations
- Responsive design information and best practices
Technical Details
Block Type Implementation
Each block type includes:
- Modern gradient backgrounds with 135-degree angles
- Appropriate icons for visual identification
- Consistent spacing and typography (1.5rem margins, 1.25rem padding)
- Rounded corners (8px border-radius) for modern appearance
- High contrast color combinations for accessibility
- Semantic structure with headers and content areas
Switch Statement Benefits
javascript
switch (blockType) {
case 'emphasis':
case 'em':
// Handles both 'emphasis' and 'em' block types
return <EmphasisBlock />;
case 'alert':
case 'warning':
// Handles both 'alert' and 'warning' block types
return <AlertBlock />;
default:
// Default code block handling
return <BaseCodeblock code={value} lang={lang ?? 'text'} />;
}
Inline Code Styling Features
- Typography: SF Mono, Monaco, Inconsolata, Roboto Mono font stack
- Effects: Subtle gradients, box shadows, and text shadows
- Interactions: Hover effects with transform and enhanced shadows
- Accessibility: Focus states, high contrast mode support
- Responsive: Dark theme adjustments and print-friendly styles
CSS Architecture
- Scoped styles within each block type component
- CSS custom properties for consistent theming
- Important declarations to override Shiki default styles
- Progressive enhancement with fallbacks for older browsers
Integration Points
Markdown Processing Pipeline
- Seamless integration with existing remark/rehype AST processing
- Backward compatibility with existing markdown content
- No breaking changes to existing code block functionality
- Enhanced rendering for new block type syntax
Content Management
- Examples file provides reference for content creators
- Consistent styling across all documentation
- Improved readability for technical content
- Better visual hierarchy in documentation pages
Development Workflow
- Easier maintenance with switch statement structure
- Clear separation of concerns between block types
- Extensible architecture for future block types
- Consistent code style across components
Documentation
Usage Examples
This is an important point that needs emphasis.
Warning
This is a warning message that users should be aware of.
Information
This provides additional information to the reader.
Success
The operation completed successfully!
Error
An error occurred during processing.
Tip
Here's a helpful tip for better results.
Note
Additional context or supplementary information.
This is a memorable quote from an important source.
text
### Block Type Aliases
- `emphasis` or `em`
- `alert` or `warning`
- `quote` or `blockquote`
- `info` or `information`
- `success` or `check`
- `error` or `danger`
- `tip` or `hint`
- `note`
### Related Files
- `site/src/components/markdown/AstroMarkdown.astro` - Main markdown processor
- `site/src/components/codeblocks/BaseCodeblock.astro` - Code block renderer
- `content/vocabulary/ExampleMD.md` - Usage examples and documentation
- `content/changelog--code/2025-06-25_02.md` - This changelog entry
### Performance Impact
- **Improved rendering performance** with switch statement vs multiple if-else
- **Reduced CSS complexity** with scoped styles
- **Better caching** with consistent component structure
- **Enhanced user experience** with smooth transitions and interactions