All Projects → piotrmurach → Tty Markdown

piotrmurach / Tty Markdown

Licence: mit
Convert a markdown document or text into a terminal friendly output.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Tty Markdown

Galacritty
WIP GTK terminal emulator based on Alacritty
Stars: ✭ 136 (-50.55%)
Mutual labels:  cli, terminal, console, tty
Mandown
man-page inspired Markdown viewer
Stars: ✭ 173 (-37.09%)
Mutual labels:  cli, terminal, console, markdown
Laravel Zero
A PHP framework for console artisans
Stars: ✭ 2,821 (+925.82%)
Mutual labels:  console-application, cli, terminal, console
Zui
⬢ Zsh User Interface library – CGI+DHTML-like rapid application development with Zsh
Stars: ✭ 95 (-65.45%)
Mutual labels:  console-application, terminal, console, tty
Tty Font
Terminal fonts
Stars: ✭ 44 (-84%)
Mutual labels:  terminal, console, tty, rubygem
Cointop
A fast and lightweight interactive terminal based UI application for tracking cryptocurrencies 🚀
Stars: ✭ 2,912 (+958.91%)
Mutual labels:  cli, terminal, console
Tslide
Terminal SlideDeck, supporting markdown.
Stars: ✭ 198 (-28%)
Mutual labels:  cli, terminal, markdown
Saldl
A lightweight well-featured CLI downloader optimized for speed and early preview.
Stars: ✭ 203 (-26.18%)
Mutual labels:  cli, terminal, tty
Php Console Spinner
Colorful highly configurable spinner for php cli applications (suitable for async apps)
Stars: ✭ 225 (-18.18%)
Mutual labels:  cli, terminal, console
Ervy
Bring charts to terminal.
Stars: ✭ 1,530 (+456.36%)
Mutual labels:  cli, terminal, console
.tmux
🇫🇷 Oh my tmux! My self-contained, pretty & versatile tmux configuration made with ❤️
Stars: ✭ 15,594 (+5570.55%)
Mutual labels:  cli, terminal, console
Jquery.terminal
jQuery Terminal Emulator - JavaScript library for creating web-based terminals with custom commands
Stars: ✭ 2,623 (+853.82%)
Mutual labels:  cli, terminal, console
Php Console
🖥 PHP CLI application library, provide console argument parse, console controller/command run, color style, user interactive, format information show and more. 功能全面的PHP命令行应用库。提供控制台参数解析, 命令运行,颜色风格输出, 用户信息交互, 特殊格式信息显示
Stars: ✭ 310 (+12.73%)
Mutual labels:  console-application, cli, console
Htop
htop is an interactive text-mode process viewer for Unix systems. It aims to be a better 'top'.
Stars: ✭ 5,626 (+1945.82%)
Mutual labels:  console-application, terminal, console
Ascii
👾 ASCII Roulette :: ascii art video chat on the cli
Stars: ✭ 202 (-26.55%)
Mutual labels:  cli, terminal, console
Nnn
n³ The unorthodox terminal file manager
Stars: ✭ 13,138 (+4677.45%)
Mutual labels:  cli, terminal, console
Go Termd
Package termd provides terminal markdown rendering, with code block syntax highlighting support.
Stars: ✭ 223 (-18.91%)
Mutual labels:  cli, terminal, markdown
Word Wrap
Wrap words to a specified length.
Stars: ✭ 107 (-61.09%)
Mutual labels:  cli, terminal, console
Box Cli Maker
Make Highly Customized Boxes for your CLI
Stars: ✭ 115 (-58.18%)
Mutual labels:  cli, terminal, console
S Tui
Terminal-based CPU stress and monitoring utility
Stars: ✭ 2,825 (+927.27%)
Mutual labels:  cli, terminal, console
TTY Toolkit logo

TTY::Markdown Gitter

Gem Version Actions CI Build status Maintainability Coverage Status Inline docs

Convert a markdown document or text into a terminal friendly output.

TTY::Markdown provides independent markdown processing component for TTY toolkit.

Installation

Add this line to your application's Gemfile:

gem 'tty-markdown'

And then execute:

$ bundle

Or install it yourself as:

$ gem install tty-markdown

Contents

1. Usage

Using parse method, you can transform a markdown string into a terminal formatted content:

parsed = TTY::Markdown.parse("# Hello")
puts parsed
# => "\e[36;1mHello\e[0m\n"

The parse_file allows you to transform a markdown document into a terminal formatted output:

parsed = TTY::Markdown.parse_file('example.md')
puts parsed

1.1 Header

Parsing the following markdown headers:

TTY::Markdown
=============

**tty-markdown** converts markdown document into a terminal friendly output.

## Examples

### Nested list items

The terminal output looks like this:

Headers example

1.2 List

Both numbered and unordered lists are supported. Given a markdown:

- Item 1
  - Item 2
  - Item 3
    - Item 4
- Item 5

The parsed output looks like this:

Unordered list example

1.3 Definition List

Given a definition list:

Item 1
: This is the description for Item 1

Item 2
: This is the description for Item 2
: This is another description for Item 2

The parsed output looks like this:

Definition list example

1.4 Link

A markdown link:

[An inline-style link](https://ttytoolkit.org)

[An inline-style link with title](https://ttytoolkit.org "TTY Toolkit Homepage")

The link text will be rendered with the link next to it:

Link example

1.5 Blockquote

Given a markdown quote:

> Blockquotes are very handy in email to emulate reply text.
> This line is part of the same quote.
> *Oh*, you can put **Markdown** into a blockquote.

The rendered output looks like this:

Blockquote example

1.6 Code and Syntax Highlighting

The parser can highlight syntax of many programming languages.

Given a markdown codeblock with a language specification:

```ruby
class Greeter
  def hello(name)
    puts "Hello #{name}"
  end
end
```

The terminal output will look like this:

Code highlighting example

1.7 Table

You can transform tables which understand the markdown alignment.

For example, given the following table:

| Tables   |      Are      |  Cool |
|----------|:-------------:|------:|
| col 1 is |  left-aligned | $1600 |
| col 2 is |    centered   |   $12 |
| col 3 is | right-aligned |    $1 |

Then the terminal output will look like this:

Table example

1.8 Horizontal Rule

You can specify a horizontal rule in markdown:

***

and then transform it:

parsed = TTY::Markdown.parse(markdown_string)

puts parsed will output:

Horizontal rule example

1.9 Footnotes

You can create footnote references:

It is not down on any map[^foo]; true places[^bar] never are.

[^foo]: A diagrammatic representation of an area of land or sea.
[^bar]: A particular position, point, or area in space; a location.

All footnotes will be displayed with a sequential number and rendered in the terminal like this:

Footnotes example

2. Options

2.1 :mode

By default the 256 color scheme is used to render code block elements.

You can change this by specifying maximum number of colors to be 16 ANSI colors:

TTY::Markdown.pasre(markdown_string, mode: 16)

This feature may be handy when working in terminals with limited color support.

By default, TTY::Markdown detects your terminal color mode and adjusts output automatically.

2.2 :theme

A hash of styles that allows to customize specific elements of the markdown text. By default the following styles are used:

THEME = {
  em: :yellow,
  header: [:cyan, :bold],
  hr: :yellow,
  link: [:yellow, :underline],
  list: :yellow,
  strong: [:yellow, :bold],
  table: :yellow,
  quote: :yellow,
  image: :bright_black,
  note: :yellow,
  comment: :bright_black
}

In order to provide new styles use :theme key:

TTY::Markdown.parse(markdown_string, theme: { ... })

2.3 :width

You can easily control the maximum width of the output by using the :width key:

TTY::Markdown.parse(markdown_string, width: 80)

By default the terminal screen width is used.

2.4 :symbols

By default formatting will include various Unicode symbols. You can switch to an included ASCII set and/or override individually with the :symbols key:

TTY::Markdown.parse(markdown_string, symbols: :ascii)
TTY::Markdown.parse(markdown_string, symbols: {base: :ascii})
TTY::Markdown.parse(markdown_string, symbols: {override: {bullet: "x"}})

2.5 :indent

By default any content apart from the main h1 header is indented with 2 spaces. Use :indent to provide custom indent or no indent at all:

TTY::Markdown.parse(markdown_string, indent: 0)

2.6 :color

You can control when to apply coloring to various document elements.

Valid values are :never, :always or :auto. By default :auto is used which auto detects if coloring can be applied.

For example, to always color content regardless of terminal support do:

TTY::Markdown.parse(markdown_string, color: :always)

3. Command line tool

You can install tty-markdown-cli to use tty-markdown executable in terminal:

$ tty-markdown README.md

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/piotrmurach/tty-markdown. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the TTY::Markdown project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Copyright

Copyright (c) 2018 Piotr Murach. See LICENSE for further details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].