tty-markdown 0.3.0 → 0.7.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.
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "kramdown/parser/kramdown"
4
+
5
+ module Kramdown
6
+ module Parser
7
+ class KramdownExt < Kramdown::Parser::Kramdown
8
+ def initialize(source, options)
9
+ super
10
+
11
+ { codeblock_fenced: :codeblock_fenced_ext }.each do |current, replacement|
12
+ @block_parsers[@block_parsers.index(current)] = replacement
13
+ end
14
+ end
15
+
16
+ FENCED_CODEBLOCK_START = /^[ ]{0,3}[~`]{3,}/.freeze
17
+ FENCED_CODEBLOCK_MATCH = /^[ ]{0,3}(([~`]){3,})\s*?((\S+?)(?:\?\S*)?)?\s*?\n(.*?)^[ ]{0,3}\1\2*\s*?\n/m.freeze
18
+
19
+ define_parser(:codeblock_fenced_ext, FENCED_CODEBLOCK_START, nil,
20
+ "parse_codeblock_fenced")
21
+ end # KramdownExt
22
+ end # Parser
23
+ end # TTY
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'pastel'
4
- require 'rouge'
5
- require 'tty-color'
3
+ require "pastel"
4
+ require "rouge"
6
5
 
7
6
  module TTY
8
7
  module Markdown
@@ -32,33 +31,38 @@ module TTY
32
31
  #
33
32
  # @api private
34
33
  def guess_lang(code)
35
- lang = nil
36
34
  start_line = code.lines[0]
37
35
  if available_lexers.include?(start_line.strip.downcase)
38
- lang = start_line.strip.downcase
36
+ start_line.strip.downcase
39
37
  end
40
38
  end
41
39
  module_function :guess_lang
42
40
 
43
41
  # Highlight code snippet
44
42
  #
43
+ # @param [String] code
44
+ # @param [Integer] mode
45
+ # the color mode supported by the terminal
46
+ # @param [String] lang
47
+ # the code snippet language
48
+ # @param [Boolean] enabled
49
+ # whether or not coloring is enabled
50
+ # @param [Proc] color
51
+ # the fallback coloring
52
+ #
45
53
  # @api public
46
- def highlight(code, **options)
47
- lang = guess_lang(code)
48
- mode = options[:mode] || TTY::Color.mode
49
- lines = code.dup.lines
50
- if options[:fenced].nil?
51
- code = lines[1...-1].join + lines[-1].strip
52
- end
53
-
54
+ def highlight(code, mode: 256, lang: nil, enabled: nil,
55
+ color: ->(line) { line })
56
+ lang = guess_lang(code) if lang.nil?
54
57
  lexer = Rouge::Lexer.find_fancy(lang, code) || Rouge::Lexers::PlainText
55
58
 
56
- if mode >= 256
59
+ if enabled == false
60
+ code
61
+ elsif 256 <= mode
57
62
  formatter = Rouge::Formatters::Terminal256.new
58
63
  formatter.format(lexer.lex(code))
59
64
  else
60
- pastel = Pastel.new
61
- code.split("\n").map { |line| pastel.yellow(line) }.join("\n")
65
+ code.lines.map { |line| color.(line.chomp) }.join("\n")
62
66
  end
63
67
  end
64
68
  module_function :highlight
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TTY
2
4
  module Markdown
3
- VERSION = '0.3.0'.freeze
5
+ VERSION = "0.7.0"
4
6
  end # TTY
5
7
  end # Markdown
metadata CHANGED
@@ -1,183 +1,162 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tty-markdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Murach
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-17 00:00:00.000000000 Z
11
+ date: 2020-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.16.2
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: 1.16.2
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: pastel
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - "~>"
32
38
  - !ruby/object:Gem::Version
33
- version: 0.7.2
39
+ version: '0.8'
34
40
  type: :runtime
35
41
  prerelease: false
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
44
  - - "~>"
39
45
  - !ruby/object:Gem::Version
40
- version: 0.7.2
46
+ version: '0.8'
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: rouge
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
51
  - - "~>"
46
52
  - !ruby/object:Gem::Version
47
- version: 3.1.0
53
+ version: '3.14'
48
54
  type: :runtime
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
58
  - - "~>"
53
59
  - !ruby/object:Gem::Version
54
- version: 3.1.0
60
+ version: '3.14'
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: strings
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
65
  - - "~>"
60
66
  - !ruby/object:Gem::Version
61
- version: 0.1.0
67
+ version: 0.2.0
62
68
  type: :runtime
63
69
  prerelease: false
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
66
72
  - - "~>"
67
73
  - !ruby/object:Gem::Version
68
- version: 0.1.0
74
+ version: 0.2.0
69
75
  - !ruby/object:Gem::Dependency
70
76
  name: tty-color
71
77
  requirement: !ruby/object:Gem::Requirement
72
78
  requirements:
73
79
  - - "~>"
74
80
  - !ruby/object:Gem::Version
75
- version: 0.4.2
81
+ version: '0.5'
76
82
  type: :runtime
77
83
  prerelease: false
78
84
  version_requirements: !ruby/object:Gem::Requirement
79
85
  requirements:
80
86
  - - "~>"
81
87
  - !ruby/object:Gem::Version
82
- version: 0.4.2
88
+ version: '0.5'
83
89
  - !ruby/object:Gem::Dependency
84
90
  name: tty-screen
85
91
  requirement: !ruby/object:Gem::Requirement
86
92
  requirements:
87
93
  - - "~>"
88
94
  - !ruby/object:Gem::Version
89
- version: 0.6.4
95
+ version: '0.8'
90
96
  type: :runtime
91
97
  prerelease: false
92
98
  version_requirements: !ruby/object:Gem::Requirement
93
99
  requirements:
94
100
  - - "~>"
95
101
  - !ruby/object:Gem::Version
96
- version: 0.6.4
97
- - !ruby/object:Gem::Dependency
98
- name: bundler
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '1.16'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '1.16'
102
+ version: '0.8'
111
103
  - !ruby/object:Gem::Dependency
112
104
  name: rake
113
105
  requirement: !ruby/object:Gem::Requirement
114
106
  requirements:
115
- - - "~>"
107
+ - - ">="
116
108
  - !ruby/object:Gem::Version
117
- version: '10.0'
109
+ version: '0'
118
110
  type: :development
119
111
  prerelease: false
120
112
  version_requirements: !ruby/object:Gem::Requirement
121
113
  requirements:
122
- - - "~>"
114
+ - - ">="
123
115
  - !ruby/object:Gem::Version
124
- version: '10.0'
116
+ version: '0'
125
117
  - !ruby/object:Gem::Dependency
126
118
  name: rspec
127
119
  requirement: !ruby/object:Gem::Requirement
128
120
  requirements:
129
- - - "~>"
121
+ - - ">="
130
122
  - !ruby/object:Gem::Version
131
123
  version: '3.0'
132
124
  type: :development
133
125
  prerelease: false
134
126
  version_requirements: !ruby/object:Gem::Requirement
135
127
  requirements:
136
- - - "~>"
128
+ - - ">="
137
129
  - !ruby/object:Gem::Version
138
130
  version: '3.0'
139
131
  description: Convert a markdown text or document into a terminal friendly output.
140
- email: []
132
+ email:
133
+ - piotr@piotrmurach.com
141
134
  executables: []
142
135
  extensions: []
143
- extra_rdoc_files: []
136
+ extra_rdoc_files:
137
+ - README.md
138
+ - CHANGELOG.md
139
+ - LICENSE.txt
144
140
  files:
145
- - ".gitignore"
146
- - ".rspec"
147
- - ".travis.yml"
148
141
  - CHANGELOG.md
149
- - CODE_OF_CONDUCT.md
150
- - Gemfile
151
142
  - LICENSE.txt
152
143
  - README.md
153
- - Rakefile
154
- - appveyor.yml
155
- - assets/headers.png
156
- - assets/hr.png
157
- - assets/link.png
158
- - assets/list.png
159
- - assets/quote.png
160
- - assets/syntax_highlight.png
161
- - assets/table.png
162
- - bin/console
163
- - bin/setup
164
- - examples/example.md
165
- - examples/man.md
166
- - examples/man.rb
167
- - examples/marked.rb
168
144
  - lib/tty-markdown.rb
169
145
  - lib/tty/markdown.rb
170
- - lib/tty/markdown/parser.rb
146
+ - lib/tty/markdown/converter.rb
147
+ - lib/tty/markdown/kramdown_ext.rb
171
148
  - lib/tty/markdown/syntax_highlighter.rb
172
149
  - lib/tty/markdown/version.rb
173
- - tasks/console.rake
174
- - tasks/coverage.rake
175
- - tasks/spec.rake
176
- - tty-markdown.gemspec
177
- homepage: https://piotrmurach.github.io/tty
150
+ homepage: https://ttytoolkit.org
178
151
  licenses:
179
152
  - MIT
180
- metadata: {}
153
+ metadata:
154
+ allowed_push_host: https://rubygems.org
155
+ bug_tracker_uri: https://github.com/piotrmurach/tty-markdown/issues
156
+ changelog_uri: https://github.com/piotrmurach/tty-markdown/blob/master/CHANGELOG.md
157
+ documentation_uri: https://www.rubydoc.info/gems/tty-markdown
158
+ homepage_uri: https://ttytoolkit.org
159
+ source_code_uri: https://github.com/piotrmurach/tty-markdown
181
160
  post_install_message:
182
161
  rdoc_options: []
183
162
  require_paths:
@@ -193,8 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
172
  - !ruby/object:Gem::Version
194
173
  version: '0'
195
174
  requirements: []
196
- rubyforge_project:
197
- rubygems_version: 2.5.1
175
+ rubygems_version: 3.1.2
198
176
  signing_key:
199
177
  specification_version: 4
200
178
  summary: Convert a markdown text or document into a terminal friendly output.
data/.gitignore DELETED
@@ -1,12 +0,0 @@
1
- /.bundle/
2
- /Gemfile.lock
3
- /.yardoc
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
-
11
- # rspec failure tracking
12
- .rspec_status
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
@@ -1,23 +0,0 @@
1
- ---
2
- language: ruby
3
- sudo: false
4
- cache: bundler
5
- before_install: "gem update bundler"
6
- script: "bundle exec rake ci"
7
- rvm:
8
- - 2.0.0
9
- - 2.1.10
10
- - 2.2.8
11
- - 2.3.6
12
- - 2.4.3
13
- - 2.5.0
14
- - ruby-head
15
- - jruby-9000
16
- - jruby-head
17
- matrix:
18
- allow_failures:
19
- - rvm: ruby-head
20
- - rvm: jruby-head
21
- fast_finish: true
22
- branches:
23
- only: master
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at [email]. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/