Skip to content
A simple Slack message text formatting to HTML code converter.
Python Makefile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

README.md

slackdown

A simple Slack message text formatting to HTML code converter.

Build Status PyPI version Coverage Status

Installation

pip install slackdown

Basic usage

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.

Features

slackdown includes multiple features of Slack messages including all the one's highlighted in Slack's message formatting documentation.

Emphasis

  • Text surrounded by _underscores_ will be rendered inside <i> tags.
  • Text surrounded by *asterisks* will be rendered inside <b> tags.

Strikethrough

  • Text surrounded by ~tildes~ will be rendered inside <s> tags.

Lists

  • 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>

Blockquotes

  • Lines of text that start with a &gt;s are rendered inside <blockquote> tags.
  • Text blocks that include a line starting with three &gt;s will render the message from that point on inside <blockquote> tags. Note: the Slack API returns all > as &gt; 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>

Code Blocks

  • Text surrounded in `backticks` will be rendered inside <code> tags.
  • Text surrounded by ```three backticks``` will be rendered inside <pre> tags.

Hyperlinks

  • Text surrounded by < angle brackets > will be rendered inside <a> tags with target="blank" and their contents as the href.

Line Breaks

  • 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>

Spaces

  • Since extra whitespace is stripped in HTML, any extra space is rendered using &nbsp. Every two space characters are rendered as a space character and a &nbsp. This minimizes added characters while keeping the same amount of rendered whitespace as the original text.
You can’t perform that action at this time.