tty-markdown 0.1.0 → 0.2.0
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 +17 -1
- data/README.md +4 -4
- data/examples/man.md +17 -0
- data/examples/man.rb +6 -0
- data/lib/tty/markdown.rb +26 -4
- data/lib/tty/markdown/parser.rb +37 -2
- data/lib/tty/markdown/syntax_highlighter.rb +3 -1
- data/lib/tty/markdown/version.rb +1 -1
- data/tty-markdown.gemspec +3 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44486f20a5fb0b3db0de9d760bf88e33a713aa56
|
4
|
+
data.tar.gz: 9c55823506373b0a6d95c38fa1fab6a4b38d2462
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a49d8dc74703dd156ea8646beb251c51dfc0efd0f27ccee0c29b04648c8d7aa671730d607154a3d1fb9ab0c3bf988662565a39f346fcdb95a2b3331a8c73eda
|
7
|
+
data.tar.gz: cab7e9b37d1a281ad5c9419e26881fa56f1420070d141ace550468be373885d637177927d362c537cf91c31f760704f1370a544625e420d8b07f152d357dc3bf
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,23 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## [v0.2.0] - 2018-01-29
|
4
|
+
|
5
|
+
### Added
|
6
|
+
* Add space indented codeblock markdown conversion
|
7
|
+
* Add markdown math formula conversion
|
8
|
+
* Add markdown typogrpahic symbols conversion by Tanaka Masaki(@T-a-n-a-k-a-M-a-s-a-k-i)
|
9
|
+
* Add html entities conversion
|
10
|
+
* Add warnings about unsupported conversions for completness
|
11
|
+
|
12
|
+
### Changed
|
13
|
+
* Change gemspec to require Ruby >= 2.0.0
|
14
|
+
|
15
|
+
### Fixed
|
16
|
+
* Fix smart quotes to correctly encode entities
|
17
|
+
|
3
18
|
## [v0.1.0] - 2018-01-24
|
4
19
|
|
5
20
|
* Initial implementation and release
|
6
21
|
|
7
|
-
[v0.
|
22
|
+
[v0.2.0]: https://github.com/piotrmurach/tty-markdown/compare/v0.1.0...v0.2.0
|
23
|
+
[v0.1.0]: https://github.com/piotrmurach/tty-markdown/compare/v0.1.0
|
data/README.md
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
[coverage]: https://coveralls.io/github/piotrmurach/tty-markdown
|
16
16
|
[inchpages]: http://inch-ci.org/github/piotrmurach/tty-markdown
|
17
17
|
|
18
|
-
> Convert a markdown
|
18
|
+
> Convert a markdown document or text into a terminal friendly output.
|
19
19
|
|
20
20
|
|
21
21
|
**TTY::Markdown** provides independent markdown processing component for [TTY](https://github.com/piotrmurach/tty) toolkit.
|
@@ -109,7 +109,7 @@ parsed = TTY::Markdown.parse(markdown_string)
|
|
109
109
|
|
110
110
|

|
111
111
|
|
112
|
-
### Quote
|
112
|
+
### 1.3 Quote
|
113
113
|
|
114
114
|
Given a markdown quote:
|
115
115
|
|
@@ -129,7 +129,7 @@ parsed = TTY::Markdown.parse(markdown_string)
|
|
129
129
|
|
130
130
|

|
131
131
|
|
132
|
-
### Codeblock
|
132
|
+
### 1.4 Codeblock
|
133
133
|
|
134
134
|
The parser can highlight syntax of many programming languages. Given the markdown codeblock with language specification:
|
135
135
|
|
@@ -153,7 +153,7 @@ parsed = TTY::Markdown.parse(code_snippet)
|
|
153
153
|
|
154
154
|

|
155
155
|
|
156
|
-
### Table
|
156
|
+
### 1.5 Table
|
157
157
|
|
158
158
|
You can transform tables which understand the markdown alignment.
|
159
159
|
|
data/examples/man.md
ADDED
data/examples/man.rb
ADDED
data/lib/tty/markdown.rb
CHANGED
@@ -14,6 +14,17 @@ module TTY
|
|
14
14
|
diamond: '◈',
|
15
15
|
pipe: '│',
|
16
16
|
line: '─',
|
17
|
+
hellip: '…',
|
18
|
+
laquo: '«',
|
19
|
+
laquo_space: '« ',
|
20
|
+
raquo: '»',
|
21
|
+
raquo_space: ' »',
|
22
|
+
ndash: '-',
|
23
|
+
mdash: "\u2014",
|
24
|
+
lsquo: '‘',
|
25
|
+
rsquo: '’',
|
26
|
+
ldquo: '“',
|
27
|
+
rdquo: '”',
|
17
28
|
top_left: '┌',
|
18
29
|
top_right: '┐',
|
19
30
|
top_center: '┬',
|
@@ -22,8 +33,8 @@ module TTY
|
|
22
33
|
mid_center: '┼',
|
23
34
|
bottom_right: '┘',
|
24
35
|
bottom_left: '└',
|
25
|
-
bottom_center: '┴'
|
26
|
-
}
|
36
|
+
bottom_center: '┴',
|
37
|
+
}.freeze
|
27
38
|
|
28
39
|
WIN_SYMBOLS = {
|
29
40
|
arrow: '->',
|
@@ -32,6 +43,17 @@ module TTY
|
|
32
43
|
bar: '│',
|
33
44
|
pipe: '|',
|
34
45
|
line: '─',
|
46
|
+
hellip: '...',
|
47
|
+
laquo: '<<',
|
48
|
+
laquo_space: '<< ',
|
49
|
+
raquo: '>>',
|
50
|
+
raquo_space: ' >>',
|
51
|
+
ndash: '-',
|
52
|
+
mdash: "--",
|
53
|
+
lsquo: ''',
|
54
|
+
rsquo: ''',
|
55
|
+
ldquo: '"',
|
56
|
+
rdquo: '"',
|
35
57
|
top_left: '+',
|
36
58
|
top_right: '+',
|
37
59
|
top_center: '+',
|
@@ -41,7 +63,7 @@ module TTY
|
|
41
63
|
bottom_right: '+',
|
42
64
|
bottom_left: '+',
|
43
65
|
bottom_center: '+'
|
44
|
-
}
|
66
|
+
}.freeze
|
45
67
|
|
46
68
|
THEME = {
|
47
69
|
em: :italic,
|
@@ -52,7 +74,7 @@ module TTY
|
|
52
74
|
strong: [:yellow, :bold],
|
53
75
|
table: :blue,
|
54
76
|
quote: :yellow,
|
55
|
-
}
|
77
|
+
}.freeze
|
56
78
|
|
57
79
|
# Parse a markdown string
|
58
80
|
#
|
data/lib/tty/markdown/parser.rb
CHANGED
@@ -139,12 +139,12 @@ module TTY
|
|
139
139
|
end
|
140
140
|
|
141
141
|
def convert_smart_quote(el, opts)
|
142
|
-
|
142
|
+
opts[:result] << TTY::Markdown.symbols[el.value]
|
143
143
|
end
|
144
144
|
|
145
145
|
def convert_codespan(el, opts)
|
146
146
|
raw_code = el.value
|
147
|
-
highlighted = SyntaxHighliter.highlight(raw_code, @color_opts)
|
147
|
+
highlighted = SyntaxHighliter.highlight(raw_code, @color_opts.merge(opts))
|
148
148
|
code = highlighted.split("\n").map.with_index do |line, i|
|
149
149
|
if i == 0 # first line
|
150
150
|
line
|
@@ -155,6 +155,11 @@ module TTY
|
|
155
155
|
opts[:result] << code.join("\n")
|
156
156
|
end
|
157
157
|
|
158
|
+
def convert_codeblock(el, opts)
|
159
|
+
opts[:fenced] = false
|
160
|
+
convert_codespan(el, opts)
|
161
|
+
end
|
162
|
+
|
158
163
|
def convert_blockquote(el, opts)
|
159
164
|
inner(el, opts)
|
160
165
|
end
|
@@ -337,6 +342,32 @@ module TTY
|
|
337
342
|
end
|
338
343
|
end
|
339
344
|
|
345
|
+
def convert_math(el, opts)
|
346
|
+
if opts[:prev] && opts[:prev].type == :blank
|
347
|
+
indent = ' ' * @current_indent
|
348
|
+
opts[:result] << indent
|
349
|
+
end
|
350
|
+
convert_codespan(el, opts)
|
351
|
+
opts[:result] << "\n"
|
352
|
+
end
|
353
|
+
|
354
|
+
def convert_abbreviation(el, opts)
|
355
|
+
opts[:result] << el.value
|
356
|
+
end
|
357
|
+
|
358
|
+
def convert_typographic_sym(el, opts)
|
359
|
+
opts[:result] << TTY::Markdown.symbols[el.value]
|
360
|
+
end
|
361
|
+
|
362
|
+
def convert_entity(el, opts)
|
363
|
+
opts[:result] << unicode_char(el.value.code_point)
|
364
|
+
end
|
365
|
+
|
366
|
+
# Convert codepoint to UTF-8 representation
|
367
|
+
def unicode_char(codepoint)
|
368
|
+
[codepoint].pack('U*')
|
369
|
+
end
|
370
|
+
|
340
371
|
def convert_footnote(*)
|
341
372
|
warning("Footnotes are not supported")
|
342
373
|
end
|
@@ -348,6 +379,10 @@ module TTY
|
|
348
379
|
def convert_img(*)
|
349
380
|
warning("Images are not supported")
|
350
381
|
end
|
382
|
+
|
383
|
+
def convert_html_element(*)
|
384
|
+
warning("HTML elements are not supported")
|
385
|
+
end
|
351
386
|
end # Parser
|
352
387
|
end # Markdown
|
353
388
|
end # TTY
|
@@ -47,7 +47,9 @@ module TTY
|
|
47
47
|
lang = guess_lang(code)
|
48
48
|
mode = options[:mode] || TTY::Color.mode
|
49
49
|
lines = code.dup.lines
|
50
|
-
|
50
|
+
if options[:fenced].nil?
|
51
|
+
code = lines[1...-1].join + lines[-1].strip
|
52
|
+
end
|
51
53
|
|
52
54
|
lexer = Rouge::Lexer.find_fancy(lang, code) || Rouge::Lexers::PlainText
|
53
55
|
|
data/lib/tty/markdown/version.rb
CHANGED
data/tty-markdown.gemspec
CHANGED
@@ -20,12 +20,14 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
+
spec.required_ruby_version = '>= 2.0.0'
|
24
|
+
|
23
25
|
spec.add_dependency "kramdown", '~> 1.16.2'
|
24
26
|
spec.add_dependency "pastel", '~> 0.7.2'
|
25
27
|
spec.add_dependency "rouge", '~> 3.1.0'
|
26
28
|
spec.add_dependency "strings", '~> 0.1.0'
|
27
29
|
spec.add_dependency "tty-color", '~> 0.4.2'
|
28
|
-
spec.add_dependency "tty-screen", '~> 0.6.
|
30
|
+
spec.add_dependency "tty-screen", '~> 0.6.4'
|
29
31
|
|
30
32
|
spec.add_development_dependency "bundler", "~> 1.16"
|
31
33
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tty-markdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Murach
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kramdown
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.6.
|
89
|
+
version: 0.6.4
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.6.
|
96
|
+
version: 0.6.4
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: bundler
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -160,6 +160,8 @@ files:
|
|
160
160
|
- bin/console
|
161
161
|
- bin/setup
|
162
162
|
- examples/example.md
|
163
|
+
- examples/man.md
|
164
|
+
- examples/man.rb
|
163
165
|
- examples/marked.rb
|
164
166
|
- lib/tty-markdown.rb
|
165
167
|
- lib/tty/markdown.rb
|
@@ -182,7 +184,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
182
184
|
requirements:
|
183
185
|
- - ">="
|
184
186
|
- !ruby/object:Gem::Version
|
185
|
-
version:
|
187
|
+
version: 2.0.0
|
186
188
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
187
189
|
requirements:
|
188
190
|
- - ">="
|