red_quilt 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45de1415fe8cc64323b390d8cedc4d6691fa6c0ab17337fac8aa956cef8bd107
4
- data.tar.gz: c3392372dd65fe74149678dbb9b5ebc8cc389b6f44ca4b0013e6eadfd565568d
3
+ metadata.gz: 97ab1d8ff3dcb3278403b6f85fba5c49bfef8fa9fa2aceac979873fd580260ba
4
+ data.tar.gz: b604fecab6bf8f3e3ab06a768cc3625e7adbcca3f256334efcf7c9c2e1c4fcd8
5
5
  SHA512:
6
- metadata.gz: c7f3c0226e9a2e2cac06273147dfd497f45566ba99d766cee30ccd6fbff728669ab1d9ab112c93de33cce405e2cea9c8789e4f431a70c10d546e2bc2309c8c5b
7
- data.tar.gz: 69cae77089c64fbf8821cc6340e0c0ad8749004fbf03ec5acf1b55daa388404db5a64a276f48267ab9e58a66a21eb2892b9f120b942e105930862c94e29de7fe
6
+ metadata.gz: 2709412545b3b9c28752f6da004781bcf628874db68eea0753231951f3c73a89a5bdadf9250e7940db77f1e8d4d5dca89bd4ed04c428c4f764fcdb7d278baf85
7
+ data.tar.gz: 27568989536531184a37814fd84b81961887ddfc4de9de3cc05de6135930833a06578cb36c8ffff3f9f95abd6dd7c4ad6894281b7f72a2f8e33ef65fb583e44c
data/README.md CHANGED
@@ -137,6 +137,12 @@ redquilt --extended-autolinks --footnotes input.md
137
137
 
138
138
  # Standalone page with the bare template (no embedded CSS)
139
139
  redquilt --theme none input.md
140
+
141
+ # Write HTML to a file instead of stdout
142
+ redquilt -o output.html input.md
143
+
144
+ # Render and open the result in the default browser
145
+ redquilt --open input.md
140
146
  ```
141
147
 
142
148
  ### Options
@@ -154,6 +160,10 @@ redquilt --theme none input.md
154
160
  --lang LANG html lang attribute (default: "en")
155
161
  --css URL Add a stylesheet link
156
162
  --theme THEME Embedded stylesheet: default (default) or none
163
+ -o, --output FILE Write HTML to FILE instead of stdout
164
+ --open Write HTML to a file and open it in the default
165
+ browser (forces --standalone; uses a file under
166
+ Dir.tmpdir when -o is not given)
157
167
  --diagnostics Print diagnostics to stderr
158
168
  --diagnostics-only Print diagnostics only (suppress output)
159
169
  -h, --help Show help
@@ -45,11 +45,11 @@ CommonMark§2.3/2.4の最小前処理。`\r\n`/`\r`→`\n`の行末正規化と
45
45
  - 桁計算: タブ展開を含むインデント計算は`Indentation`に委譲。
46
46
  - 出力: inline未解決のblockノードをArenaに構築する。
47
47
 
48
- ### InlinePass / Lexer / Builder
48
+ ### InlinePass / Inline::Lexer / Inline::Builder
49
49
  - 対象選定: paragraph / heading / table cellの各inline targetを走査して処理。
50
50
  - Lexer: targetのbyte span、またはstr1 literalの範囲をスキャンしTokens(parallel array)へ。
51
- - Builder①linear pass: code span / link / image / autolink / 簡易inlineを解決。
52
- - Builder②process_emphasis: delimiter stackを畳んでemphasis / strong / strikethroughを確定(CommonMark§6.2、strikethroughはGFM拡張)。
51
+ - Builder① linear_pass: code span / link / image / autolink / 簡易inlineを解決。
52
+ - Builder② process_emphasis: delimiter stackを畳んでemphasis / strong / strikethroughを確定(CommonMark§6.2、strikethroughはGFM拡張)。
53
53
  - footnote参照: `[^label]`を`FootnoteRegistry`で解決し、初回参照順に採番して`FOOTNOTE_REFERENCE`を生成。
54
54
 
55
55
  ### FootnotePass (`footnotes: true`)
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rbconfig"
4
+
5
+ module RedQuilt
6
+ # Opens a local HTML file in the OS default browser when `--open` is set.
7
+ # Best-effort: unsupported platforms or spawn failures are logged but
8
+ # never abort the CLI.
9
+ class BrowserLauncher
10
+ def initialize(err:)
11
+ @err = err
12
+ end
13
+
14
+ def launch(path)
15
+ command = platform_command
16
+ unless command
17
+ @err.puts "redquilt: --open is not supported on this platform; skipping."
18
+ return
19
+ end
20
+
21
+ pid = Process.spawn(*command, path, in: :close, out: File::NULL, err: File::NULL)
22
+ Process.detach(pid)
23
+ rescue StandardError => e
24
+ @err.puts "redquilt: failed to open browser: #{e.message}"
25
+ end
26
+
27
+ private
28
+
29
+ def platform_command
30
+ case RbConfig::CONFIG["host_os"]
31
+ when /darwin/ then ["open"]
32
+ when /linux|bsd/ then ["xdg-open"]
33
+ when /mswin|mingw|cygwin/ then ["cmd.exe", "/c", "start", ""]
34
+ end
35
+ end
36
+ end
37
+ end
data/lib/red_quilt/cli.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "optparse"
4
+ require "tmpdir"
4
5
  require "red_quilt"
6
+ require "red_quilt/browser_launcher"
5
7
 
6
8
  module RedQuilt
7
9
  # Entry point for the `redquilt` executable. Defined as a module-level
@@ -34,6 +36,8 @@ module RedQuilt
34
36
  lang: "en",
35
37
  css: nil,
36
38
  theme: :default,
39
+ output: nil,
40
+ open: false,
37
41
  }.freeze
38
42
 
39
43
  THEMES = %i[none default].freeze
@@ -44,6 +48,13 @@ module RedQuilt
44
48
  options = parse_options(argv, stderr: stderr)
45
49
  return options if options.is_a?(Integer)
46
50
 
51
+ if options[:open] && options[:format] != :html
52
+ stderr.puts "redquilt: --open requires --format html"
53
+ return 1
54
+ end
55
+ options[:standalone] = true if options[:open]
56
+
57
+ source_path = argv.first
47
58
  source = read_source(argv, stdin: stdin, stderr: stderr)
48
59
  return 1 unless source
49
60
 
@@ -54,15 +65,7 @@ module RedQuilt
54
65
  lint: options[:lint])
55
66
 
56
67
  unless options[:diagnostics_only]
57
- case options[:format]
58
- when :html
59
- stdout.write(render_html(doc, options))
60
- when :ast
61
- require "pp"
62
- PP.pp(doc.to_ast, stdout)
63
- when :json
64
- stdout.puts doc.to_json
65
- end
68
+ emit_output(doc, options, source_path: source_path, stdout: stdout, stderr: stderr)
66
69
  end
67
70
 
68
71
  if options[:diagnostics] || options[:diagnostics_only]
@@ -72,6 +75,35 @@ module RedQuilt
72
75
  doc.diagnostics.any? { |d| d.severity == :error } ? 1 : 0
73
76
  end
74
77
 
78
+ def self.emit_output(doc, options, source_path:, stdout:, stderr:)
79
+ destination = output_destination(options, source_path)
80
+
81
+ case options[:format]
82
+ when :html
83
+ html = render_html(doc, options)
84
+ if destination
85
+ File.write(destination, html)
86
+ else
87
+ stdout.write(html)
88
+ end
89
+ when :ast
90
+ require "pp"
91
+ PP.pp(doc.to_ast, stdout)
92
+ when :json
93
+ stdout.puts doc.to_json
94
+ end
95
+
96
+ BrowserLauncher.new(err: stderr).launch(destination) if options[:open] && destination
97
+ end
98
+
99
+ def self.output_destination(options, source_path)
100
+ return options[:output] if options[:output]
101
+ return nil unless options[:open]
102
+
103
+ base = source_path ? File.basename(source_path, ".*") : "stdin"
104
+ File.join(Dir.tmpdir, "redquilt-#{base}.html")
105
+ end
106
+
75
107
  def self.parse_options(argv, stderr:)
76
108
  options = DEFAULTS.dup
77
109
  parser = OptionParser.new do |opts|
@@ -115,6 +147,13 @@ module RedQuilt
115
147
  "Embedded stylesheet: default (the default) or none (bare HTML)") do |t|
116
148
  options[:theme] = t
117
149
  end
150
+ opts.on("-o", "--output FILE", "Write HTML to FILE instead of stdout") do |f|
151
+ options[:output] = f
152
+ end
153
+ opts.on("--open",
154
+ "Write HTML to a file and open it in the default browser (forces --standalone)") do
155
+ options[:open] = true
156
+ end
118
157
  opts.on("--diagnostics", "Also print diagnostics to stderr") do
119
158
  options[:diagnostics] = true
120
159
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RedQuilt
4
- VERSION = "0.7.0"
4
+ VERSION = "0.7.1"
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: red_quilt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - takahashim
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2026-05-29 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: A modern Markdown document processor in pure Ruby, with an arena-style
13
13
  AST and full CommonMark spec test suite compliance.
@@ -33,6 +33,7 @@ files:
33
33
  - lib/red_quilt/arena.rb
34
34
  - lib/red_quilt/block_parser.rb
35
35
  - lib/red_quilt/blockquote.rb
36
+ - lib/red_quilt/browser_launcher.rb
36
37
  - lib/red_quilt/cli.rb
37
38
  - lib/red_quilt/diagnostic.rb
38
39
  - lib/red_quilt/document.rb
@@ -90,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
91
  - !ruby/object:Gem::Version
91
92
  version: '0'
92
93
  requirements: []
93
- rubygems_version: 3.6.2
94
+ rubygems_version: 4.0.10
94
95
  specification_version: 4
95
96
  summary: CommonMark-based Markdown processor written in pure Ruby
96
97
  test_files: []