A simple Slack message text formatting to HTML code converter.
- Issues: github.com/datadesk/slackdown/issues
- Packaging: pypi.python.org/pypi/slackdown
- Testing: travis-ci.org/datadesk/slackdown
- Coverage: coveralls.io/r/datadesk/slackdown
pip install slackdown
Import the library.
import slackdown
Convert a Slack message to HTML using the render function.
>>> slackdown.render('*bold*')
'<p><b>bold</b></p>'
>>> slackdown.render('_italics_')
'<p><i>italics</i></p>'
All inline elements will be rendered inside <p>
tags unless they are already wrapped in another block element like <pre>
,<blockquote>
,<ul>
, or <ol>
tags.
slackdown includes multiple features of Slack messages including all the one's highlighted in Slack's message formatting documentation.
- Text surrounded by _underscores_ will be rendered inside
<i>
tags. - Text surrounded by *asterisks* will be rendered inside
<b>
tags.
- Text surrounded by ~tildes~ will be rendered inside
<s>
tags.
- Lines of text that begin with a bullet(
•
), hyphen(-
), or digit followed by a period(1.
) will be rendered inside<li>
tags. - Bulleted and hyphened lists are rendered inside
<ul>
tags. - Numbered lists are rendered inside
<ol>
tags.- Note that the numbers used in the original text will be ignored and they will instead be rendered using your CSS list style.
- To include multiple lists add an extra line break between them. This line break will not be rendered in the final HTML.
- item 1
- item 2
- item 3
1. item 1
2. item 2
3. item 3
is rendered as
<ul>
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ul>
<ol>
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ol>
- Lines of text that start with a
>
s are rendered inside<blockquote>
tags. - Text blocks that include a line starting with three
>
s will render the message from that point on inside<blockquote>
tags. Note: the Slack API returns all>
as>
because angle brackets are used for links in Slack text formatting See the documentation for more.
> A blockquote line
>>> Multiple lines
of a
blockquote
is rendered as
<blockquote>A blockquote line</blockquote>
<blockquote>
Multiple lines </br>
of a </br>
blockquote
</blockquote>
- Text surrounded in `backticks` will be rendered inside
<code>
tags. - Text surrounded by ```three backticks``` will be rendered inside
<pre>
tags.
- Text surrounded by < angle brackets > will be rendered inside
<a>
tags withtarget="blank"
and their contents as thehref
.
- Line breaks rendered inside
<p>
tags will close the tag and start a new paragraph. Line breaks in other block elements will be rendered as<br />
tags.
Multiple
lines of
paragraph text
` ` `
Multiple
lines of
pre text
` ` `
is rendered as
<p>Multiple</p>
<p>lines of</p>
<p>paragraph text</p>
<p></p>
<pre>
Multiple <br />
lines of <br />
pre text
</pre>
- Since extra whitespace is stripped in HTML, any extra space is rendered using  . Every two space characters are rendered as a space character and a  . This minimizes added characters while keeping the same amount of rendered whitespace as the original text.