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:
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:
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:
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.parse(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:
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:
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 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.
请发表评论