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
@@ -1,130 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Markdown, 'codeblock' do
|
4
|
-
it "highlights a fenced code without language" do
|
5
|
-
markdown =<<-TEXT
|
6
|
-
```
|
7
|
-
class Greeter
|
8
|
-
def say
|
9
|
-
end
|
10
|
-
end
|
11
|
-
```
|
12
|
-
TEXT
|
13
|
-
parsed = TTY::Markdown.parse(markdown, colors: 16)
|
14
|
-
expect(parsed).to eq([
|
15
|
-
"\e[33mclass Greeter\e[0m",
|
16
|
-
"\e[33m def say\e[0m",
|
17
|
-
"\e[33m end\e[0m",
|
18
|
-
"\e[33mend\e[0m\n"
|
19
|
-
].join("\n"))
|
20
|
-
end
|
21
|
-
|
22
|
-
it "highlights code without language" do
|
23
|
-
markdown =<<-TEXT
|
24
|
-
class Greeter
|
25
|
-
def say
|
26
|
-
end
|
27
|
-
end
|
28
|
-
TEXT
|
29
|
-
parsed = TTY::Markdown.parse(markdown, colors: 16)
|
30
|
-
expect(parsed).to eq([
|
31
|
-
"\e[33mclass Greeter\e[0m",
|
32
|
-
"\e[33m def say\e[0m",
|
33
|
-
"\e[33m end\e[0m",
|
34
|
-
"\e[33mend\e[0m"
|
35
|
-
].join("\n"))
|
36
|
-
end
|
37
|
-
|
38
|
-
it "highlights fenced code according to language" do
|
39
|
-
markdown =<<-TEXT
|
40
|
-
```ruby
|
41
|
-
class Greeter
|
42
|
-
def say
|
43
|
-
end
|
44
|
-
end
|
45
|
-
```
|
46
|
-
TEXT
|
47
|
-
parsed = TTY::Markdown.parse(markdown, colors: 16)
|
48
|
-
expect(parsed).to eq([
|
49
|
-
"\e[33mclass Greeter\e[0m",
|
50
|
-
"\e[33m def say\e[0m",
|
51
|
-
"\e[33m end\e[0m",
|
52
|
-
"\e[33mend\e[0m\n"
|
53
|
-
].join("\n"))
|
54
|
-
end
|
55
|
-
|
56
|
-
it "indents immediate code correctly" do
|
57
|
-
markdown =<<-TEXT
|
58
|
-
### header
|
59
|
-
```
|
60
|
-
class Greeter
|
61
|
-
def say
|
62
|
-
end
|
63
|
-
end
|
64
|
-
```
|
65
|
-
TEXT
|
66
|
-
parsed = TTY::Markdown.parse(markdown, colors: 16)
|
67
|
-
expect(parsed).to eq([
|
68
|
-
" \e[36;1mheader\e[0m",
|
69
|
-
" \e[33mclass Greeter\e[0m",
|
70
|
-
" \e[33m def say\e[0m",
|
71
|
-
" \e[33m end\e[0m",
|
72
|
-
" \e[33mend\e[0m\n"
|
73
|
-
].join("\n"))
|
74
|
-
end
|
75
|
-
|
76
|
-
it "indents code after blank correctly" do
|
77
|
-
markdown =<<-TEXT
|
78
|
-
### header
|
79
|
-
|
80
|
-
```
|
81
|
-
class Greeter
|
82
|
-
def say
|
83
|
-
end
|
84
|
-
end
|
85
|
-
```
|
86
|
-
TEXT
|
87
|
-
parsed = TTY::Markdown.parse(markdown, colors: 16)
|
88
|
-
expect(parsed).to eq([
|
89
|
-
" \e[36;1mheader\e[0m",
|
90
|
-
"",
|
91
|
-
" \e[33mclass Greeter\e[0m",
|
92
|
-
" \e[33m def say\e[0m",
|
93
|
-
" \e[33m end\e[0m",
|
94
|
-
" \e[33mend\e[0m\n"
|
95
|
-
].join("\n"))
|
96
|
-
end
|
97
|
-
|
98
|
-
it "wraps code exceeding set width" do
|
99
|
-
markdown =<<-TEXT
|
100
|
-
```
|
101
|
-
lexer = Rouge::Lexer.find_fancy(lang, code) || Rouge::Lexers::PlainText
|
102
|
-
```
|
103
|
-
TEXT
|
104
|
-
parsed = TTY::Markdown.parse(markdown, width: 50, colors: 16)
|
105
|
-
|
106
|
-
expected_output =
|
107
|
-
"\e[33mlexer = Rouge::Lexer.find_fancy(lang, code) || \e[0m\n" +
|
108
|
-
"\e[33mRouge::Lexers::PlainText\e[0m\n"
|
109
|
-
|
110
|
-
expect(parsed).to eq(expected_output)
|
111
|
-
end
|
112
|
-
|
113
|
-
it "wraps code exceeding set width preserving indentation" do
|
114
|
-
markdown =<<-TEXT
|
115
|
-
### lexer
|
116
|
-
|
117
|
-
```
|
118
|
-
lexer = Rouge::Lexer.find_fancy(lang, code) || Rouge::Lexers::PlainText
|
119
|
-
```
|
120
|
-
TEXT
|
121
|
-
parsed = TTY::Markdown.parse(markdown, width: 50, colors: 16)
|
122
|
-
|
123
|
-
expected_output =
|
124
|
-
" \e[36;1mlexer\e[0m\n\n" +
|
125
|
-
" \e[33mlexer = Rouge::Lexer.find_fancy(lang, code) || \e[0m\n" +
|
126
|
-
" \e[33mRouge::Lexers::PlainText\e[0m\n"
|
127
|
-
|
128
|
-
expect(parsed).to eq(expected_output)
|
129
|
-
end
|
130
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Markdown, 'comment' do
|
4
|
-
it "converts xml type comment" do
|
5
|
-
markdown =<<-TEXT
|
6
|
-
text before
|
7
|
-
<!-- TODO: this is a comment -->
|
8
|
-
text after
|
9
|
-
TEXT
|
10
|
-
|
11
|
-
parsed = TTY::Markdown.parse(markdown)
|
12
|
-
|
13
|
-
expect(parsed).to eq([
|
14
|
-
"text before",
|
15
|
-
"<!-- TODO: this is a comment -->\n",
|
16
|
-
"text after\n"
|
17
|
-
].join("\n"))
|
18
|
-
end
|
19
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Markdown, 'emphasis' do
|
4
|
-
context 'when strong emphasis' do
|
5
|
-
it "converts asterisks to bold ansi codes" do
|
6
|
-
parsed = TTY::Markdown.parse("Some text with **bold** content.")
|
7
|
-
|
8
|
-
expect(parsed).to eq("Some text with \e[33;1mbold\e[0m content.\n")
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'when italics emphasis' do
|
13
|
-
it "converts asterisks to bold ansi codes" do
|
14
|
-
parsed = TTY::Markdown.parse("Some text with *italic* content.")
|
15
|
-
|
16
|
-
expect(parsed).to eq("Some text with \e[33mitalic\e[0m content.\n")
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'when strikethrough emphasis' do
|
21
|
-
it "converts two tildes to ansi codes" do
|
22
|
-
parsed = TTY::Markdown.parse("Some text with ~~scratched~~ content.")
|
23
|
-
|
24
|
-
expect(parsed).to eq("Some text with ~~scratched~~ content.\n")
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context "when backticks" do
|
29
|
-
it "convertrs backtics to ansi codes" do
|
30
|
-
parsed = TTY::Markdown.parse("Some text with `important` content.", colors: 16)
|
31
|
-
|
32
|
-
expect(parsed).to eq("Some text with \e[33mimportant\e[0m content.\n")
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Markdown, 'entity' do
|
4
|
-
it "converts html entities" do
|
5
|
-
markdown =<<-TEXT
|
6
|
-
© 2018 by me and λ
|
7
|
-
TEXT
|
8
|
-
parsed = TTY::Markdown.parse(markdown)
|
9
|
-
expect(parsed).to eq("© 2018 by me and λ\n")
|
10
|
-
end
|
11
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Markdown, 'header' do
|
4
|
-
it "converts top level header" do
|
5
|
-
parsed = TTY::Markdown.parse("#Header1")
|
6
|
-
|
7
|
-
expect(parsed).to eq("\e[36;1;4mHeader1\e[0m\n")
|
8
|
-
end
|
9
|
-
|
10
|
-
it "converts headers" do
|
11
|
-
headers =<<-TEXT
|
12
|
-
# Header1
|
13
|
-
header1 content
|
14
|
-
|
15
|
-
## Header2
|
16
|
-
header2 content
|
17
|
-
|
18
|
-
### Header3
|
19
|
-
header3 content
|
20
|
-
TEXT
|
21
|
-
parsed = TTY::Markdown.parse(headers)
|
22
|
-
|
23
|
-
expect(parsed).to eq([
|
24
|
-
"\e[36;1;4mHeader1\e[0m",
|
25
|
-
"header1 content",
|
26
|
-
"",
|
27
|
-
" \e[36;1mHeader2\e[0m",
|
28
|
-
" header2 content",
|
29
|
-
"",
|
30
|
-
" \e[36;1mHeader3\e[0m",
|
31
|
-
" header3 content\n"
|
32
|
-
].join("\n"))
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
data/spec/unit/parse/hr_spec.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Markdown, 'horizontal rule' do
|
4
|
-
let(:symbols) { TTY::Markdown.symbols }
|
5
|
-
|
6
|
-
it "draws a horizontal rule" do
|
7
|
-
markdown =<<-TEXT
|
8
|
-
---
|
9
|
-
TEXT
|
10
|
-
parsed = TTY::Markdown.parse(markdown, width: 10)
|
11
|
-
expect(parsed).to eq("\e[33m#{symbols[:diamond]}#{symbols[:line]*8}#{symbols[:diamond]}\e[0m\n")
|
12
|
-
end
|
13
|
-
|
14
|
-
it "draws a horizontal rule within header indentation" do
|
15
|
-
markdown =<<-TEXT
|
16
|
-
### header
|
17
|
-
---
|
18
|
-
TEXT
|
19
|
-
parsed = TTY::Markdown.parse(markdown, width: 20)
|
20
|
-
expect(parsed).to eq([
|
21
|
-
" \e[36;1mheader\e[0m\n",
|
22
|
-
" \e[33m#{symbols[:diamond]}#{symbols[:line]*10}#{symbols[:diamond]}\e[0m\n"
|
23
|
-
].join)
|
24
|
-
end
|
25
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Markdown, 'link' do
|
4
|
-
let(:symbols) { TTY::Markdown.symbols }
|
5
|
-
|
6
|
-
it "converts link" do
|
7
|
-
markdown =<<-TEXT
|
8
|
-
[I'm an inline-style link](https://www.google.com)
|
9
|
-
TEXT
|
10
|
-
parsed = TTY::Markdown.parse(markdown)
|
11
|
-
expect(parsed).to eq([
|
12
|
-
"I#{symbols[:rsquo]}m an inline-style link #{symbols[:arrow]} \e[33;4mhttps://www.google.com\e[0m\n"
|
13
|
-
].join)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "converts link with title" do
|
17
|
-
markdown =<<-TEXT
|
18
|
-
[I'm an inline-style link with title](https://www.google.com "Google's Homepage")
|
19
|
-
TEXT
|
20
|
-
parsed = TTY::Markdown.parse(markdown)
|
21
|
-
expect(parsed).to eq([
|
22
|
-
"Google's Homepage #{symbols[:arrow]} \e[33;4mhttps://www.google.com\e[0m\n"
|
23
|
-
].join)
|
24
|
-
end
|
25
|
-
end
|
@@ -1,103 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Markdown, 'list' do
|
4
|
-
let(:symbols) { TTY::Markdown.symbols }
|
5
|
-
let(:pastel) { Pastel.new}
|
6
|
-
|
7
|
-
it "converts unordered bulleted lists of nested items" do
|
8
|
-
markdown =<<-TEXT
|
9
|
-
- Item 1
|
10
|
-
- Item 2
|
11
|
-
- Item 3
|
12
|
-
- Item 4
|
13
|
-
- Item 5
|
14
|
-
- Item 6
|
15
|
-
TEXT
|
16
|
-
parsed = TTY::Markdown.parse(markdown)
|
17
|
-
expect(parsed).to eq([
|
18
|
-
"#{pastel.yellow(symbols[:bullet])} Item 1",
|
19
|
-
" #{pastel.yellow(symbols[:bullet])} Item 2",
|
20
|
-
" #{pastel.yellow(symbols[:bullet])} Item 3",
|
21
|
-
" #{pastel.yellow(symbols[:bullet])} Item 4",
|
22
|
-
" #{pastel.yellow(symbols[:bullet])} Item 5",
|
23
|
-
"#{pastel.yellow(symbols[:bullet])} Item 6\n"
|
24
|
-
].join("\n"))
|
25
|
-
end
|
26
|
-
|
27
|
-
it "indents unordered list" do
|
28
|
-
markdown =<<-TEXT
|
29
|
-
### header
|
30
|
-
- Item 1
|
31
|
-
- Item 2
|
32
|
-
- Item 3
|
33
|
-
- Item 4
|
34
|
-
- Item 5
|
35
|
-
- Item 6
|
36
|
-
TEXT
|
37
|
-
parsed = TTY::Markdown.parse(markdown)
|
38
|
-
expect(parsed).to eq([
|
39
|
-
" \e[36;1mheader\e[0m",
|
40
|
-
" #{pastel.yellow(symbols[:bullet])} Item 1",
|
41
|
-
" #{pastel.yellow(symbols[:bullet])} Item 2",
|
42
|
-
" #{pastel.yellow(symbols[:bullet])} Item 3",
|
43
|
-
" #{pastel.yellow(symbols[:bullet])} Item 4",
|
44
|
-
" #{pastel.yellow(symbols[:bullet])} Item 5",
|
45
|
-
" #{pastel.yellow(symbols[:bullet])} Item 6\n"
|
46
|
-
].join("\n"))
|
47
|
-
end
|
48
|
-
|
49
|
-
it "indents unordered list with multiline content" do
|
50
|
-
markdown =<<-TEXT
|
51
|
-
### header
|
52
|
-
- First multiline
|
53
|
-
Item 1
|
54
|
-
- Second multiline
|
55
|
-
Item 2
|
56
|
-
- Item 3
|
57
|
-
- Item 4
|
58
|
-
TEXT
|
59
|
-
parsed = TTY::Markdown.parse(markdown)
|
60
|
-
expect(parsed).to eq([
|
61
|
-
" \e[36;1mheader\e[0m",
|
62
|
-
" #{pastel.yellow(symbols[:bullet])} First multiline",
|
63
|
-
" Item 1",
|
64
|
-
" #{pastel.yellow(symbols[:bullet])} Second multiline",
|
65
|
-
" Item 2",
|
66
|
-
" #{pastel.yellow(symbols[:bullet])} Item 3",
|
67
|
-
" #{pastel.yellow(symbols[:bullet])} Item 4\n",
|
68
|
-
].join("\n"))
|
69
|
-
end
|
70
|
-
|
71
|
-
it "displays inline codeblocks in lists correctly" do
|
72
|
-
markdown =<<-TEXT
|
73
|
-
- Version: run `ruby -v` or `ruby --version`.
|
74
|
-
- Help: run `ruby -h` or `ruby --help`.
|
75
|
-
TEXT
|
76
|
-
|
77
|
-
parsed = TTY::Markdown.parse(markdown, colors: 16)
|
78
|
-
expect(parsed).to eq([
|
79
|
-
"#{pastel.yellow(symbols[:bullet])} Version: run \e[33mruby -v\e[0m or \e[33mruby --version\e[0m.",
|
80
|
-
"#{pastel.yellow(symbols[:bullet])} Help: run \e[33mruby -h\e[0m or \e[33mruby --help\e[0m.\n"
|
81
|
-
].join("\n"))
|
82
|
-
end
|
83
|
-
|
84
|
-
it "convert ordered numbered list of nested items" do
|
85
|
-
markdown =<<-TEXT
|
86
|
-
1. Item 1
|
87
|
-
2. Item 2
|
88
|
-
3. Item 3
|
89
|
-
4. Item 4
|
90
|
-
5. Item 5
|
91
|
-
6. Item 6
|
92
|
-
TEXT
|
93
|
-
parsed = TTY::Markdown.parse(markdown)
|
94
|
-
expect(parsed).to eq([
|
95
|
-
"#{pastel.yellow('1.')} Item 1",
|
96
|
-
" #{pastel.yellow('1.')} Item 2",
|
97
|
-
" #{pastel.yellow('2.')} Item 3",
|
98
|
-
" #{pastel.yellow('1.')} Item 4",
|
99
|
-
" #{pastel.yellow('2.')} Item 5",
|
100
|
-
"#{pastel.yellow('2.')} Item 6\n"
|
101
|
-
].join("\n"))
|
102
|
-
end
|
103
|
-
end
|
@@ -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