Purpose
File handler plugins are responsible for:- Converting content files to HTML (Markdown → HTML, AsciiDoc → HTML, etc.)
- Processing file content with custom logic
- Supporting multiple file extensions
- Enabling custom content formats
Function Signature
Lifecycle
- Router plugin discovers a content file (e.g.,
blog/my-post.md) - Router plugin creates a
HandledRoutewithtemplateFilepointing to the file - Render plugin reads the file content
- File handler plugin is called based on file extension
- Plugin transforms the raw content to HTML
- HTML is injected into the Angular application
- Post-render plugins process the final HTML
When to Use
Create a file handler plugin when you need to:- Support a new content file format (
.rst,.org,.tex, etc.) - Add custom processing to existing formats (Markdown with special syntax)
- Transform content with custom logic (encrypt, compress, etc.)
- Integrate with external content processing tools
Implementation Examples
Basic File Handler Plugin
Markdown File Handler
Here’s Scully’s built-in Markdown handler:HTML Pass-Through Handler
The simplest file handler just returns the content as-is:AsciiDoc Handler
Custom Format with Metadata
Plugin with Configuration
Registering File Handler Plugins
Basic Registration
Multiple Extensions
Configuration
Setting Plugin Configuration
Getting Plugin Configuration
User Configuration
Users can override plugin configuration inscully.config.ts:
How Files are Processed
1. File Discovery
Router plugin (likecontentFolder) discovers files:
2. File Reading
Render plugin reads the file content:3. File Handler Selection
Scully selects the handler based on file extension:4. Content Transformation
File handler transforms the content:5. HTML Injection
The HTML is injected into the Angular application:Extension Lookup
Scully looks up file handlers in this order:- Exact extension match:
.md→plugins.fileHandler['md'] - Alternate extensions: Check
plugin[AlternateExtensionsForFilePlugin]array - If no handler found, file is skipped with a warning
Best Practices
- Return valid HTML: File handlers must return valid HTML strings
- Handle errors gracefully: Return empty string or default content on error
- Preserve frontmatter: Don’t include YAML/TOML frontmatter in output
- Support configuration: Use
setConfig/getConfigfor user customization - Register alternate extensions: Support common variations (
.md,.markdown) - Log warnings: Inform users of issues without breaking the build
- Keep it synchronous when possible: Avoid async operations unless necessary
- Document configuration: Provide clear TypeScript interfaces for config
- Test with edge cases: Empty files, malformed content, missing metadata
- Performance matters: File handlers run on every content file
Frontmatter Handling
Frontmatter is typically handled before the file handler is called:Built-in File Handler Plugins
Scully includes these file handler plugins:md: Markdown with optional syntax highlighting (also:markdown)html: Pass-through for HTML filesadoc: AsciiDoc support (also:asciidoc,asc)
Related
- Router Plugins - Discover content files
- Render Plugins - Process HTML after injection
- Route Process Plugins - Modify the route list

