tty-markdown 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +40 -2
- data/README.md +117 -59
- data/lib/tty-markdown.rb +1 -1
- data/lib/tty/markdown.rb +127 -72
- data/lib/tty/markdown/converter.rb +821 -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
- metadata +38 -65
- 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
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Markdown, 'math' do
|
4
|
-
it "converts math formulae" do
|
5
|
-
markdown =<<-TEXT
|
6
|
-
$$5+5$$
|
7
|
-
TEXT
|
8
|
-
parsed = TTY::Markdown.parse(markdown, colors: 16)
|
9
|
-
expect(parsed).to eq("\e[33m5+5\e[0m\n")
|
10
|
-
end
|
11
|
-
|
12
|
-
it "indents maths formulae correctly" do
|
13
|
-
markdown =<<-TEXT
|
14
|
-
### header
|
15
|
-
|
16
|
-
$$5+5$$
|
17
|
-
TEXT
|
18
|
-
parsed = TTY::Markdown.parse(markdown, colors: 16)
|
19
|
-
expect(parsed).to eq([
|
20
|
-
" \e[36;1mheader\e[0m",
|
21
|
-
"",
|
22
|
-
" \e[33m5+5\e[0m\n"
|
23
|
-
].join("\n"))
|
24
|
-
end
|
25
|
-
|
26
|
-
it "indents immediate maths formulae correctly" do
|
27
|
-
markdown =<<-TEXT
|
28
|
-
### header
|
29
|
-
$$5+5$$
|
30
|
-
TEXT
|
31
|
-
parsed = TTY::Markdown.parse(markdown, colors: 16)
|
32
|
-
expect(parsed).to eq([
|
33
|
-
" \e[36;1mheader\e[0m",
|
34
|
-
" \e[33m5+5\e[0m\n"
|
35
|
-
].join("\n"))
|
36
|
-
end
|
37
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Markdown, 'paragraph' do
|
4
|
-
it "converts multiline paragraphs" do
|
5
|
-
markdown =<<-TEXT
|
6
|
-
This is a first paragraph
|
7
|
-
that spans two lines.
|
8
|
-
|
9
|
-
And this is a next one.
|
10
|
-
TEXT
|
11
|
-
parsed = TTY::Markdown.parse(markdown)
|
12
|
-
expect(parsed).to eq([
|
13
|
-
"This is a first paragraph",
|
14
|
-
"that spans two lines.",
|
15
|
-
"",
|
16
|
-
"And this is a next one.\n"
|
17
|
-
].join("\n"))
|
18
|
-
end
|
19
|
-
|
20
|
-
it "converts multiline pragraphs within header section" do
|
21
|
-
|
22
|
-
markdown =<<-TEXT
|
23
|
-
### header
|
24
|
-
This is a first paragraph
|
25
|
-
that spans two lines.
|
26
|
-
|
27
|
-
And this is a next one.
|
28
|
-
TEXT
|
29
|
-
parsed = TTY::Markdown.parse(markdown)
|
30
|
-
expect(parsed).to eq([
|
31
|
-
" \e[36;1mheader\e[0m",
|
32
|
-
" This is a first paragraph",
|
33
|
-
" that spans two lines.",
|
34
|
-
"",
|
35
|
-
" And this is a next one.\n"
|
36
|
-
].join("\n"))
|
37
|
-
end
|
38
|
-
end
|
@@ -1,164 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Markdown, 'table' do
|
4
|
-
let(:symbols) { TTY::Markdown.symbols }
|
5
|
-
|
6
|
-
it "parses markdown table with header" do
|
7
|
-
markdown =<<-TEXT
|
8
|
-
| Tables | Are | Cool |
|
9
|
-
|----------|:-------------:|------:|
|
10
|
-
| col 1 is | left-aligned | $1600 |
|
11
|
-
| col 2 is | centered | $12 |
|
12
|
-
| col 3 is | right-aligned | $1 |
|
13
|
-
TEXT
|
14
|
-
|
15
|
-
parsed = TTY::Markdown.parse(markdown)
|
16
|
-
|
17
|
-
expect(parsed).to eq([
|
18
|
-
"\e[33m#{symbols[:top_left]}#{symbols[:line]*10}#{symbols[:top_center]}",
|
19
|
-
"#{symbols[:line]*15}#{symbols[:top_center]}",
|
20
|
-
"#{symbols[:line]*7}#{symbols[:top_right]}",
|
21
|
-
"\e[0m\n",
|
22
|
-
|
23
|
-
"\e[33m#{symbols[:pipe]} \e[0mTables ",
|
24
|
-
"\e[33m#{symbols[:pipe]}\e[0m Are ",
|
25
|
-
"\e[33m#{symbols[:pipe]}\e[0m Cool \e[33m#{symbols[:pipe]}\e[0m \n",
|
26
|
-
|
27
|
-
"\e[33m#{symbols[:mid_left]}#{symbols[:line]*10}#{symbols[:mid_center]}",
|
28
|
-
"#{symbols[:line]*15}#{symbols[:mid_center]}",
|
29
|
-
"#{symbols[:line]*7}#{symbols[:mid_right]}",
|
30
|
-
"\e[0m\n",
|
31
|
-
|
32
|
-
"\e[33m#{symbols[:pipe]} \e[0mcol 1 is ",
|
33
|
-
"\e[33m#{symbols[:pipe]}\e[0m left-aligned ",
|
34
|
-
"\e[33m#{symbols[:pipe]}\e[0m $1600 \e[33m#{symbols[:pipe]}\e[0m \n",
|
35
|
-
|
36
|
-
"\e[33m#{symbols[:mid_left]}#{symbols[:line]*10}#{symbols[:mid_center]}",
|
37
|
-
"#{symbols[:line]*15}#{symbols[:mid_center]}",
|
38
|
-
"#{symbols[:line]*7}#{symbols[:mid_right]}",
|
39
|
-
"\e[0m\n",
|
40
|
-
|
41
|
-
"\e[33m#{symbols[:pipe]} \e[0mcol 2 is ",
|
42
|
-
"\e[33m#{symbols[:pipe]}\e[0m centered ",
|
43
|
-
"\e[33m#{symbols[:pipe]}\e[0m $12 \e[33m#{symbols[:pipe]}\e[0m \n",
|
44
|
-
|
45
|
-
"\e[33m#{symbols[:mid_left]}#{symbols[:line]*10}#{symbols[:mid_center]}",
|
46
|
-
"#{symbols[:line]*15}#{symbols[:mid_center]}",
|
47
|
-
"#{symbols[:line]*7}#{symbols[:mid_right]}",
|
48
|
-
"\e[0m\n",
|
49
|
-
|
50
|
-
"\e[33m#{symbols[:pipe]} \e[0mcol 3 is ",
|
51
|
-
"\e[33m#{symbols[:pipe]}\e[0m right-aligned ",
|
52
|
-
"\e[33m#{symbols[:pipe]}\e[0m $1 \e[33m#{symbols[:pipe]}\e[0m \n",
|
53
|
-
|
54
|
-
"\e[33m#{symbols[:bottom_left]}#{symbols[:line]*10}#{symbols[:bottom_center]}",
|
55
|
-
"#{symbols[:line]*15}#{symbols[:bottom_center]}",
|
56
|
-
"#{symbols[:line]*7}#{symbols[:bottom_right]}",
|
57
|
-
"\e[0m\n"
|
58
|
-
].join)
|
59
|
-
end
|
60
|
-
|
61
|
-
it "parses markdown table without header" do
|
62
|
-
markdown =<<-TEXT
|
63
|
-
| col 1 is | left-aligned | $1600 |
|
64
|
-
| col 2 is | centered | $12 |
|
65
|
-
| col 3 is | right-aligned | $1 |
|
66
|
-
TEXT
|
67
|
-
|
68
|
-
parsed = TTY::Markdown.parse(markdown)
|
69
|
-
|
70
|
-
expect(parsed).to eq([
|
71
|
-
"\e[33m#{symbols[:top_left]}#{symbols[:line]*10}#{symbols[:top_center]}",
|
72
|
-
"#{symbols[:line]*15}#{symbols[:top_center]}",
|
73
|
-
"#{symbols[:line]*7}#{symbols[:top_right]}",
|
74
|
-
"\e[0m\n",
|
75
|
-
|
76
|
-
"\e[33m#{symbols[:pipe]} \e[0mcol 1 is ",
|
77
|
-
"\e[33m#{symbols[:pipe]}\e[0m left-aligned ",
|
78
|
-
"\e[33m#{symbols[:pipe]}\e[0m $1600 \e[33m#{symbols[:pipe]}\e[0m \n",
|
79
|
-
|
80
|
-
"\e[33m#{symbols[:mid_left]}#{symbols[:line]*10}#{symbols[:mid_center]}",
|
81
|
-
"#{symbols[:line]*15}#{symbols[:mid_center]}",
|
82
|
-
"#{symbols[:line]*7}#{symbols[:mid_right]}",
|
83
|
-
"\e[0m\n",
|
84
|
-
|
85
|
-
"\e[33m#{symbols[:pipe]} \e[0mcol 2 is ",
|
86
|
-
"\e[33m#{symbols[:pipe]}\e[0m centered ",
|
87
|
-
"\e[33m#{symbols[:pipe]}\e[0m $12 \e[33m#{symbols[:pipe]}\e[0m \n",
|
88
|
-
|
89
|
-
"\e[33m#{symbols[:mid_left]}#{symbols[:line]*10}#{symbols[:mid_center]}",
|
90
|
-
"#{symbols[:line]*15}#{symbols[:mid_center]}",
|
91
|
-
"#{symbols[:line]*7}#{symbols[:mid_right]}",
|
92
|
-
"\e[0m\n",
|
93
|
-
|
94
|
-
"\e[33m#{symbols[:pipe]} \e[0mcol 3 is ",
|
95
|
-
"\e[33m#{symbols[:pipe]}\e[0m right-aligned ",
|
96
|
-
"\e[33m#{symbols[:pipe]}\e[0m $1 \e[33m#{symbols[:pipe]}\e[0m \n",
|
97
|
-
|
98
|
-
"\e[33m#{symbols[:bottom_left]}#{symbols[:line]*10}#{symbols[:bottom_center]}",
|
99
|
-
"#{symbols[:line]*15}#{symbols[:bottom_center]}",
|
100
|
-
"#{symbols[:line]*7}#{symbols[:bottom_right]}",
|
101
|
-
"\e[0m\n"
|
102
|
-
].join)
|
103
|
-
end
|
104
|
-
|
105
|
-
it "wraps multiline records" do
|
106
|
-
markdown =<<-TEXT
|
107
|
-
| Tables | Are | Cool |
|
108
|
-
|----------|:-------------:|------:|
|
109
|
-
| col 1 is | left-aligned | $1600 |
|
110
|
-
| col 2 is | centered | $12 |
|
111
|
-
| col 3 is a multiline column | right-aligned has also a very long content that wraps around | $1 |
|
112
|
-
TEXT
|
113
|
-
|
114
|
-
parsed = TTY::Markdown.parse(markdown, width: 80)
|
115
|
-
|
116
|
-
expected_output =
|
117
|
-
"\e[33m#{symbols[:top_left]}#{symbols[:line]*24}#{symbols[:top_center]}" +
|
118
|
-
"#{symbols[:line]*51}#{symbols[:top_center]}" +
|
119
|
-
"#{symbols[:line]*7}#{symbols[:top_right]}" +
|
120
|
-
"\e[0m\n" +
|
121
|
-
|
122
|
-
"\e[33m#{symbols[:pipe]} \e[0mTables " +
|
123
|
-
"\e[33m#{symbols[:pipe]}\e[0m Are " +
|
124
|
-
"\e[33m#{symbols[:pipe]}\e[0m Cool \e[33m#{symbols[:pipe]}\e[0m \n" +
|
125
|
-
|
126
|
-
"\e[33m#{symbols[:mid_left]}#{symbols[:line]*24}#{symbols[:mid_center]}" +
|
127
|
-
"#{symbols[:line]*51}#{symbols[:mid_center]}" +
|
128
|
-
"#{symbols[:line]*7}#{symbols[:mid_right]}" +
|
129
|
-
"\e[0m\n" +
|
130
|
-
|
131
|
-
"\e[33m#{symbols[:pipe]} \e[0mcol 1 is " +
|
132
|
-
"\e[33m#{symbols[:pipe]}\e[0m left-aligned " +
|
133
|
-
"\e[33m#{symbols[:pipe]}\e[0m $1600 \e[33m#{symbols[:pipe]}\e[0m \n" +
|
134
|
-
|
135
|
-
"\e[33m#{symbols[:mid_left]}#{symbols[:line]*24}#{symbols[:mid_center]}" +
|
136
|
-
"#{symbols[:line]*51}#{symbols[:mid_center]}" +
|
137
|
-
"#{symbols[:line]*7}#{symbols[:mid_right]}" +
|
138
|
-
"\e[0m\n" +
|
139
|
-
|
140
|
-
"\e[33m#{symbols[:pipe]} \e[0mcol 2 is " +
|
141
|
-
"\e[33m#{symbols[:pipe]}\e[0m centered " +
|
142
|
-
"\e[33m#{symbols[:pipe]}\e[0m $12 \e[33m#{symbols[:pipe]}\e[0m \n" +
|
143
|
-
|
144
|
-
"\e[33m#{symbols[:mid_left]}#{symbols[:line]*24}#{symbols[:mid_center]}" +
|
145
|
-
"#{symbols[:line]*51}#{symbols[:mid_center]}" +
|
146
|
-
"#{symbols[:line]*7}#{symbols[:mid_right]}" +
|
147
|
-
"\e[0m\n" +
|
148
|
-
|
149
|
-
"\e[33m#{symbols[:pipe]} \e[0mcol 3 is a multiline " +
|
150
|
-
"\e[33m#{symbols[:pipe]}\e[0m right-aligned has also a very long content that " +
|
151
|
-
"\e[33m#{symbols[:pipe]}\e[0m $1 \e[33m#{symbols[:pipe]}\e[0m \n" +
|
152
|
-
|
153
|
-
"\e[33m#{symbols[:pipe]} \e[0mcolumn " +
|
154
|
-
"\e[33m#{symbols[:pipe]}\e[0m wraps around " +
|
155
|
-
"\e[33m#{symbols[:pipe]}\e[0m \e[33m#{symbols[:pipe]}\e[0m \n" +
|
156
|
-
|
157
|
-
"\e[33m#{symbols[:bottom_left]}#{symbols[:line]*24}#{symbols[:bottom_center]}" +
|
158
|
-
"#{symbols[:line]*51}#{symbols[:bottom_center]}" +
|
159
|
-
"#{symbols[:line]*7}#{symbols[:bottom_right]}" +
|
160
|
-
"\e[0m\n"
|
161
|
-
|
162
|
-
expect(parsed).to eq(expected_output)
|
163
|
-
end
|
164
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Markdown, 'typography' do
|
4
|
-
let(:symbols) { TTY::Markdown.symbols }
|
5
|
-
|
6
|
-
it "converts header with typographic symbols" do
|
7
|
-
markdown =<<-TEXT
|
8
|
-
--- << typographic >> ... symbols --
|
9
|
-
TEXT
|
10
|
-
parsed = TTY::Markdown.parse(markdown)
|
11
|
-
expect(parsed).to eq("#{symbols[:mdash]} #{symbols[:laquo]} typographic #{symbols[:raquo]} #{symbols[:hellip]} symbols #{symbols[:ndash]}\n")
|
12
|
-
end
|
13
|
-
|
14
|
-
it "converts smart quotes to utf-8 chars" do
|
15
|
-
markdown = "To \"extract\" `script.rb`'s..."
|
16
|
-
parsed = TTY::Markdown.parse(markdown, colors: 16)
|
17
|
-
|
18
|
-
expect(parsed).to eq("To #{symbols[:ldquo]}extract#{symbols[:rdquo]} \e[33mscript.rb\e[0m#{symbols[:rsquo]}s#{symbols[:hellip]}\n")
|
19
|
-
end
|
20
|
-
end
|
data/tasks/console.rake
DELETED
data/tasks/coverage.rake
DELETED
data/tasks/spec.rake
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
begin
|
4
|
-
require 'rspec/core/rake_task'
|
5
|
-
|
6
|
-
desc 'Run all specs'
|
7
|
-
RSpec::Core::RakeTask.new(:spec) do |task|
|
8
|
-
task.pattern = 'spec/{unit,integration}{,/*/**}/*_spec.rb'
|
9
|
-
end
|
10
|
-
|
11
|
-
namespace :spec do
|
12
|
-
desc 'Run unit specs'
|
13
|
-
RSpec::Core::RakeTask.new(:unit) do |task|
|
14
|
-
task.pattern = 'spec/unit{,/*/**}/*_spec.rb'
|
15
|
-
end
|
16
|
-
|
17
|
-
desc 'Run integration specs'
|
18
|
-
RSpec::Core::RakeTask.new(:integration) do |task|
|
19
|
-
task.pattern = 'spec/integration{,/*/**}/*_spec.rb'
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
rescue LoadError
|
24
|
-
%w[spec spec:unit spec:integration].each do |name|
|
25
|
-
task name do
|
26
|
-
$stderr.puts "In order to run #{name}, do `gem install rspec`"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|