RelayUI

Markdown

RUI::Markdown is a namespace containing components that aid in rendering markdown. There are sane defaults provided for rendered markdown elements like links and lists. In fact, this entire page is just one big markdown block.

RUI's markdown components use redcarpet for rendering markdown and rouge for syntax highlighting.

Parameters

RUI::Markdown::[Variant].new { &block }

&block (block) (required)
→ The content to be displayed inside the markdown block, usually as a non-indented STRING heredoc.

Variants

There are two variants of markdown components: Safe and Unsafe.

Safe Markdown

RUI::Markdown::Safe should be considered the "default" markdown component and can be used for any markdown content, including user-generated content. HTML elements will be escaped to prevent against any XSS concerns. The component accepts a block containing a string, often as a heredoc. The contents of the string will be rendered as markdown.

Important: When using a STRING heredoc as in the example, be sure that the string is NOT indented. Otherwise, the markdown will not render correctly.

Example:

  render RUI::Markdown::Safe.new do
<<-STRING
Here is some cool markdown from [LogicRelay](https://www.logicrelay.com).

- Here is a list item
- Here's another list item
STRING
  end

This will be rendered as:

Here is some cool markdown from LogicRelay.

  • Here is a list item
  • Here's another list item

Unsafe Markdown

RUI::Markdown::Unsafe is for content that is trusted, eg: from a personal blog or hardcoded content. HTML elements will not be escaped in unsafe markdown, which preserves the behavior of code blocks. The component again accepts a block containing a string, often as a heredoc.

Here is an example of a code block:

  render RUI::Markdown::Unsafe.new do
<<-STRING
```ruby
def some_method
  puts "Hello, world!"
end
``` ‎
STRING
  end