### Install Fastvolt Markdown Parser via Composer Source: https://github.com/fastvolt/markdown/blob/v0.3.0/README.md This command installs the Fastvolt Markdown parser using Composer. It ensures that the library and its dependencies are correctly set up in your PHP project. ```sh composer require fastvolt/markdown ``` -------------------------------- ### Fastvolt Markdown Parser `run` Method with `MarkdownEnum::TO_HTML_FILE` Source: https://github.com/fastvolt/markdown/blob/v0.3.0/README.md This example demonstrates using the `run` method with `MarkdownEnum::TO_HTML_FILE` as an alternative to `saveToHtmlFile()`. It specifies the output directory and filename for the compiled HTML file. ```php Markdown::new() ->addOutputDirectory(__DIR__ . '/build') ->run(MarkdownEnum::TO_HTML_FILE, 'index.html'); ``` -------------------------------- ### Combine Multiple Markdown Files and Compile to Directories Source: https://github.com/fastvolt/markdown/blob/v0.3.0/README.md An advanced example demonstrating the combination of multiple Markdown files (`addFile`) and inline content (`setInlineContent`, `setContent`) which are then compiled and saved to multiple output directories (`addOutputDirectory`). The final output is an HTML file named 'index.html'. This method also shows how to include header and footer markdown files. ```php $markdown = Markdown::new(sanitize: true) // include header file's markdown contents ->addFile('./Header.md') // body contents ->setInlineContent('_My name is **vincent**, the co-author of this blog_') ->setContent('Kindly follow me on my GitHub page via: [@vincent](https://github.com/oladoyinbov).') ->setContent('Here are the lists of my projects:') ->setContent(' - Dragon CMS - Fastvolt Framework. + Fastvolt Router + Markdown Parser. ') // include footer file's markdown contents ->addFile(__DIR__ . '/Footer.md') // add the main compilation directory ->addOutputDirectory(__DIR__ . '/pages/') // add another compilation directory to backup the result ->addOutputDirectory(__DIR__ . '/backup/pages/') // compile and store as 'index.html' ->saveToHtmlFile(file_name: 'index.html'); if ($markdown) { echo "Compile Successful. Files created in /pages/ and /backup/pages/"; } ``` -------------------------------- ### Convert Markdown File to Raw HTML with Fastvolt PHP Source: https://github.com/fastvolt/markdown/blob/v0.3.0/README.md This example shows how to parse a Markdown file and output its content as raw HTML. It utilizes the `addFile` method to specify the Markdown source and `getHtml` to retrieve the compiled output. ```php $markdown = Markdown::new(); // add markdown file to parse $markdown->addFile(__DIR__ . '/sample.md'); // compile and get as raw html echo $markdown->getHtml(); ``` -------------------------------- ### Convert Markdown Directory to HTML Directory Structure with Fastvolt PHP Source: https://github.com/fastvolt/markdown/blob/v0.3.0/README.md This example demonstrates converting an entire directory of Markdown files into a mirrored directory structure of HTML files. It uses `setSourceDirectory`, `addOutputDirectory`, and `run` with `MarkdownEnum::TO_HTML_DIRECTORY`. ```php use FastVolt\Helper\Markdown; use FastVolt\Helper\Markdown\Enums\MarkdownEnum; $markdown = Markdown::new() // Set the source directory to read all .md files from (including sub-directories) ->setSourceDirectory(__DIR__ . '/docs/') // Set the output directory to compile the mirrored HTML structure to (Alias: ->setCompileDir()) ->addOutputDirectory(__DIR__ . '/public/') // Run the directory conversion process ->run(MarkdownEnum::TO_HTML_DIRECTORY); if ($markdown) { echo "Directory conversion successful!"; } // If '/docs/guide/*.md' exists, it creates '/public/guide/*.html'. ``` -------------------------------- ### Handle Markdown File and Conversion Errors Source: https://context7.com/fastvolt/markdown/llms.txt Provides examples of error handling for common issues encountered during Markdown processing. This includes catching `MarkdownFileNotFound` exceptions for missing files and `LogicException` for invalid states like attempting to compile without content or save without an output directory. ```php use FastVolt\Helper\Markdown; use FastVolt\Helper\Markdown\Exceptions\MarkdownFileNotFound; try { $markdown = Markdown::new() ->addFile(__DIR__ . '/nonexistent.md') ->getHtml(); } catch (MarkdownFileNotFound $e) { echo "Error: " . $e->getMessage(); // Output: File name or directory (./nonexistent.md) does not exist! } try { // Attempting to compile without setting content $markdown = Markdown::new()->getHtml(); } catch (\LogicException $e) { echo "Error: " . $e->getMessage(); // Output: Set a Markdown Content or File Before Conversion! } try { // Attempting to save without output directory $markdown = Markdown::new() ->setContent('# Test') ->saveToHtmlFile('test.html'); } catch (\LogicException $e) { echo "Error: " . $e->getMessage(); // Output: Output directory not set. Use the setCompileDir() or setOutputDirectory() method before conversion process. } ``` -------------------------------- ### PHP: Compile Multi-Source Markdown Documents with FastVolt Source: https://context7.com/fastvolt/markdown/llms.txt This PHP code snippet demonstrates how to use the FastVolt Markdown library to build a complete HTML document by combining content from multiple Markdown files and inline strings. It showcases the fluent API for chaining methods and adding various content types, including code blocks and raw HTML. The example also illustrates setting multiple output directories for deployment. ```php use FastVolt\Helper\Markdown; // Create template files: // navigation.md: [Home](/) | [About](/about) | [Contact](/contact) // sidebar.md: ## Quick Links\n- [Link 1](#)\n- [Link 2](#) $markdown = Markdown::new(sanitize: true) // Header section ->setContent("# Complete Website Page\n## Generated from Multiple Sources") // Navigation ->addFile(__DIR__ . '/templates/navigation.md') // Main content with inline elements ->setInlineContent('**Author:** _Jane Smith_') ->setContent("This page demonstrates combining multiple sources.") ->setContent("## Features\n- Multi-file support\n- Inline content\n- Safe HTML escaping") // Code example ->setContent("```php\n$markdown = Markdown::new();\n```") // Sidebar ->addFile(__DIR__ . '/templates/sidebar.md') // Footer with raw HTML (will be escaped) ->setContent('') // Multiple deployment targets ->addOutputDirectory(__DIR__ . '/website/') ->addOutputDirectory(__DIR__ . '/staging/') // Generate file ->saveToHtmlFile('index.html'); // Creates ./website/index.html and ./staging/index.html with all content combined ``` -------------------------------- ### Interface Method Reference Source: https://github.com/fastvolt/markdown/blob/v0.3.0/README.md Reference for the fluent API methods used to configure and execute the Markdown parser. These methods allow for chaining commands to set up parsing options and initiate the conversion process. ```APIDOC ## `::new(bool $sanitize = true)` ### Description Initialize the parser instance. This is the preferred static factory method for creating a new parser object. ### Method `static` ### Parameters #### Path Parameters - **`$sanitize`** (bool) - Optional - Specifies whether to sanitize the output HTML. Defaults to `true`. ### Response #### Success Response (200) - **`self`** - An instance of the parser class. ``` ```APIDOC ## `->setSourceDirectory(string $name)` ### Description Sets the input root directory for whole-directory compilation. ### Method `instance` ### Parameters #### Path Parameters - **`$name`** (string) - Required - The path to the source directory. ### Response #### Success Response (200) - **`static`** - The parser instance for chaining. ``` ```APIDOC ## `->setContent(string $content)` ### Description Adds multi-line Markdown content (supports lists, headings, etc.) to the compilation queue. ### Method `instance` ### Parameters #### Path Parameters - **`$content`** (string) - Required - The multi-line Markdown content to add. ### Response #### Success Response (200) - **`static`** - The parser instance for chaining. ``` ```APIDOC ## `->setInlineContent(string $content)` ### Description Adds single-line Markdown content (e.g., *bold*, **italic**) to the compilation queue. ### Method `instance` ### Parameters #### Path Parameters - **`$content`** (string) - Required - The single-line Markdown content to add. ### Response #### Success Response (200) - **`static`** - The parser instance for chaining. ``` ```APIDOC ## `->addFile(string $fileName)` ### Description Adds a single Markdown file path to the compilation queue. This method is an alias for `->setFile()`. ### Method `instance` ### Parameters #### Path Parameters - **`$fileName`** (string) - Required - The path to the Markdown file. ### Response #### Success Response (200) - **`static`** - The parser instance for chaining. ``` ```APIDOC ## `->addMultipleFiles(array $names)` ### Description Adds an array of Markdown file paths to the compilation queue. ### Method `instance` ### Parameters #### Path Parameters - **`$names`** (array) - Required - An array of paths to Markdown files. ### Response #### Success Response (200) - **`static`** - The parser instance for chaining. ``` ```APIDOC ## `->addOutputDirectory(string $dir)` ### Description Adds a directory where the compiled HTML will be saved. This allows for multiple output targets. ### Method `instance` ### Parameters #### Path Parameters - **`$dir`** (string) - Required - The path to the output directory. ### Response #### Success Response (200) - **`static`** - The parser instance for chaining. ``` ```APIDOC ## `->addMultipleOutputDirectories(array $dirs)` ### Description Adds an array of directories where the compiled HTML will be saved. ### Method `instance` ### Parameters #### Path Parameters - **`$dirs`** (array) - Required - An array of paths to output directories. ### Response #### Success Response (200) - **`static`** - The parser instance for chaining. ``` ```APIDOC ## `->getHtml()` ### Description Executes the compilation process and returns the raw HTML string. ### Method `instance` ### Response #### Success Response (200) - **`string|null`** - The compiled HTML string, or `null` if compilation failed. ### Alias `->toHtml()` ``` ```APIDOC ## `->saveToHtmlFile(string $name)` ### Description Executes the compilation process and writes the output to the specified HTML file(s). ### Method `instance` ### Parameters #### Path Parameters - **`$name`** (string) - Required - The name or path for the output HTML file(s). ### Response #### Success Response (200) - **`bool`** - `true` if the file was saved successfully, `false` otherwise. ### Alias `->toHtmlFile()` ``` ```APIDOC ## `->run(MarkdownEnum $as, ?string $file)` ### Description A universal command to execute conversion based on the specified `MarkdownEnum` target. ### Method `instance` ### Parameters #### Path Parameters - **`$as`** (MarkdownEnum) - Required - The target format for conversion. - **`$file`** (string|null) - Optional - A file path to use for specific conversion types. ### Response #### Success Response (200) - **`mixed`** - The result of the conversion, type depends on the `$as` parameter. ``` -------------------------------- ### Notes Source: https://github.com/fastvolt/markdown/blob/v0.3.0/README.md Provides context about the library's origin and relationship to other projects. ```APIDOC ## Notes > This library is an extended and simplified version of the excellent [Parsedown](https://github.com/erusev/parsedown/) by Erusev. ``` -------------------------------- ### Universal Markdown Execution with Enums Source: https://context7.com/fastvolt/markdown/llms.txt Utilizes the universal `run()` method with `MarkdownEnum` to manage different execution modes. Supported modes include converting to raw HTML, saving to an HTML file, and converting an entire directory of Markdown files to HTML. ```php use FastVolt\Helper\Markdown; use FastVolt\Helper\Markdown\Enums\MarkdownEnum; // Mode 1: TO_HTML - Get raw HTML string $html = Markdown::new() ->setContent('# Heading') ->run(MarkdownEnum::TO_HTML); echo $html; //

Heading

// Mode 2: TO_HTML_FILE - Save to HTML file $result = Markdown::new() ->setContent('# Page Title') ->addOutputDirectory(__DIR__ . '/dist/') ->run(MarkdownEnum::TO_HTML_FILE, 'page.html'); // Creates: ./dist/page.html // Mode 3: TO_HTML_DIRECTORY - Convert entire directory $success = Markdown::new() ->setSourceDirectory(__DIR__ . '/markdown-docs/') ->addOutputDirectory(__DIR__ . '/html-docs/') ->run(MarkdownEnum::TO_HTML_DIRECTORY); // Converts all .md files to .html with same structure ``` -------------------------------- ### Parse Markdown File to HTML with Fastvolt Source: https://context7.com/fastvolt/markdown/llms.txt Reads a Markdown file from the specified path and converts its content to HTML. The parser is initialized, the file is added to the parsing queue, and the resulting HTML is retrieved. Ensure the Markdown file exists at the provided path. ```php use FastVolt\Helper\Markdown; // Create a markdown file: sample.md // Contents: // # Welcome // - Item 1 // - Item 2 // > Blockquote text $markdown = Markdown::new(); // Add markdown file to parse $markdown->addFile(__DIR__ . '/sample.md'); // Compile and get raw HTML $html = $markdown->getHtml(); echo $html; // Output: //

Welcome

// //

Blockquote text

``` -------------------------------- ### Convert Directory Structure to HTML with Fastvolt Source: https://context7.com/fastvolt/markdown/llms.txt Recursively converts all Markdown files within a source directory into an HTML structure mirrored in the specified output directory. This is useful for generating static websites or documentation. The `run` method with `TO_HTML_DIRECTORY` enum initiates the conversion. ```php use FastVolt\Helper\Markdown; use FastVolt\Helper\Markdown\Enums\MarkdownEnum; // Directory structure: // ./docs/ // ├── index.md // ├── guide/ // │ ├── intro.md // │ └── advanced.md // └── api/ // └── reference.md $result = Markdown::new() // Set source directory containing .md files ->setSourceDirectory(__DIR__ . '/docs/') // Set output directory for HTML files ->addOutputDirectory(__DIR__ . '/public/') // Run directory conversion ->run(MarkdownEnum::TO_HTML_DIRECTORY); if ($result) { echo "Directory conversion successful!"; } // Creates mirrored structure: // ./public/ // ├── index.html // ├── guide/ // │ ├── intro.html // │ └── advanced.html // └── api/ // └── reference.html ``` -------------------------------- ### Supported Formatting Symbols Source: https://github.com/fastvolt/markdown/blob/v0.3.0/README.md A reference of Markdown syntax symbols supported by the parser and their corresponding rendered HTML output. ```APIDOC ## Supported Formatting Symbols | Markdown Syntax | Description | Example Syntax | Rendered Output | | :-------------------------- | :-------------------------- | :--------------------------------------- | :------------------------------------- | | `#` to `######` | Headings (H1–H6) | `## Heading 2` | `

Heading 2

` | | `**text**` or `__text__` | Bold | `**bold**` | `bold` | | `*text*` or `_text_` | Italic | `*italic*` | `italic` | | `~~text~~` | Strikethrough | `~~strike~~` | `strike` | | `` `code` `` | Inline code | `` `echo` `` | `echo` | | ```` ```
code block
``` ```` | Code block | ```` ```php\n echo "Hi"; \n``` ```` | `
...
` | | `-`, `+`, or `*` | Unordered list | `- Item 1`
`* Item 2` | `` | | `1.` `2.` | Ordered list | `1. Item`
`2. Item` | `
  1. Item
` | | `[text](url)` | Hyperlink | `[GitHub](https://github.com)` | `GitHub` | | `> blockquote` | Blockquote | `> This is a quote` | `
This is a quote
` | | `---`, `***`, `___` | Horizontal Rule | `---` | `
` | | `![alt](image.jpg)` | Image | `![Logo](logo.png)` | `Logo` | | `\` | Escape special character | `\*not italic\*` | `*not italic* (as text)` | ``` -------------------------------- ### License Source: https://github.com/fastvolt/markdown/blob/v0.3.0/README.md Information regarding the licensing of the Fastvolt Markdown Parser project. ```APIDOC ## License This project is open-source and licensed under the MIT License by @fastvolt. ``` -------------------------------- ### Requirements Source: https://github.com/fastvolt/markdown/blob/v0.3.0/README.md Specifies the minimum PHP version required to use the Fastvolt Markdown Parser library. ```APIDOC ## Requirements PHP 8.1 or newer. ``` -------------------------------- ### Control XSS Protection with Sanitization Options Source: https://context7.com/fastvolt/markdown/llms.txt Demonstrates how to control HTML sanitization to prevent XSS attacks. By default, sanitization is enabled for security. Disabling it should only be done with trusted HTML content. Malicious scripts are escaped when sanitization is on. ```php use FastVolt\Helper\Markdown; // Sanitization enabled (default, secure) $safe = Markdown::new(sanitize: true); $safe->setContent(''); echo $safe->getHtml(); // Output:

<script>alert("XSS")</script>

// Sanitization disabled (use only with trusted content) $unsafe = Markdown::new(sanitize: false); $unsafe->setContent('
Trusted HTML
'); echo $unsafe->getHtml(); // Output:
Trusted HTML
// Security best practice: Always use sanitize: true unless you completely // control and trust the Markdown source ``` -------------------------------- ### Parse Markdown String to HTML with Fastvolt Source: https://context7.com/fastvolt/markdown/llms.txt Converts a given Markdown string into an HTML string. It initializes the Markdown parser, sets the content, and retrieves the compiled HTML. XSS protection is enabled by default. ```php use FastVolt\Helper\Markdown; // Initialize parser with sanitization enabled (default) $markdown = Markdown::new(); // Set markdown content $markdown->setContent("## Hello, World\n\nThis is **bold** and *italic* text."); // Compile and get raw HTML echo $markdown->getHtml(); // Output: //

Hello, World

//

This is bold and italic text.

``` -------------------------------- ### Fastvolt Markdown Parser `run` Method with `MarkdownEnum::TO_HTML` Source: https://github.com/fastvolt/markdown/blob/v0.3.0/README.md This snippet shows an alternative method to `getHtml()` using the `run` method with the `MarkdownEnum::TO_HTML` enum to convert Markdown content to raw HTML. This provides a unified interface for different conversion types. ```php Markdown::new() ->setContent('# Heading 1') ->run(MarkdownEnum::TO_HTML); ``` -------------------------------- ### Combine Multiple Markdown Sources with Fastvolt Source: https://context7.com/fastvolt/markdown/llms.txt Allows chaining multiple Markdown sources, including files and raw content strings, into a single HTML output. This is useful for constructing pages with distinct sections like headers, footers, and body content. Multiple output directories can be specified to save the compiled HTML to various locations. ```php use FastVolt\Helper\Markdown; // Create header.md: # Blog Title\n## Subtitle // Create footer.md: ---\n© 2024 My Blog $markdown = Markdown::new() // Add header file ->addFile(__DIR__ . '/header.md') // Add body content ->setContent("This is the main **content** of the page.") ->setContent("Another paragraph with a [link](https://example.com).") // Add footer file ->addFile(__DIR__ . '/footer.md') // Set multiple output directories ->addOutputDirectory(__DIR__ . '/public/') ->addOutputDirectory(__DIR__ . '/backup/') // Save to file ->saveToHtmlFile('index.html'); if ($markdown) { echo "Created: ./public/index.html and ./backup/index.html"; } // Both files contain: //

Blog Title

//

Subtitle

//

This is the main content of the page.

//

Another paragraph with a link.

//
//

© 2024 My Blog

``` -------------------------------- ### Batch Process Multiple Markdown Files Source: https://context7.com/fastvolt/markdown/llms.txt Enables processing multiple Markdown files in a single operation using `addMultipleFiles` and `addMultipleOutputDirectories`. The compiled content from all specified Markdown files is saved into a single HTML file at each designated output location. ```php use FastVolt\Helper\Markdown; $files = [ __DIR__ . '/content/intro.md', __DIR__ . '/content/chapter1.md', __DIR__ . '/content/chapter2.md', __DIR__ . '/content/conclusion.md', ]; $markdown = Markdown::new() // Add all files at once ->addMultipleFiles($files) // Set multiple output locations ->addMultipleOutputDirectories([ __DIR__ . '/build/', __DIR__ . '/dist/', __DIR__ . '/backup/', ]) // Save combined output ->saveToHtmlFile('book.html'); // Creates: ./build/book.html, ./dist/book.html, ./backup/book.html // Each file contains all four markdown files compiled in order ``` -------------------------------- ### Convert Markdown Files in a Directory to HTML Source: https://github.com/fastvolt/markdown/blob/v0.3.0/README.md Converts all .md files within a specified source directory to HTML, preserving the folder structure in the output directory. This method utilizes the `MarkdownEnum::TO_HTML_DIRECTORY` enum for execution. It requires setting both the source and output directories before running the conversion. ```php Markdown::new() ->setSourceDirectory(__DIR__ . '/src/my-docs') ->addOutputDirectory(__DIR__ . '/public/docs') ->run(MarkdownEnum::TO_HTML_DIRECTORY); ``` -------------------------------- ### Convert Markdown File to HTML File with Fastvolt PHP Source: https://github.com/fastvolt/markdown/blob/v0.3.0/README.md This snippet illustrates how to convert a Markdown file into a standalone HTML file. It specifies the input Markdown file, an output directory, and uses `saveToHtmlFile` to perform the compilation. ```php $markdown = Markdown::new() // add markdown file ->addFile(__DIR__ . '/blogPost.md') // add output directory ->addOutputDirectory(__DIR__ . '/pages/') // compile as an html file ->saveToHtmlFile(filename: 'index.html'); if ($markdown) { echo "Compiled to ./pages/index.html"; } ``` -------------------------------- ### Parse Inline Markdown with Basic Formatting Source: https://context7.com/fastvolt/markdown/llms.txt Uses the `setInlineContent` method for parsing single-line Markdown with basic formatting like italics and bold. This mode is limited and does not support block elements such as headings or lists. It returns raw HTML. ```php use FastVolt\Helper\Markdown; $markdown = Markdown::new(); // Use setInlineContent for single-line parsing $markdown->setInlineContent('_My name is **John Doe**, welcome!_'); echo $markdown->getHtml(); // Output: // My name is John Doe, welcome! // Note: Inline mode doesn't support headings, lists, or block elements ``` -------------------------------- ### Process Inline Markdown Content Source: https://github.com/fastvolt/markdown/blob/v0.3.0/README.md Converts a single string containing Markdown syntax directly to HTML using the `setInlineContent` and `getHtml` methods. This is useful for dynamically generated Markdown content. Note that not all Markdown symbols are supported with this method. ```php $markdown = Markdown::new(); $markdown->setInlineContent('_My name is **vincent**, the co-author of this blog_'); echo $markdown->getHtml(); ``` -------------------------------- ### Save Markdown to HTML File with Fastvolt Source: https://context7.com/fastvolt/markdown/llms.txt Converts Markdown content and saves the generated HTML directly to a specified file. This method allows setting the Markdown content, defining one or more output directories, and naming the output HTML file. The function returns a boolean indicating success. ```php use FastVolt\Helper\Markdown; $markdown = Markdown::new() // Add markdown content ->setContent("# My Blog Post\n\nThis is the content.") // Set output directory ->addOutputDirectory(__DIR__ . '/public/') // Compile and save as HTML file ->saveToHtmlFile('blog.html'); if ($markdown) { echo "Successfully saved to ./public/blog.html"; } // Creates: ./public/blog.html // Contents:

My Blog Post

This is the content.

``` -------------------------------- ### Sanitize HTML Output for XSS Protection Source: https://github.com/fastvolt/markdown/blob/v0.3.0/README.md Demonstrates how to enable or disable HTML sanitization to prevent XSS attacks. When `sanitize` is true (default), HTML tags are escaped. Setting it to false renders raw HTML, which should only be done if the Markdown source is fully trusted. The `setContent` and `getHtml` methods are used for processing. ```php $markdown = Markdown::new( sanitize: true ); $markdown_unsafe = Markdown::new( sanitize: false ); $content = '

Hello World

'; echo $markdown ->setContent($content) ->getHtml(); echo $markdown_unsafe ->setContent($content) ->getHtml(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.