md-reader 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 05f44183513c5dc93bb333082f7c528e3de2e3f6ccb3d4760618d20d95ec52c0
4
- data.tar.gz: 31ac81531635c283b620339f132fba0c28fc91df3392c7f773c7adb129972deb
3
+ metadata.gz: f19af5e102c9eea366a9df28b932e1c0bebfdda9313cfb303d3b899590a60121
4
+ data.tar.gz: 22d688f9092748da05a64a201d0a2a130743abf963725ce3aa41bef26ac442b5
5
5
  SHA512:
6
- metadata.gz: 3f70219ea013ecc72a40e06d243d7ff57aa263ae648b4e590faaa4eca65875469b20ae320502cd5a27450037288cd15324c1ba76e0607b739d3cbb611bfe0e3a
7
- data.tar.gz: c25aa48ac21ee51976274869c59fcd65e7a9933fe406128e1f055f354b0f6b461fcd22f657ef80b7fe07306edffffd613fe24874b982cae6e01893ccc4a976a2
6
+ metadata.gz: 287b6f2b39fdf728c36dac8df8fb8d10580df8c8b7216dab5f1380297155216e65ec69fbf603e87937b2fd29286dcd3b5aaf40c9ddbc35034d63c878277e9d4d
7
+ data.tar.gz: 519b7e84b7c1f88e8a897980056c14679aa4fa2ba60905df8d303f4ae3d7169a1318a87cf393df3ae7afc9cec0a13364e2b2912e016664b217a72512f486198d
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Italo Matos
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # md-reader
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/md-reader.svg)](https://rubygems.org/gems/md-reader)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
5
+
6
+ A simple Ruby gem that opens Markdown files in your browser as formatted HTML.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ gem install md-reader
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ ```bash
17
+ md-reader README.md
18
+ ```
19
+
20
+ That's it. The file opens in your default browser with GitHub-like styling.
21
+
22
+ ## Features
23
+
24
+ - Syntax highlighting for fenced code blocks (Ruby, Python, JS, Go, and [200+ languages](https://rouge-ruby.github.io/docs/Rouge/Lexer.html))
25
+ - Tables, strikethrough, autolinks
26
+ - Blockquotes, footnotes
27
+ - Clean GitHub-inspired CSS — no external dependencies at runtime
28
+ - Temporary file is cleaned up automatically on exit
29
+
30
+ ## Development
31
+
32
+ ```bash
33
+ git clone https://github.com/italomatos/md-reader
34
+ cd md-reader
35
+ bundle install
36
+ bundle exec bin/md-reader test.md
37
+ ```
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork the repo
42
+ 2. Create a feature branch (`git checkout -b feature/my-feature`)
43
+ 3. Commit your changes
44
+ 4. Open a Pull Request
45
+
46
+ ## License
47
+
48
+ MIT — see [LICENSE](LICENSE).
data/bin/md-reader CHANGED
@@ -6,6 +6,27 @@ $LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
6
6
  require "md_reader"
7
7
  require "launchy"
8
8
  require "tmpdir"
9
+ require "shellwords"
10
+
11
+ # Dentro do WSL o launchy não acha browser (procura xdg-open/navegador de
12
+ # desktop Linux). Detectamos o WSL e abrimos no Windows, traduzindo o caminho
13
+ # Linux para o formato UNC (\\wsl.localhost\...) e montando uma URL file://.
14
+ def wsl?
15
+ return ENV.key?("WSL_DISTRO_NAME") if ENV.key?("WSL_DISTRO_NAME")
16
+
17
+ File.exist?("/proc/version") &&
18
+ File.read("/proc/version").downcase.include?("microsoft")
19
+ end
20
+
21
+ def open_file(path)
22
+ if wsl?
23
+ win_path = `wslpath -w #{Shellwords.escape(path)}`.strip # \\wsl.localhost\...\x.html
24
+ url = "file:#{win_path.tr('\\', '/')}" # file://wsl.localhost/...
25
+ system("explorer.exe", url) # explorer costuma retornar status != 0 mesmo em sucesso
26
+ else
27
+ Launchy.open("file://#{path}")
28
+ end
29
+ end
9
30
 
10
31
  if ARGV.empty?
11
32
  warn "Usage: md-reader <arquivo.md>"
@@ -35,6 +56,6 @@ File.write(tmp_path, html, encoding: "utf-8")
35
56
  at_exit { File.delete(tmp_path) rescue nil }
36
57
 
37
58
  puts "Abrindo #{title} no browser..."
38
- Launchy.open("file://#{tmp_path}")
59
+ open_file(tmp_path)
39
60
 
40
61
  sleep 3
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MdReader
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/md_reader.rb CHANGED
@@ -1,9 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "redcarpet"
4
+ require "rouge"
5
+ require "rouge/plugins/redcarpet"
4
6
  require "md_reader/version"
5
7
 
6
8
  module MdReader
9
+ class HTMLWithHighlight < Redcarpet::Render::HTML
10
+ include Rouge::Plugins::Redcarpet
11
+ end
12
+
7
13
  class Converter
8
14
  MARKDOWN_EXTENSIONS = {
9
15
  fenced_code_blocks: true,
@@ -17,7 +23,7 @@ module MdReader
17
23
  }.freeze
18
24
 
19
25
  def call(content, title = "Document")
20
- renderer = Redcarpet::Render::HTML.new(hard_wrap: true, with_toc_data: true)
26
+ renderer = HTMLWithHighlight.new(hard_wrap: true, with_toc_data: true)
21
27
  markdown = Redcarpet::Markdown.new(renderer, MARKDOWN_EXTENSIONS)
22
28
  body = markdown.render(content)
23
29
  html_template(body, title)
@@ -25,6 +31,10 @@ module MdReader
25
31
 
26
32
  private
27
33
 
34
+ def highlight_css
35
+ Rouge::Themes::Github.render(scope: ".highlight")
36
+ end
37
+
28
38
  def html_template(body, title)
29
39
  <<~HTML
30
40
  <!DOCTYPE html>
@@ -87,6 +97,23 @@ module MdReader
87
97
  font-size: 100%;
88
98
  }
89
99
 
100
+ .highlight {
101
+ font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
102
+ font-size: 85%;
103
+ background: #f6f8fa;
104
+ border-radius: 6px;
105
+ padding: 1rem;
106
+ overflow: auto;
107
+ line-height: 1.45;
108
+ margin-bottom: 1rem;
109
+ }
110
+ .highlight pre {
111
+ margin: 0;
112
+ padding: 0;
113
+ background: transparent;
114
+ border-radius: 0;
115
+ }
116
+
90
117
  blockquote {
91
118
  margin: 0 0 1rem 0;
92
119
  padding: 0 1em;
@@ -130,6 +157,8 @@ module MdReader
130
157
  }
131
158
 
132
159
  mark { background: #fff3b8; border-radius: 2px; padding: 0.1em 0.2em; }
160
+
161
+ #{highlight_css}
133
162
  </style>
134
163
  </head>
135
164
  <body>
data/md_reader.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
11
11
  gem.email = ["italomatos@gmail.com"]
12
12
  gem.license = "MIT"
13
13
 
14
- gem.files = Dir["lib/**/*.rb"] + %w[md_reader.gemspec]
14
+ gem.files = Dir["lib/**/*.rb"] + %w[md_reader.gemspec README.md LICENSE]
15
15
  gem.executables = ["md-reader"]
16
16
  gem.require_paths = ["lib"]
17
17
 
@@ -19,4 +19,5 @@ Gem::Specification.new do |gem|
19
19
 
20
20
  gem.add_dependency "redcarpet", "~> 3.6"
21
21
  gem.add_dependency "launchy", "~> 2.5"
22
+ gem.add_dependency "rouge", "~> 4.0"
22
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: md-reader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Italo Matos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-06-11 00:00:00.000000000 Z
11
+ date: 2026-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rouge
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.0'
41
55
  description: Comando de terminal que converte Markdown em HTML com estilo GitHub e
42
56
  abre no browser.
43
57
  email:
@@ -47,6 +61,8 @@ executables:
47
61
  extensions: []
48
62
  extra_rdoc_files: []
49
63
  files:
64
+ - LICENSE
65
+ - README.md
50
66
  - bin/md-reader
51
67
  - lib/md_reader.rb
52
68
  - lib/md_reader/version.rb