Skip to content

Advanced Markdown

Introduction

Since HydePHP makes heavy use of Markdown, there are some extra features and helpers created just for Hyde to make using Markdown even easier and more powerful!

Using Blade in Markdown

A special feature in Hyde, is that you can use Laravel Blade in Markdown files!

To use Blade in your Markdown files, simply use the Blade shortcode directive, followed by your desired Blade string.

Standard syntax

1[Blade]: {{ "Hello World!" }} // Will render: 'Hello World!'

Blade includes

Only single-line shortcode directives are supported. If you need to use multi-line Blade code, use an @include directive to render a more complex Blade template. You can pass data to includes by specifying an array to the second argument.

1[Blade]: @include("hello-world")
2[Blade]: @include("hello", ["name" => "World"])

Enabling Blade-supported Markdown

The feature is disabled by default since it allows arbitrary PHP to run, which could be a security risk, depending on your setup. However, if your Markdown is trusted, and you know it's safe, you can enable it in the config/markdown.php file.

Filepath: config/markdown.php
1'enable_blade' => true,

Limitations

All shortcodes must be the first word on a new line, and only single-line shortcodes are supported.

Coloured Blockquotes

The HydePHP Markdown converter also supports some extra directives and features. One of them being four different coloured blockquotes. Simply append the desired colour after the initial > character.

1‎> Normal Blockquote
2‎>info Info Blockquote
3‎>warning Warning Blockquote
4‎>danger Danger Blockquote
5‎>success Success Blockquote

Normal Blockquote

Info Blockquote

Warning Blockquote

Danger Blockquote

Success Blockquote

Customizations

You can easily customize these styles too by adding and editing the following in your resources/app.css file, and then recompiling your site styles. The code examples here use the Tailwind @apply directives, but you could also use border-color: something; just as well.

Filepath: resources/app.css
1/* Markdown Features */
2 
3.prose blockquote.info {
4 @apply border-blue-500;
5}
6 
7.prose blockquote.success {
8 @apply border-green-500;
9}
10 
11.prose blockquote.warning {
12 @apply border-amber-500;
13}
14 
15.prose blockquote.danger {
16 @apply border-red-600;
17}

Markdown usage

The coloured blockquotes also support inline Markdown, just like normal blockquotes.

1‎>info Formatting is **supported**!

Limitations

Note that these currently do not support multi-line blockquotes.

Code Block Filepaths

When browsing these documentation pages you may have noticed a label in the top right corner of code blocks specifying the file path. These are also created by using a custom Hyde feature that turns code comments into automatic code blocks.

Usage

Simply add a code comment with the path in the first line of a fenced code block like so:

Filepath: _docs/advanced-markdown.md
1```php
2// Filepath: hello-world.php
3 
4echo 'Hello World!';
5```

Which becomes:

Filepath: hello-world.php
1echo 'Hello World!';

Alternative syntax

The syntax is rather forgiving, by design, and supports using both // and # for comments. The colon is also optional, and the 'filepath' string is case-insensitive. So the following is also perfectly valid:

1```js
2// filepath hello.js
3console.log('Hello World!');
4```

If you have a newline after the filepath, like in the first example, it will be removed so your code stays readable.

Advanced usage

If you have enabled HTML in Markdown by setting the allow_html option to true in your config/markdown.php file, anything within the path label will be rendered as HTML. This means you can add links, or even images to the label.

Filepath: View file on Github
1```markdown
2‎// Filepath: <a href="https://github.com">View file on Github</a>
3```

Limitations

The filepaths are hidden on mobile devices using CSS to prevent them from overlapping with the code block.

Configuration

Full configuration reference

All Markdown-related configuration options are in the config/markdown.php file. You can find the full reference on the Customization page.

Raw HTML Tags

To convert Markdown, HydePHP uses the GitHub Flavored Markdown extension, which strips out potentially unsafe HTML. If you want to allow all arbitrary HTML tags, and understand the risks involved, you can enable all HTML tags by setting the allow_html option to true in your config/markdown.php file.

Filepath: config/markdown.php
1'allow_html' => true,

This will add and configure the DisallowedRawHtml CommonMark extension so that no HTML tags are stripped out.

Tailwind Typography Prose Classes

HydePHP uses the Tailwind Typography to style rendered Markdown. We do this by adding the .prose CSS class to the HTML elements containing the rendered Markdown, using the built-in Blade components.

You can easily edit these classes, for example if you want to customize the prose colours, in the config/markdown.php file.

Filepath: config/markdown.php
1'prose_classes' => 'prose dark:prose-invert',
2'prose_classes' => 'prose dark:prose-invert prose-img:inline',

Please note that if you add any new classes, you may need to recompile your CSS file.