htmd 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 388f231123ba73796dd205a9f4237c50bebc7411ee55465fe953b04f201ea53f
4
+ data.tar.gz: 14befeec07f2a1fe7c8a672078deeed6b52e23129c367288718ea013e8c828b1
5
+ SHA512:
6
+ metadata.gz: 271f38c94c38cfac8164ae509c45736bea722ea0750101dd9e9e6df1f8afb90d9fc75f0f74ce4c3c60629de73dd8d85bb4ceb77c6e110a8caab0da031976fc5e
7
+ data.tar.gz: fc591144c964b51af8b0fc7fb73b3ff43db82a9971ea2847089868c6e729801e2737fba8b6f398a2f2e6203b6fb1eff42ca4789e6e7fb88641cbbd737bf36cfd
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Oren Mittman
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # htmd
2
+
3
+ Convert a markdown file to HTML and open it in your default browser. Rendering is done with [Commonmarker](https://github.com/gjtorikian/commonmarker), the HTML is written to a tempfile, and the tempfile is opened with the macOS `open` command.
4
+
5
+ Requires macOS and Ruby 3.4+.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ gem install htmd
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Pass a markdown file:
16
+
17
+ ```bash
18
+ htmd README.md
19
+ ```
20
+
21
+ Or pipe markdown on stdin:
22
+
23
+ ```bash
24
+ echo "# Hello" | htmd
25
+ ```
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at
36
+ https://github.com/nihil2501/htmd.
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the
41
+ [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task default: %i[]
data/exe/htmd ADDED
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "htmd"
4
+ require "optparse"
5
+
6
+ class NoInputError < RuntimeError
7
+ def initialize
8
+ super("no input: pass a file or pipe markdown on stdin")
9
+ end
10
+ end
11
+
12
+ def ensure_input!
13
+ if ARGV.empty? && $stdin.tty?
14
+ raise NoInputError
15
+ end
16
+ end
17
+
18
+ parser = OptionParser.new do |opts|
19
+ opts.banner = <<~BANNER
20
+ Usage: htmd [file ...]
21
+
22
+ Convert markdown to HTML and open it in your browser.
23
+ With no file, reads markdown from standard input.
24
+
25
+ BANNER
26
+
27
+ opts.on_tail("-h", "--help", "Show this help") do
28
+ puts opts
29
+ exit
30
+ end
31
+
32
+ opts.on_tail("--version", "Show version") do
33
+ puts "htmd #{Htmd::VERSION}"
34
+ exit
35
+ end
36
+ end
37
+
38
+ begin
39
+ parser.parse!
40
+ ensure_input!
41
+ Htmd.run(ARGF)
42
+ rescue OptionParser::ParseError, NoInputError, SystemCallError => e
43
+ warn "htmd: #{e}"
44
+ warn parser
45
+ exit 1
46
+ end
@@ -0,0 +1,3 @@
1
+ module Htmd
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,44 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>htmd</title>
6
+ <style>
7
+ body {
8
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
9
+ line-height: 1.5;
10
+ max-width: 48em;
11
+ margin: 2em auto;
12
+ padding: 0 2em;
13
+ }
14
+ h1, h2, h3, h4, h5, h6 { position: relative; }
15
+ a.anchor {
16
+ position: absolute;
17
+ top: 0;
18
+ bottom: 0;
19
+ left: -1.5em;
20
+ width: 1.5em;
21
+ display: flex;
22
+ align-items: center;
23
+ justify-content: flex-end;
24
+ padding-right: 0.3em;
25
+ box-sizing: border-box;
26
+ }
27
+ a.anchor::before {
28
+ --octicon-link: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"/></svg>');
29
+ content: "";
30
+ display: block;
31
+ width: 0.9em;
32
+ height: 0.9em;
33
+ background: currentColor;
34
+ -webkit-mask: var(--octicon-link) no-repeat center / contain;
35
+ mask: var(--octicon-link) no-repeat center / contain;
36
+ visibility: hidden;
37
+ }
38
+ h1:hover a.anchor::before, h2:hover a.anchor::before, h3:hover a.anchor::before,
39
+ h4:hover a.anchor::before, h5:hover a.anchor::before, h6:hover a.anchor::before,
40
+ a.anchor:focus::before { visibility: visible; }
41
+ </style>
42
+ </head>
43
+ <body></body>
44
+ </html>
data/lib/htmd.rb ADDED
@@ -0,0 +1,44 @@
1
+ require "commonmarker"
2
+ require "tempfile"
3
+
4
+ require_relative "htmd/version"
5
+
6
+ module Htmd
7
+ WRAPPER_HTML = File.read(File.expand_path("htmd/wrapper.html", __dir__))
8
+ private_constant :WRAPPER_HTML
9
+
10
+ class << self
11
+ def run(file)
12
+ file
13
+ .then { read(it) }
14
+ .then { convert(it) }
15
+ .then { write(it) }
16
+ .then { system_open(it) }
17
+ end
18
+
19
+ private
20
+
21
+ def read(file)
22
+ file.read
23
+ end
24
+
25
+ def convert(markdown)
26
+ wrap_html(Commonmarker.to_html(markdown))
27
+ end
28
+
29
+ def wrap_html(body)
30
+ WRAPPER_HTML.sub("<body></body>") { "<body>\n#{body}</body>" }
31
+ end
32
+
33
+ def write(html)
34
+ Tempfile.create(%w[converted .html]).tap do |file|
35
+ file.write(html)
36
+ file.close
37
+ end
38
+ end
39
+
40
+ def system_open(file)
41
+ system("open", file.path)
42
+ end
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: htmd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Oren Mittman
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: commonmarker
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.9'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.9'
26
+ description: Reads a markdown file, converts it to HTML with Commonmarker, writes
27
+ it to a tempfile, and opens it with the macOS `open` command.
28
+ email:
29
+ - nihil2501@gmail.com
30
+ executables:
31
+ - htmd
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - LICENSE.txt
36
+ - README.md
37
+ - Rakefile
38
+ - exe/htmd
39
+ - lib/htmd.rb
40
+ - lib/htmd/version.rb
41
+ - lib/htmd/wrapper.html
42
+ homepage: https://github.com/nihil2501/htmd
43
+ licenses:
44
+ - MIT
45
+ metadata:
46
+ allowed_push_host: https://rubygems.org
47
+ source_code_uri: https://github.com/nihil2501/htmd
48
+ rubygems_mfa_required: 'true'
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '3.4'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubygems_version: 4.0.17
64
+ specification_version: 4
65
+ summary: Convert markdown to HTML and open it.
66
+ test_files: []