I am looking for something simple like triple backticks, but that still allows other markdown syntax inside.
This is not the case for triple backticks, since it is used for code blocks:
**NOTE:**
Find the docs [here](http://example.com/).
Everything inside is taken literally, so it is not possible to use other markdown features inside, like links or bold text ...
Is there any syntax or feature in markdown that enables such notification boxes?
GitHub Flavored Markdown, often shortened as GFM, is the dialect of Markdown that is currently supported for user content on GitHub.com and GitHub Enterprise. This formal specification, based on the CommonMark Spec, defines the syntax and semantics of this dialect. GFM is a strict superset of CommonMark.
Turn on Markdown Formatting for notes. For this, go to Tools > Options > Appearance and check "Use Markdown format in notes".
To highlight code, write the name of the language the code is written in after the initial triple backticks.
You can create bullet points in an unordered list in markdown format using an asterisk “*” at the beginning of the line. Links can be inserted anywhere in the readme.md. The structure is very similar to an image file, but without the exclamation mark at the beginning of the line.
As Waylan mentions in his answer, Github strips script and style tags from the markdown before displaying it. This means the only possibilities for notification boxes that will render on Github are those provided by native markdown or html.
After some searching and experimenting, I discovered it is possible to (ab)use the
tables syntax,
and combine it with Github emoji markdown.
For example:
Boxes from a single cell table:
| :exclamation: This is very important |
|-----------------------------------------|
| :zap: Ignore at your own risk! |
|-----------------------------------------|
Boxes from a single row table with 2 cells:
| :memo: | Take note of this |
|---------------|:------------------------|
| :point_up: | Remember to not forget! |
|---------------|:------------------------|
Boxes from a 2 row table:
| :warning: WARNING |
|:---------------------------|
| I should warn you ... |
| :boom: DANGER |
|:---------------------------|
| Will explode when clicked! |
Note that markdown tables do not allow newlines, so you should use <br />
tags if you need multiple lines inside the box. In this case it might be simpler to directly use the html <table>
tag, since it doesn't have this newline restriction. It also allows getting rid of the bold styling of the table header <thead>
by replacing its <th>
tags with <td>
tags:
<table>
<thead>
<tr>
<td align="left">
:information_source: Information
</td>
</tr>
</thead>
<tbody>
<tr>
<td>
<ul>
<li>Tis not true.</li>
<li>I won't explode.</li>
</ul>
</td>
</tr>
</tbody>
</table>
Is there any syntax or feature in markdown that enables such notification boxes?
Yes, you can use raw HTML. As the original rules explain:
HTML is a publishing format; Markdown is a writing format. Thus, Markdown’s formatting syntax only addresses issues that can be conveyed in plain text.
Therefore, styling a warning box around some text is out-of-scope for Markdown as that is a publishing concern, not a writing concern. However, as the ruled continue:
For any markup that is not covered by Markdown’s syntax, you simply use HTML itself.
An as you are using Github Flavored Markdown, you get the added benefit that when formatted properly, you can still have Markdown processed within the block level raw HTML tags (so long as the parser you are using is compliant with the spec). As the spec explains, Markdown is processed within a raw HTML block after the first blank line. So simply include a blank line after the opening raw HTML tag and you won't have any issues.
<div class="warning">
**NOTE:**
Find the docs [here](http://example.com/).
</div>
Of course, you will also need to define what your warning block looks like. In the above example, I assigned the warning
class to the wrapping <div>
tag. Some CSS would also need to be defined within the document (in a <style>
tag) to style any <div>
which has the warning
class.
Alternatively, if you only have one warning box in your document, you could define the styles in an inline style
attribute: <div style="...">
(replacing ...
with the actual CSS rules).
A word of caution though. If you plan to have your document rendered and hosted on github.com, this will not work. While GitHub's Markdown parser will work as described above, GitHub also does some postprocessing for security reasons (as documented at github/markup). The sanitation filter they use will strip out all styles (inline or not). In that case, there is no option available. The same applies here on StackOverflow.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With