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.
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- if ENV['COVERAGE'] || ENV['TRAVIS']
4
- require 'simplecov'
5
- require 'coveralls'
6
-
7
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
8
- SimpleCov::Formatter::HTMLFormatter,
9
- Coveralls::SimpleCov::Formatter
10
- ]
11
-
12
- SimpleCov.start do
13
- command_name 'spec'
14
- add_filter 'spec'
15
- end
16
- end
17
-
18
- require "bundler/setup"
19
- require "tty/markdown"
20
-
21
- RSpec.configure do |config|
22
- # Enable flags like --only-failures and --next-failure
23
- config.example_status_persistence_file_path = ".rspec_status"
24
-
25
- # Disable RSpec exposing methods globally on `Module` and `main`
26
- config.disable_monkey_patching!
27
-
28
- config.expect_with :rspec do |c|
29
- c.syntax = :expect
30
- end
31
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Markdown, 'abbrev' do
4
- it "abbreviates markdown" do
5
- markdown =<<-TEXT
6
- *[HTML]: Hyper Text Markup Language
7
- test HTML
8
- TEXT
9
- parsed = TTY::Markdown.parse(markdown)
10
- expect(parsed).to eq([
11
- "test HTML\n"
12
- ].join("\n"))
13
- end
14
-
15
- it "indents abbreviations correctly" do
16
- markdown =<<-TEXT
17
- ### header
18
- *[HTML]: Hyper Text Markup Language
19
- test HTML
20
- TEXT
21
- parsed = TTY::Markdown.parse(markdown)
22
- expect(parsed).to eq([
23
- " \e[36;1mheader\e[0m",
24
- " test HTML\n"
25
- ].join("\n"))
26
- end
27
- end
@@ -1,77 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Markdown, 'blockquote' do
4
- let(:bar) { TTY::Markdown.symbols[:bar] }
5
- let(:apos) { TTY::Markdown.symbols[:rsquo] }
6
-
7
- it "converts single blockquote" do
8
- markdown =<<-TEXT
9
- > Oh, you can *put* **Markdown** into a blockquote.
10
- TEXT
11
- parsed = TTY::Markdown.parse(markdown)
12
- expect(parsed).to eq([
13
- "\e[33m#{bar}\e[0m Oh, you can \e[33mput\e[0m \e[33;1mMarkdown\e[0m into a blockquote.\n"
14
- ].join)
15
- end
16
-
17
- it "indents blockquote within header" do
18
- markdown =<<-TEXT
19
- ### Quote
20
- > Oh, you can *put* **Markdown** into a blockquote.
21
- TEXT
22
- parsed = TTY::Markdown.parse(markdown)
23
- expect(parsed).to eq([
24
- " \e[36;1mQuote\e[0m",
25
- " \e[33m#{bar}\e[0m Oh, you can \e[33mput\e[0m \e[33;1mMarkdown\e[0m into a blockquote.\n"
26
- ].join("\n"))
27
- end
28
-
29
- it "converts multiple blockquotes without header" do
30
- markdown =<<-TEXT
31
- > one
32
- > two
33
- > three
34
- TEXT
35
- parsed = TTY::Markdown.parse(markdown)
36
- expected_output =
37
- "\e[33m#{bar}\e[0m one\n" +
38
- "\e[33m#{bar}\e[0m two\n" +
39
- "\e[33m#{bar}\e[0m three\n"
40
-
41
- expect(parsed).to eq(expected_output)
42
- end
43
-
44
- it "converts multiple blockquote" do
45
- markdown =<<-TEXT
46
- ### Quote
47
- > Blockquotes are very handy in email to emulate reply text.
48
- > This line is part of the same quote.
49
- > *Oh*, you can put **Markdown** into a blockquote.
50
- TEXT
51
- parsed = TTY::Markdown.parse(markdown)
52
- expect(parsed).to eq([
53
- " \e[36;1mQuote\e[0m\n",
54
- " \e[33m#{bar}\e[0m Blockquotes are very handy in email to emulate reply text.\n",
55
- " \e[33m#{bar}\e[0m This line is part of the same quote.\n",
56
- " \e[33m#{bar}\e[0m \e[33mOh\e[0m, you can put \e[33;1mMarkdown\e[0m into a blockquote.\n"
57
- ].join)
58
- end
59
-
60
- it "converts blockquote into lines" do
61
- markdown =<<-TEXT
62
- > This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can *put* **Markdown** into a blockquote.
63
- > Last line to ensure all is fine.
64
- TEXT
65
-
66
- parsed = TTY::Markdown.parse(markdown, width: 50)
67
- expected_output =
68
- "\e[33m#{bar}\e[0m This is a very long line that will still be \n" +
69
- "\e[33m#{bar}\e[0m quoted properly when it wraps. Oh boy let\n" +
70
- "\e[33m#{bar}\e[0m #{apos}s keep writing to make sure this is long enough \n" +
71
- "\e[33m#{bar}\e[0m to actually wrap for everyone. Oh, you can \n" +
72
- "\e[33m#{bar}\e[0m \e[33mput\e[0m \e[33;1mMarkdown\e[0m into a blockquote.\n" +
73
- "\e[33m#{bar}\e[0m Last line to ensure all is fine.\n"
74
-
75
- expect(parsed).to eq(expected_output)
76
- end
77
- end
@@ -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
- &copy; 2018 by me and &#x3bb;
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
-
@@ -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