tty-markdown 0.6.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +49 -2
- data/LICENSE.txt +1 -1
- data/README.md +176 -80
- data/lib/tty/markdown/converter.rb +819 -0
- data/lib/tty/markdown/kramdown_ext.rb +23 -0
- data/lib/tty/markdown/syntax_highlighter.rb +20 -16
- data/lib/tty/markdown/version.rb +1 -1
- data/lib/tty/markdown.rb +194 -72
- data/lib/tty-markdown.rb +1 -1
- metadata +41 -68
- data/Rakefile +0 -8
- data/assets/headers.png +0 -0
- data/assets/hr.png +0 -0
- data/assets/link.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 +0 -14
- data/bin/setup +0 -8
- data/examples/man.rb +0 -6
- data/examples/marked.rb +0 -6
- data/lib/tty/markdown/parser.rb +0 -482
- data/spec/spec_helper.rb +0 -31
- data/spec/unit/parse/abbrev_spec.rb +0 -27
- data/spec/unit/parse/blockquote_spec.rb +0 -77
- data/spec/unit/parse/codeblock_spec.rb +0 -130
- data/spec/unit/parse/comment_spec.rb +0 -19
- data/spec/unit/parse/emphasis_spec.rb +0 -35
- data/spec/unit/parse/entity_spec.rb +0 -11
- data/spec/unit/parse/header_spec.rb +0 -35
- data/spec/unit/parse/hr_spec.rb +0 -25
- data/spec/unit/parse/link_spec.rb +0 -25
- data/spec/unit/parse/list_spec.rb +0 -103
- data/spec/unit/parse/math_spec.rb +0 -37
- data/spec/unit/parse/paragraph_spec.rb +0 -38
- data/spec/unit/parse/table_spec.rb +0 -164
- data/spec/unit/parse/typography_spec.rb +0 -20
- data/tasks/console.rake +0 -11
- data/tasks/coverage.rake +0 -11
- data/tasks/spec.rake +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d66f69be1b2127af4896ee71342a8be1ea8cf9dabcdceed64c696baf23121a8
|
4
|
+
data.tar.gz: 7e612092f8fa261a8ae1bff784d4a5f607882c417576978c4f18d8ef87bca9c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 219503274cc89c967412401023b4fa194dc018538115d30d45cbe0ed3fb103dbe9f14dfefd29aeef3de03a9d87bcce5def305c9c9f69aeb4a59b171dd96313b5
|
7
|
+
data.tar.gz: 5587f2552f75db9e0a053cb7afe2975f5a984329f53d94f3c50868c8253daf3e8f5383c128d59307c782e7395934a58128d5c09d25ca739e02800f51e2694053
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,49 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## [v0.7.1] - 2022-12-21
|
4
|
+
|
5
|
+
### Changed
|
6
|
+
* Change the symbols option to accept string value
|
7
|
+
|
8
|
+
### Fixed
|
9
|
+
* Fix the theme option to allow overriding specific markdown element styles
|
10
|
+
|
11
|
+
## [v0.7.0] - 2020-09-03
|
12
|
+
|
13
|
+
### Added
|
14
|
+
* Add converter for br element by @krage
|
15
|
+
* Add configuration of symbols by @krage
|
16
|
+
* Add definition list support
|
17
|
+
* Add table footer formatting
|
18
|
+
* Add formatting of image source location
|
19
|
+
* Add footnotes support
|
20
|
+
* Add XML comments support
|
21
|
+
* Add HTML div/i/em/b/strong/img/a element support
|
22
|
+
* Add color configuration setting
|
23
|
+
|
24
|
+
### Changed
|
25
|
+
* Change #new to accept configuration options as keywords
|
26
|
+
* Display links with both label and optional title by @krage
|
27
|
+
* Display link without the label when label content is same as link target @krage
|
28
|
+
* Change hr formatting to be always full width
|
29
|
+
* Differentiate between span and block math elements
|
30
|
+
* Display abbreviation with its definition
|
31
|
+
* Improve performance by calculating table column widths and row heights only once
|
32
|
+
* Change to remove mailto: from email links for brevity @krage
|
33
|
+
* Change to update kramdown to support versions >= 1.16 and < 3.0
|
34
|
+
* Change to update pastel, tty-color & tty-screen dependencies
|
35
|
+
* Change HTML del element formatting to strikethrough
|
36
|
+
* Rename colors setting to mode
|
37
|
+
|
38
|
+
### Fixed
|
39
|
+
* Fix break line handling by @krage
|
40
|
+
* Fix links handling by @krage
|
41
|
+
* Fix table formatting of empty cells
|
42
|
+
* Fix content wrapping to account for the current indentation
|
43
|
+
* Fix header wrapping
|
44
|
+
* Fix blockquote formatting of content with emphasised style or apostrophe
|
45
|
+
* Fix support for HTML del element
|
46
|
+
|
3
47
|
## [v0.6.0] - 2019-03-30
|
4
48
|
|
5
49
|
### Added
|
@@ -15,7 +59,7 @@
|
|
15
59
|
### Changed
|
16
60
|
* Change gemspec to load files directly
|
17
61
|
* Change to update rouge dependency
|
18
|
-
* Change to relax
|
62
|
+
* Change to relax constraints on tty-screen and tty-color
|
19
63
|
|
20
64
|
## [v0.4.0] - 2018-06-20
|
21
65
|
|
@@ -54,7 +98,10 @@
|
|
54
98
|
|
55
99
|
* Initial implementation and release
|
56
100
|
|
57
|
-
[v0.
|
101
|
+
[v0.7.1]: https://github.com/piotrmurach/tty-markdown/compare/v0.7.0...v0.7.1
|
102
|
+
[v0.7.0]: https://github.com/piotrmurach/tty-markdown/compare/v0.6.0...v0.7.0
|
103
|
+
[v0.6.0]: https://github.com/piotrmurach/tty-markdown/compare/v0.5.1...v0.6.0
|
104
|
+
[v0.5.1]: https://github.com/piotrmurach/tty-markdown/compare/v0.5.0...v0.5.1
|
58
105
|
[v0.5.0]: https://github.com/piotrmurach/tty-markdown/compare/v0.4.0...v0.5.0
|
59
106
|
[v0.4.0]: https://github.com/piotrmurach/tty-markdown/compare/v0.3.0...v0.4.0
|
60
107
|
[v0.3.0]: https://github.com/piotrmurach/tty-markdown/compare/v0.2.0...v0.3.0
|
data/LICENSE.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c) 2018 Piotr Murach
|
3
|
+
Copyright (c) 2018 Piotr Murach (piotrmurach.com)
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -1,27 +1,26 @@
|
|
1
1
|
<div align="center">
|
2
|
-
<a href="https://
|
2
|
+
<a href="https://ttytoolkit.org"><img width="130" src="https://github.com/piotrmurach/tty/raw/master/images/tty.png" alt="TTY Toolkit logo" /></a>
|
3
3
|
</div>
|
4
4
|
|
5
5
|
# TTY::Markdown [][gitter]
|
6
6
|
|
7
7
|
[][gem]
|
8
|
-
[][gh_actions_ci]
|
9
9
|
[][appveyor]
|
10
10
|
[][codeclimate]
|
11
11
|
[][coverage]
|
12
|
-
[][inchpages]
|
13
13
|
|
14
14
|
[gitter]: https://gitter.im/piotrmurach/tty
|
15
|
-
[gem]:
|
16
|
-
[
|
15
|
+
[gem]: https://badge.fury.io/rb/tty-markdown
|
16
|
+
[gh_actions_ci]: https://github.com/piotrmurach/tty-markdown/actions?query=workflow%3ACI
|
17
17
|
[appveyor]: https://ci.appveyor.com/project/piotrmurach/tty-markdown
|
18
18
|
[codeclimate]: https://codeclimate.com/github/piotrmurach/tty-markdown/maintainability
|
19
19
|
[coverage]: https://coveralls.io/github/piotrmurach/tty-markdown
|
20
|
-
[inchpages]:
|
20
|
+
[inchpages]: https://inch-ci.org/github/piotrmurach/tty-markdown
|
21
21
|
|
22
22
|
> Convert a markdown document or text into a terminal friendly output.
|
23
23
|
|
24
|
-
|
25
24
|
**TTY::Markdown** provides independent markdown processing component for [TTY](https://github.com/piotrmurach/tty) toolkit.
|
26
25
|
|
27
26
|
## Installation
|
@@ -45,15 +44,21 @@ Or install it yourself as:
|
|
45
44
|
* [1. Usage](#1-usage)
|
46
45
|
* [1.1 Header](#11-header)
|
47
46
|
* [1.2 List](#12-list)
|
48
|
-
* [1.3
|
49
|
-
* [1.4
|
50
|
-
* [1.5
|
51
|
-
* [1.6
|
52
|
-
* [1.7
|
47
|
+
* [1.3 Definition List](#13-definition-list)
|
48
|
+
* [1.4 Link](#14-link)
|
49
|
+
* [1.5 Blockquote](#15-blockquote)
|
50
|
+
* [1.6 Code and Syntax Highlighting](#16-code-and-syntax-highlighting)
|
51
|
+
* [1.7 Table](#17-table)
|
52
|
+
* [1.8 Horizontal Rule](#18-horizontal-rule)
|
53
|
+
* [1.9 Footnotes](#19-footnotes)
|
53
54
|
* [2. Options](#2-options)
|
54
|
-
* [2.1 :
|
55
|
+
* [2.1 :mode](#21-mode)
|
55
56
|
* [2.2 :theme](#22-theme)
|
56
57
|
* [2.3 :width](#23-width)
|
58
|
+
* [2.4 :symbols](#24-symbols)
|
59
|
+
* [2.5 :indent](#25-indent)
|
60
|
+
* [2.6 :color](#26-color)
|
61
|
+
* [3. Command line tool](#3-command-line-tool)
|
57
62
|
|
58
63
|
## 1. Usage
|
59
64
|
|
@@ -74,6 +79,8 @@ puts parsed
|
|
74
79
|
|
75
80
|
### 1.1 Header
|
76
81
|
|
82
|
+
Parsing the following markdown headers:
|
83
|
+
|
77
84
|
```markdown
|
78
85
|
TTY::Markdown
|
79
86
|
=============
|
@@ -85,15 +92,9 @@ TTY::Markdown
|
|
85
92
|
### Nested list items
|
86
93
|
```
|
87
94
|
|
88
|
-
|
95
|
+
The terminal output looks like this:
|
89
96
|
|
90
|
-
|
91
|
-
parsed = TTY::Markdown.parse(markdown_string)
|
92
|
-
```
|
93
|
-
|
94
|
-
`puts parsed` will output:
|
95
|
-
|
96
|
-

|
97
|
+

|
97
98
|
|
98
99
|
### 1.2 List
|
99
100
|
|
@@ -107,29 +108,42 @@ Both numbered and unordered lists are supported. Given a markdown:
|
|
107
108
|
- Item 5
|
108
109
|
```
|
109
110
|
|
110
|
-
|
111
|
+
The parsed output looks like this:
|
111
112
|
|
112
|
-
|
113
|
-
|
113
|
+

|
114
|
+
|
115
|
+
### 1.3 Definition List
|
116
|
+
|
117
|
+
Given a definition list:
|
118
|
+
|
119
|
+
```markdown
|
120
|
+
Item 1
|
121
|
+
: This is the description for Item 1
|
122
|
+
|
123
|
+
Item 2
|
124
|
+
: This is the description for Item 2
|
125
|
+
: This is another description for Item 2
|
114
126
|
```
|
115
127
|
|
116
|
-
|
128
|
+
The parsed output looks like this:
|
117
129
|
|
118
|
-

|
119
131
|
|
120
|
-
### 1.
|
132
|
+
### 1.4 Link
|
121
133
|
|
122
|
-
A
|
134
|
+
A markdown link:
|
123
135
|
|
124
136
|
```markdown
|
125
|
-
[
|
137
|
+
[An inline-style link](https://ttytoolkit.org)
|
138
|
+
|
139
|
+
[An inline-style link with title](https://ttytoolkit.org "TTY Toolkit Homepage")
|
126
140
|
```
|
127
141
|
|
128
|
-
will be rendered with
|
142
|
+
The link text will be rendered with the link next to it:
|
129
143
|
|
130
|
-

|
131
145
|
|
132
|
-
### 1.
|
146
|
+
### 1.5 Blockquote
|
133
147
|
|
134
148
|
Given a markdown quote:
|
135
149
|
|
@@ -139,19 +153,15 @@ Given a markdown quote:
|
|
139
153
|
> *Oh*, you can put **Markdown** into a blockquote.
|
140
154
|
```
|
141
155
|
|
142
|
-
|
156
|
+
The rendered output looks like this:
|
143
157
|
|
144
|
-
|
145
|
-
parsed = TTY::Markdown.parse(markdown_string)
|
146
|
-
```
|
147
|
-
|
148
|
-
`puts parsed` will output:
|
158
|
+

|
149
159
|
|
150
|
-
|
160
|
+
### 1.6 Code and Syntax Highlighting
|
151
161
|
|
152
|
-
|
162
|
+
The parser can highlight syntax of many programming languages.
|
153
163
|
|
154
|
-
|
164
|
+
Given a markdown codeblock with a language specification:
|
155
165
|
|
156
166
|
````markdown
|
157
167
|
```ruby
|
@@ -163,17 +173,11 @@ end
|
|
163
173
|
```
|
164
174
|
````
|
165
175
|
|
166
|
-
|
167
|
-
|
168
|
-
```ruby
|
169
|
-
parsed = TTY::Markdown.parse(code_snippet)
|
170
|
-
```
|
171
|
-
|
172
|
-
`puts parsed` will produce:
|
176
|
+
The terminal output will look like this:
|
173
177
|
|
174
|
-

|
175
179
|
|
176
|
-
### 1.
|
180
|
+
### 1.7 Table
|
177
181
|
|
178
182
|
You can transform tables which understand the markdown alignment.
|
179
183
|
|
@@ -187,17 +191,11 @@ For example, given the following table:
|
|
187
191
|
| col 3 is | right-aligned | $1 |
|
188
192
|
```
|
189
193
|
|
190
|
-
|
194
|
+
Then the terminal output will look like this:
|
191
195
|
|
192
|
-
|
193
|
-
parsed = TTY::Markdown.parse(markdown_string)
|
194
|
-
```
|
195
|
-
|
196
|
-
`puts parsed` will output:
|
197
|
-
|
198
|
-

|
196
|
+

|
199
197
|
|
200
|
-
### 1.
|
198
|
+
### 1.8 Horizontal Rule
|
201
199
|
|
202
200
|
You can specify a horizontal rule in markdown:
|
203
201
|
|
@@ -213,42 +211,66 @@ parsed = TTY::Markdown.parse(markdown_string)
|
|
213
211
|
|
214
212
|
`puts parsed` will output:
|
215
213
|
|
216
|
-

|
215
|
+
|
216
|
+
### 1.9 Footnotes
|
217
|
+
|
218
|
+
You can create footnote references:
|
219
|
+
|
220
|
+
```markdown
|
221
|
+
It is not down on any map[^foo]; true places[^bar] never are.
|
222
|
+
|
223
|
+
[^foo]: A diagrammatic representation of an area of land or sea.
|
224
|
+
[^bar]: A particular position, point, or area in space; a location.
|
225
|
+
```
|
226
|
+
|
227
|
+
All footnotes will be displayed with a sequential number and rendered in the terminal like this:
|
228
|
+
|
229
|
+

|
217
230
|
|
218
231
|
## 2. Options
|
219
232
|
|
220
|
-
### 2.1 `:
|
233
|
+
### 2.1 `:mode`
|
221
234
|
|
222
|
-
By default the `256`
|
235
|
+
By default the `256` color scheme is used to render code block elements.
|
236
|
+
|
237
|
+
You can change this by specifying maximum number of colors to be `16` ANSI colors:
|
223
238
|
|
224
239
|
```ruby
|
225
|
-
TTY::Markdown.
|
240
|
+
TTY::Markdown.parse(markdown_string, mode: 16)
|
226
241
|
```
|
227
242
|
|
228
|
-
This
|
243
|
+
This feature may be handy when working in terminals with limited color support.
|
244
|
+
|
245
|
+
By default, **TTY::Markdown** detects your terminal color mode and adjusts output automatically.
|
229
246
|
|
230
247
|
### 2.2 `:theme`
|
231
248
|
|
232
|
-
|
249
|
+
Use the `:theme` option to change specific markdown element styles.
|
250
|
+
|
251
|
+
For example, to override styles for the `link` and `list` elements do:
|
233
252
|
|
234
253
|
```ruby
|
235
|
-
|
236
|
-
em: :yellow,
|
237
|
-
header: [:cyan, :bold],
|
238
|
-
hr: :yellow,
|
239
|
-
link: [:yellow, :underline],
|
240
|
-
list: :yellow,
|
241
|
-
strong: [:yellow, :bold],
|
242
|
-
table: :yellow,
|
243
|
-
quote: :yellow,
|
244
|
-
}
|
254
|
+
TTY::Markdown.parse(markdown_string, theme: {link: :magenta, list: %i[magenta bold]})
|
245
255
|
```
|
246
256
|
|
247
|
-
|
257
|
+
Here's a complete list of element names with corresponding styles:
|
248
258
|
|
249
|
-
|
250
|
-
|
251
|
-
|
259
|
+
| Name | Style |
|
260
|
+
|------------|-------------------------|
|
261
|
+
| `:comment` | `:bright_black` |
|
262
|
+
| `:em` | `:yellow` |
|
263
|
+
| `:header` | `%i[cyan bold]` |
|
264
|
+
| `:hr` | `:yellow` |
|
265
|
+
| `:image` | `:bright_black` |
|
266
|
+
| `:link` | `%i[yellow underline]` |
|
267
|
+
| `:list` | `:yellow` |
|
268
|
+
| `:note` | `:yellow` |
|
269
|
+
| `:quote` | `:yellow` |
|
270
|
+
| `:strong` | `%i[yellow bold]` |
|
271
|
+
| `:table` | `:yellow` |
|
272
|
+
|
273
|
+
Read [pastel documentation](https://github.com/piotrmurach/pastel#3-supported-colors) for all supported styles.
|
252
274
|
|
253
275
|
### 2.3 `:width`
|
254
276
|
|
@@ -260,6 +282,80 @@ TTY::Markdown.parse(markdown_string, width: 80)
|
|
260
282
|
|
261
283
|
By default the terminal screen width is used.
|
262
284
|
|
285
|
+
### 2.4 `:symbols`
|
286
|
+
|
287
|
+
By default formatting will include various Unicode symbols. You can switch to an included ASCII set and/or override individually with the `:symbols` key:
|
288
|
+
|
289
|
+
```ruby
|
290
|
+
TTY::Markdown.parse(markdown_string, symbols: :ascii)
|
291
|
+
TTY::Markdown.parse(markdown_string, symbols: {base: :ascii})
|
292
|
+
TTY::Markdown.parse(markdown_string, symbols: {override: {bullet: "x"}})
|
293
|
+
```
|
294
|
+
|
295
|
+
Here's a complete list of symbol names with corresponding ASCII and Unicode characters:
|
296
|
+
|
297
|
+
| Name | ASCII | Unicode |
|
298
|
+
|------------------|-------|---------|
|
299
|
+
| `:arrow` | `->` | `»` |
|
300
|
+
| `:bar` | `\|` | `┃` |
|
301
|
+
| `:bottom_center` | `+` | `┴` |
|
302
|
+
| `:bottom_left` | `+` | `└` |
|
303
|
+
| `:bottom_right` | `+` | `┘` |
|
304
|
+
| `:bracket_left` | `[` | `[` |
|
305
|
+
| `:bracket_right` | `]` | `]` |
|
306
|
+
| `:bullet` | `*` | `●` |
|
307
|
+
| `:diamond` | `*` | `◈` |
|
308
|
+
| `:hash` | `#` | `#` |
|
309
|
+
| `:hellip` | `...` | `…` |
|
310
|
+
| `:laquo` | `<<` | `«` |
|
311
|
+
| `:laquo_space` | `<< ` | `« ` |
|
312
|
+
| `:ldquo` | `"` | `“` |
|
313
|
+
| `:lsquo` | `"` | `‘` |
|
314
|
+
| `:line` | `-` | `─` |
|
315
|
+
| `:mdash` | `-` | `—` |
|
316
|
+
| `:mid_center` | `+` | `┼` |
|
317
|
+
| `:mid_left` | `+` | `├` |
|
318
|
+
| `:mid_right` | `+` | `┤` |
|
319
|
+
| `:ndash` | `-` | `-` |
|
320
|
+
| `:paren_left` | `(` | `(` |
|
321
|
+
| `:paren_right` | `)` | `)` |
|
322
|
+
| `:pipe` | `\|` | `│` |
|
323
|
+
| `:raquo` | `>>` | `»` |
|
324
|
+
| `:raquo_space` | ` >>` | ` »` |
|
325
|
+
| `:rdquo` | `"` | `”` |
|
326
|
+
| `:rsquo` | `"` | `’` |
|
327
|
+
| `:top_center` | `+` | `┬` |
|
328
|
+
| `:top_left` | `+` | `┌` |
|
329
|
+
| `:top_right` | `+` | `┐` |
|
330
|
+
|
331
|
+
### 2.5 `:indent`
|
332
|
+
|
333
|
+
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:
|
334
|
+
|
335
|
+
```ruby
|
336
|
+
TTY::Markdown.parse(markdown_string, indent: 0)
|
337
|
+
```
|
338
|
+
|
339
|
+
### 2.6 `:color`
|
340
|
+
|
341
|
+
You can control when to apply coloring to various document elements.
|
342
|
+
|
343
|
+
Valid values are `:never`, `:always` or `:auto`. By default `:auto` is used which auto detects if coloring can be applied.
|
344
|
+
|
345
|
+
For example, to always color content regardless of terminal support do:
|
346
|
+
|
347
|
+
```ruby
|
348
|
+
TTY::Markdown.parse(markdown_string, color: :always)
|
349
|
+
```
|
350
|
+
|
351
|
+
### 3. Command line tool
|
352
|
+
|
353
|
+
You can install [tty-markdown-cli](https://github.com/piotrmurach/tty-markdown-cli) to use `tty-markdown` executable in terminal:
|
354
|
+
|
355
|
+
```bash
|
356
|
+
$ tty-markdown README.md
|
357
|
+
```
|
358
|
+
|
263
359
|
## Development
|
264
360
|
|
265
361
|
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.
|
@@ -268,7 +364,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
268
364
|
|
269
365
|
## Contributing
|
270
366
|
|
271
|
-
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 [
|
367
|
+
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](https://github.com/piotrmurach/tty-markdown/blob/master/CODE_OF_CONDUCT.md).
|
272
368
|
|
273
369
|
## License
|
274
370
|
|