tty-markdown 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +22 -0
- data/CHANGELOG.md +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +21 -0
- data/README.md +225 -0
- data/Rakefile +8 -0
- data/appveyor.yml +21 -0
- data/assets/headers.png +0 -0
- data/assets/list.png +0 -0
- data/assets/quote.png +0 -0
- data/assets/syntax_highlight.png +0 -0
- data/assets/table.png +0 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/examples/example.md +49 -0
- data/examples/marked.rb +6 -0
- data/lib/tty-markdown.rb +1 -0
- data/lib/tty/markdown.rb +92 -0
- data/lib/tty/markdown/parser.rb +353 -0
- data/lib/tty/markdown/syntax_highlighter.rb +65 -0
- data/lib/tty/markdown/version.rb +5 -0
- data/tasks/console.rake +11 -0
- data/tasks/coverage.rake +11 -0
- data/tasks/spec.rake +29 -0
- data/tty-markdown.gemspec +33 -0
- metadata +197 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 372c2535e3de00b3681eded48af2d9fef7b1c99d
|
4
|
+
data.tar.gz: 75ab67563718dc7d68d17b6738b699ac59e3cee7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a104de05f2d5cbfc3384663d2272d1b16bbd9c8bd2692548be8efd6174651ceb7af9616903b9e2b6f322c7bff6f34672ec9673a46513d5ba38cf2fc7e195d578
|
7
|
+
data.tar.gz: 696a9c610c87f79422b4b4aee4a0f4648d12396a7b94f3109708217a388c95a086fa7bd992553d026a9b985065c41a1c6116e7e6bd5d357fd4b5bc96b76f705a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
---
|
2
|
+
language: ruby
|
3
|
+
sudo: false
|
4
|
+
cache: bundler
|
5
|
+
before_install: "gem update bundler"
|
6
|
+
script: "bundle exec rake ci"
|
7
|
+
rvm:
|
8
|
+
- 2.0.0
|
9
|
+
- 2.1.10
|
10
|
+
- 2.2.8
|
11
|
+
- 2.3.6
|
12
|
+
- 2.4.3
|
13
|
+
- ruby-head
|
14
|
+
- jruby-9000
|
15
|
+
- jruby-head
|
16
|
+
matrix:
|
17
|
+
allow_failures:
|
18
|
+
- rvm: ruby-head
|
19
|
+
- rvm: jruby-head
|
20
|
+
fast_finish: true
|
21
|
+
branches:
|
22
|
+
only: master
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at [email]. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
4
|
+
|
5
|
+
gemspec
|
6
|
+
|
7
|
+
group :test do
|
8
|
+
gem 'benchmark-ips', '~> 2.7.2'
|
9
|
+
gem 'simplecov', '~> 0.14.1'
|
10
|
+
gem 'coveralls', '~> 0.8.21'
|
11
|
+
end
|
12
|
+
|
13
|
+
group :metrics do
|
14
|
+
gem 'yard', '~> 0.9.12'
|
15
|
+
gem 'yardstick', '~> 0.9.9'
|
16
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Piotr Murach
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,225 @@
|
|
1
|
+
# TTY::Markdown [![Gitter](https://badges.gitter.im/Join%20Chat.svg)][gitter]
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/tty-markdown.svg)][gem]
|
4
|
+
[![Build Status](https://secure.travis-ci.org/piotrmurach/tty-markdown.svg?branch=master)][travis]
|
5
|
+
[![Build status](https://ci.appveyor.com/api/projects/status/k4vub4koct329ggd?svg=true)][appveyor]
|
6
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/1656060107c73ac42c2b/maintainability)][codeclimate]
|
7
|
+
[![Coverage Status](https://coveralls.io/repos/github/piotrmurach/tty-markdown/badge.svg)][coverage]
|
8
|
+
[![Inline docs](http://inch-ci.org/github/piotrmurach/tty-markdown.svg?branch=master)][inchpages]
|
9
|
+
|
10
|
+
[gitter]: https://gitter.im/piotrmurach/tty
|
11
|
+
[gem]: http://badge.fury.io/rb/tty-markdown
|
12
|
+
[travis]: http://travis-ci.org/piotrmurach/tty-markdown
|
13
|
+
[appveyor]: https://ci.appveyor.com/project/piotrmurach/tty-markdown
|
14
|
+
[codeclimate]: https://codeclimate.com/github/piotrmurach/tty-markdown/maintainability
|
15
|
+
[coverage]: https://coveralls.io/github/piotrmurach/tty-markdown
|
16
|
+
[inchpages]: http://inch-ci.org/github/piotrmurach/tty-markdown
|
17
|
+
|
18
|
+
> Convert a markdown documet or text into a terminal friendly output.
|
19
|
+
|
20
|
+
|
21
|
+
**TTY::Markdown** provides independent markdown processing component for [TTY](https://github.com/piotrmurach/tty) toolkit.
|
22
|
+
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
Add this line to your application's Gemfile:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
gem 'tty-markdown'
|
29
|
+
```
|
30
|
+
|
31
|
+
And then execute:
|
32
|
+
|
33
|
+
$ bundle
|
34
|
+
|
35
|
+
Or install it yourself as:
|
36
|
+
|
37
|
+
$ gem install tty-markdown
|
38
|
+
|
39
|
+
## Contents
|
40
|
+
|
41
|
+
* [1. Usage](#1-usage)
|
42
|
+
* [1.1 List](#11-list)
|
43
|
+
* [1.2 Header](#12-header)
|
44
|
+
* [1.3 Quote](#13-quote)
|
45
|
+
* [1.4 Codeblock](#14-codeblock)
|
46
|
+
* [1.5 Table](#15-table)
|
47
|
+
* [2. Options](#2-options)
|
48
|
+
* [2.1 :theme](#21-theme)
|
49
|
+
|
50
|
+
## 1. Usage
|
51
|
+
|
52
|
+
Using `parse` method, you can transform a markdown string into a terminal formatted content:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
parsed = TTY::Markdown.parse("# Hello")
|
56
|
+
puts parsed
|
57
|
+
# => "\e[36;1mHello\e[0m\n"
|
58
|
+
```
|
59
|
+
|
60
|
+
The `parse_file` allows you to transform a markdown document into a terminal formatted output:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
parsed = TTY::Markdown.parse('example.md')
|
64
|
+
puts parsed
|
65
|
+
```
|
66
|
+
|
67
|
+
### 1.1 List
|
68
|
+
|
69
|
+
Both numbered and unordered lists are supported. Given a markdown:
|
70
|
+
|
71
|
+
```markdown
|
72
|
+
- Item 1
|
73
|
+
- Item 2
|
74
|
+
- Item 3
|
75
|
+
- Item 4
|
76
|
+
- Item 5
|
77
|
+
```
|
78
|
+
|
79
|
+
and transforming it:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
parsed = TTY::Markdown.parse(markdown_string)
|
83
|
+
```
|
84
|
+
|
85
|
+
`puts parsed` will produce:
|
86
|
+
|
87
|
+
![Code highlight](https://cdn.rawgit.com/piotrmurach/tty-markdown/master/assets/list.png)
|
88
|
+
|
89
|
+
### 1.2 Header
|
90
|
+
|
91
|
+
```markdown
|
92
|
+
TTY::Markdown
|
93
|
+
=============
|
94
|
+
|
95
|
+
**tty-markdown** converts markdown document into a terminal friendly output.
|
96
|
+
|
97
|
+
## Examples
|
98
|
+
|
99
|
+
### Nested list items
|
100
|
+
```
|
101
|
+
|
102
|
+
and transforming it:
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
parsed = TTY::Markdown.parse(markdown_string)
|
106
|
+
```
|
107
|
+
|
108
|
+
`puts parsed` will output:
|
109
|
+
|
110
|
+
![Code highlight](https://cdn.rawgit.com/piotrmurach/tty-markdown/master/assets/headers.png)
|
111
|
+
|
112
|
+
### Quote
|
113
|
+
|
114
|
+
Given a markdown quote:
|
115
|
+
|
116
|
+
```markdown
|
117
|
+
> Blockquotes are very handy in email to emulate reply text.
|
118
|
+
> This line is part of the same quote.
|
119
|
+
> *Oh*, you can put **Markdown** into a blockquote.
|
120
|
+
```
|
121
|
+
|
122
|
+
and transforming it:
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
parsed = TTY::Markdown.parse(markdown_string)
|
126
|
+
```
|
127
|
+
|
128
|
+
`puts parsed` will output:
|
129
|
+
|
130
|
+
![Code highlight](https://cdn.rawgit.com/piotrmurach/tty-markdown/master/assets/quote.png)
|
131
|
+
|
132
|
+
### Codeblock
|
133
|
+
|
134
|
+
The parser can highlight syntax of many programming languages. Given the markdown codeblock with language specification:
|
135
|
+
|
136
|
+
````markdown
|
137
|
+
```ruby
|
138
|
+
class Greeter
|
139
|
+
def hello(name)
|
140
|
+
puts "Hello #{name}"
|
141
|
+
end
|
142
|
+
end
|
143
|
+
```
|
144
|
+
````
|
145
|
+
|
146
|
+
and converting this snippet:
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
parsed = TTY::Markdown.parse(code_snippet)
|
150
|
+
```
|
151
|
+
|
152
|
+
`puts parsed` will produce:
|
153
|
+
|
154
|
+
![Code highlight](https://cdn.rawgit.com/piotrmurach/tty-markdown/master/assets/syntax_highlight.png)
|
155
|
+
|
156
|
+
### Table
|
157
|
+
|
158
|
+
You can transform tables which understand the markdown alignment.
|
159
|
+
|
160
|
+
For example, given the following table:
|
161
|
+
|
162
|
+
```markdown
|
163
|
+
| Tables | Are | Cool |
|
164
|
+
|----------|:-------------:|------:|
|
165
|
+
| col 1 is | left-aligned | $1600 |
|
166
|
+
| col 2 is | centered | $12 |
|
167
|
+
| col 3 is | right-aligned | $1 |
|
168
|
+
```
|
169
|
+
|
170
|
+
and transforming it:
|
171
|
+
|
172
|
+
```ruby
|
173
|
+
parsed = TTY::Markdown.parse(markdown_string)
|
174
|
+
```
|
175
|
+
|
176
|
+
`puts parsed` will output:
|
177
|
+
|
178
|
+
![Code highlight](https://cdn.rawgit.com/piotrmurach/tty-markdown/master/assets/table.png)
|
179
|
+
|
180
|
+
## 2. Options
|
181
|
+
|
182
|
+
### 2.1 `:theme`
|
183
|
+
|
184
|
+
A hash of styles that allows to customize specific elements of the markdown text. By default the following styles are used:
|
185
|
+
|
186
|
+
```ruby
|
187
|
+
THEME = {
|
188
|
+
em: :italic,
|
189
|
+
header: [:cyan, :bold],
|
190
|
+
hr: :yellow,
|
191
|
+
link: [:blue, :underline],
|
192
|
+
list: :yellow,
|
193
|
+
strong: [:yellow, :bold],
|
194
|
+
table: :blue,
|
195
|
+
quote: :yellow,
|
196
|
+
}
|
197
|
+
```
|
198
|
+
|
199
|
+
In order to provide new styles use `:theme` key:
|
200
|
+
|
201
|
+
```ruby
|
202
|
+
TTY::Markdown.parse(markdown_string, theme: { ... })
|
203
|
+
```
|
204
|
+
|
205
|
+
## Development
|
206
|
+
|
207
|
+
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.
|
208
|
+
|
209
|
+
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](https://rubygems.org).
|
210
|
+
|
211
|
+
## Contributing
|
212
|
+
|
213
|
+
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](http://contributor-covenant.org) code of conduct.
|
214
|
+
|
215
|
+
## License
|
216
|
+
|
217
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
218
|
+
|
219
|
+
## Code of Conduct
|
220
|
+
|
221
|
+
Everyone interacting in the TTY::Markdown project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/piotrmurach/tty-markdown/blob/master/CODE_OF_CONDUCT.md).
|
222
|
+
|
223
|
+
## Copyright
|
224
|
+
|
225
|
+
Copyright (c) 2018 Piotr Murach. See LICENSE for further details.
|
data/Rakefile
ADDED
data/appveyor.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
---
|
2
|
+
install:
|
3
|
+
- SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
|
4
|
+
- ruby --version
|
5
|
+
- gem --version
|
6
|
+
- bundle install
|
7
|
+
build: off
|
8
|
+
test_script:
|
9
|
+
- bundle exec rake ci
|
10
|
+
environment:
|
11
|
+
matrix:
|
12
|
+
- ruby_version: "200"
|
13
|
+
- ruby_version: "200-x64"
|
14
|
+
- ruby_version: "21"
|
15
|
+
- ruby_version: "21-x64"
|
16
|
+
- ruby_version: "22"
|
17
|
+
- ruby_version: "22-x64"
|
18
|
+
- ruby_version: "23"
|
19
|
+
- ruby_version: "23-x64"
|
20
|
+
- ruby_version: "24"
|
21
|
+
- ruby_version: "24-x64"
|
data/assets/headers.png
ADDED
Binary file
|
data/assets/list.png
ADDED
Binary file
|
data/assets/quote.png
ADDED
Binary file
|
Binary file
|
data/assets/table.png
ADDED
Binary file
|