```
--------------------------------
### Error-handling / safety consideration example
Source: https://github.com/jeffersongoncalves/laravel-markdown/blob/main/_autodocs/api-reference/markdown-renderer.md
Shows try-catch around rendering untrusted input with default config, noting that exceptions propagate from underlying libraries.
```php
use JeffersonGoncalves\Markdown\MarkdownRenderer;
try {
$html = (new MarkdownRenderer)->render($userInput, headingPermalinks: true);
// default config => raw HTML escaped, safe to echo
} catch (\Throwable $e) {
// no package-specific exception; any failure bubbles up from the
// underlying CommonMark/tempest-highlight stack
report($e);
}
```
--------------------------------
### Package structure tree
Source: https://github.com/jeffersongoncalves/laravel-markdown/blob/main/resources/boost/skills/markdown-development/SKILL.md
Shows the package's source and config file layout, including the service provider, static render engine, renderer wrapper, facade, and config file.
```text
src/
MarkdownServiceProvider.php # Registers the package + config file + @markdown Blade directive
Markdown.php # Static render() engine (memoized converters)
MarkdownRenderer.php # Container-resolvable wrapper behind the facade
Facades/Markdown.php # `Markdown` facade
config/
markdown.php # html_input, allow_unsafe_links, heading_permalink
```
--------------------------------
### Publish markdown config
Source: https://github.com/jeffersongoncalves/laravel-markdown/blob/main/resources/boost/skills/markdown-development/SKILL.md
Publish the package configuration file using the markdown-config tag. The config file contains html_input, allow_unsafe_links, and heading_permalink settings.
```bash
php artisan vendor:publish --tag="markdown-config"
```
--------------------------------
### Flush memoized converters after runtime config change
Source: https://github.com/jeffersongoncalves/laravel-markdown/blob/main/_autodocs/configuration.md
Call Markdown::flush() after changing markdown.* config at runtime to drop memoized converters and the highlighter, so the next render uses the new config. The example toggles html_input to 'allow' and then renders a
tag, which is preserved.
```php
config()->set('markdown.html_input', 'allow');
Markdown::flush();
$html = Markdown::render('
hi
'); // now preserved
```
--------------------------------
### Basic @markdown usage
Source: https://github.com/jeffersongoncalves/laravel-markdown/blob/main/_autodocs/api-reference/blade-directive.md
Echoes rendered HTML. The first example shows inline Markdown; the second uses a variable. Comments show the expected output.
```blade
@markdown('# Hello **world**')
{{-- echoes
Hello world
---}}
@markdown($articleBody)
{{-- echoes the rendered HTML of $articleBody ---}}
```
--------------------------------
### Get rendered HTML string directly
Source: https://github.com/jeffersongoncalves/laravel-markdown/blob/main/_autodocs/api-reference/blade-directive.md
Use the static PHP class when you need the string instead of echoing. The directive itself only echoes output.
```php
$html = \JeffersonGoncalves\Markdown\Markdown::render($source);
```
--------------------------------
### Pest tests for Markdown rendering features
Source: https://github.com/jeffersongoncalves/laravel-markdown/blob/main/resources/boost/skills/markdown-development/SKILL.md
Pest tests verifying GFM table rendering, fenced code highlighting, and heading permalinks. Uses the Markdown::render method with optional headingPermalinks parameter.
```php
use JeffersonGoncalves\Markdown\Markdown;
it('renders a GFM table', function () {
$html = Markdown::render("| A | B |\n| - | - |\n| 1 | 2 |");
expect($html)->toContain('
')->toContain('| 1 | ');
});
it('highlights fenced code blocks', function () {
$html = Markdown::render("```php\necho 'hi';\n```");
expect($html)->toMatch('/class="hl-[a-z]+"/');
});
it('adds md-anchor anchors only when enabled', function () {
expect(Markdown::render('# H', headingPermalinks: true))->toContain('md-anchor');
expect(Markdown::render('# H'))->not->toContain('md-anchor');
});
```
--------------------------------
### Markdown::render() public API
Source: https://github.com/jeffersongoncalves/laravel-markdown/blob/main/resources/boost/skills/markdown-development/SKILL.md
Static render method signature. Accepts markdown string, optional heading permalinks flag, and per-call options overriding config keys. Returns HTML string. Converters are memoized per (permalinks flag, options) combination.
```php
JeffersonGoncalves\Markdown\Markdown::render(
string $markdown,
bool $headingPermalinks = false,
array $options = [], // per-call overrides of the config keys
): string
```
--------------------------------
### Default markdown.php configuration for html_input, allow_unsafe_links, and heading_permalink
Source: https://github.com/jeffersongoncalves/laravel-markdown/blob/main/resources/boost/skills/markdown-development/SKILL.md
Configuration array read inside render() with hardcoded defaults as fallbacks. Each key can be overridden per call via $options. The heading_permalink config is only applied when render(..., headingPermalinks: true) is called. html_input defaults to 'escape' for safe-by-default rendering of untrusted input.
```php
'html_input' => 'escape', // 'allow' | 'escape' | 'strip'
'allow_unsafe_links' => false,
'heading_permalink' => [
'symbol' => '#',
'html_class' => 'md-anchor',
'id_prefix' => '', // '' = bare GitHub-style ids (id="{slug}")
],
```
--------------------------------
### Run Tests with Composer
Source: https://github.com/jeffersongoncalves/laravel-markdown/blob/main/README.md
Execute the test suite using Composer. Run this command from the project root to run all tests.
```bash
composer test
```
--------------------------------
### Mocking the facade in application code
Source: https://github.com/jeffersongoncalves/laravel-markdown/blob/main/_autodocs/api-reference/markdown-facade.md
Shows how to mock the facade's render method in tests using shouldReceive, with expected arguments and return value.
```php
use JeffersonGoncalves\Markdown\Facades\Markdown;
// Swap the underlying renderer ahead of a controller test:
Markdown::shouldReceive('render')
->once()
->with('# Hello', false, [])
->andReturn('Hello
');
```
--------------------------------
### Facade usage with heading permalinks and per-call options
Source: https://github.com/jeffersongoncalves/laravel-markdown/blob/main/_autodocs/api-reference/markdown-facade.md
Shows how to enable heading permalinks and pass per-call configuration options like 'html_input'.
```php
use JeffersonGoncalves\Markdown\Facades\Markdown;
$html = Markdown::render($readme, headingPermalinks: true);
$html = Markdown::render($trustedMarkdown, options: ['html_input' => 'allow']);
```
--------------------------------
### Basic Markdown Rendering
Source: https://github.com/jeffersongoncalves/laravel-markdown/blob/main/README.md
Render GitHub Flavored Markdown to HTML using the Markdown facade. Optionally enable heading permalink anchors by passing headingPermalinks: true.
```php
use JeffersonGoncalves\Markdown\Markdown;
// Render GitHub Flavored Markdown to HTML
$html = Markdown::render('# Hello **world**');
// Enable heading permalink anchors (adds to each heading)
$html = Markdown::render($readme, headingPermalinks: true);
```
--------------------------------
### Import the Markdown facade
Source: https://github.com/jeffersongoncalves/laravel-markdown/blob/main/_autodocs/api-reference/markdown-facade.md
Import the facade class for static access to the rendering API.
```php
use JeffersonGoncalves\Markdown\Facades\Markdown;
```
--------------------------------
### configurePackage method signature
Source: https://github.com/jeffersongoncalves/laravel-markdown/blob/main/_autodocs/api-reference/markdown-service-provider.md
Declares the configurePackage method that configures the package via the provided Package instance.
```php
public function configurePackage(Package $package): void
```
--------------------------------
### Configure HTML Input to Allow Raw HTML
Source: https://github.com/jeffersongoncalves/laravel-markdown/blob/main/README.md
Set 'html_input' to 'allow' in config/markdown.php to preserve raw HTML in markdown source. Only use for trusted content; output becomes unsafe for untrusted input and must be sanitized.
```php
// config/markdown.php
'html_input' => 'allow',
```
--------------------------------
### Three usage patterns for MarkdownRenderer
Source: https://github.com/jeffersongoncalves/laravel-markdown/blob/main/_autodocs/api-reference/markdown-renderer.md
Shows direct instantiation, container resolution, and facade usage to reach the same rendering logic.
```php
// 1. Direct instantiation
$renderer = new MarkdownRenderer;
$html = $renderer->render('# Hello');
// 2. Through the container
$renderer = app(MarkdownRenderer::class);
$html = $renderer->render('# Hello');
// 3. Through the facade (see markdown-facade.md)
use JeffersonGoncalves\Markdown\Facades\Markdown;
$html = Markdown::render('# Hello');
```
--------------------------------
### Facade Markdown::render() with $options
Source: https://github.com/jeffersongoncalves/laravel-markdown/blob/main/_autodocs/configuration.md
Renders Markdown to HTML via the facade, with the same per-call options as the static Markdown::render().
```APIDOC
## [POST] Facade Markdown::render()
### Description
Renders Markdown content to HTML using the facade. Accepts an optional $options array to override configuration for this call only.
### Method
POST (conceptual)
### Endpoint
Markdown::render($markdown, $options = [])
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
- **markdown** (string) - Required - The Markdown content to render.
- **options** (array) - Optional - Per-call options. Keys:
- `html_input` (string) - Optional - 'escape', 'allow', or 'strip'. Overrides config('markdown.html_input').
- `allow_unsafe_links` (bool) - Optional - Overrides config('markdown.allow_unsafe_links').
- `heading_permalink` (array) - Optional - Keys: `symbol`, `html_class`, `id_prefix`. Only used when headingPermalinks is true.
### Request Example
```php
use JeffersonGoncalves\Markdown\Facades\Markdown;
$html = Markdown::render($markdown, options: ['html_input' => 'allow']);
```
### Response
#### Success Response (200)
- **html** (string) - The rendered HTML.
#### Response Example
```html
hi
```
```
--------------------------------
### Published Config File Contents
Source: https://github.com/jeffersongoncalves/laravel-markdown/blob/main/README.md
Default configuration for HTML input handling, unsafe links, and heading permalinks. The id_prefix defaults to an empty string to match GitHub's heading id convention.
```php
return [
'html_input' => 'escape',
'allow_unsafe_links' => false,
'heading_permalink' => [
'symbol' => '#',
'html_class' => 'md-anchor',
'id_prefix' => '',
],
];
```
--------------------------------
### Basic usage of Markdown::render()
Source: https://github.com/jeffersongoncalves/laravel-markdown/blob/main/_autodocs/api-reference/markdown.md
Renders a simple Markdown string to HTML. The output contains the expected heading and strong tags.
```php
use JeffersonGoncalves\Markdown\Markdown;
$html = Markdown::render('# Hello **world**');
// $html contains: Hello world
```
--------------------------------
### Render untrusted user input with default config
Source: https://github.com/jeffersongoncalves/laravel-markdown/blob/main/_autodocs/api-reference/markdown.md
Shows that with default configuration, raw HTML like