GithubHelp home page GithubHelp logo

crrice / slackdown Goto Github PK

View Code? Open in Web Editor NEW

This project forked from datadesk/slackdown

0.0 1.0 0.0 20 KB

A simple Slack message text formatting to HTML code converter.

License: MIT License

Makefile 0.78% Python 99.22%

slackdown's Introduction

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.

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

slackdown's People

Contributors

brizandrew avatar palewire avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.