micron_markup 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: 10fbacd5dda2ab831b8dd3f24217590dcd74b46ea422da322cbd1919029de206
4
+ data.tar.gz: caed600059968c7ba9b69db4e0e99d0096ef615ff1caa0cec50727dfed0626ad
5
+ SHA512:
6
+ metadata.gz: 4df8e3c4a20ee04701d6a5bd55c5ff36cc15dfc0b6ac29638bedcb5f88cf3348348e049e1dd02ce84098481a2d7b098cbe4948d3e15c09e093d2899627942919
7
+ data.tar.gz: 1577d2157e9720508934e5c3f80dc4fa3d1d33344852300f967a721cfc9d9a66a773d9f1c24d195e910aa3c40a955c2ac9b16721fef73cc50135b05cfb9c9438
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2026-02-02
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at xorgnak@xorgnak.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in micron_markup.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Erik Olson
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,37 @@
1
+ # MicronMarkup
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/micron_markup`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add micron_markup
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install micron_markup
16
+
17
+ ## Usage
18
+
19
+ TODO: Write usage instructions here
20
+
21
+ ## Development
22
+
23
+ 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.
24
+
25
+ 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).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/micron_markup. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/micron_markup/blob/master/CODE_OF_CONDUCT.md).
30
+
31
+ ## License
32
+
33
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
34
+
35
+ ## Code of Conduct
36
+
37
+ Everyone interacting in the MicronMarkup project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/micron_markup/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MicronMarkup
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,616 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'colorize'
4
+ require 'cgi'
5
+
6
+ require_relative "micron_markup/version"
7
+
8
+ module MicronMarkup
9
+ class Error < StandardError; end
10
+ class Renderer
11
+ ANSI_COLORS = {
12
+ '0' => :black, '1' => :red, '2' => :green, '3' => :yellow,
13
+ '4' => :blue, '5' => :magenta, '6' => :cyan, '7' => :white,
14
+ '8' => :light_black, '9' => :light_red, 'a' => :light_green,
15
+ 'b' => :light_yellow, 'c' => :light_blue, 'd' => :light_magenta,
16
+ 'e' => :light_cyan, 'f' => :light_white
17
+ }
18
+
19
+ def initialize(source)
20
+ @source = source
21
+ @lines = source.split("\n")
22
+ reset_state
23
+ end
24
+
25
+ def reset_state
26
+ @state = {
27
+ bold: false,
28
+ italic: false,
29
+ underline: false,
30
+ foreground: nil,
31
+ background: nil,
32
+ alignment: :left,
33
+ section_level: 0,
34
+ in_literal: false,
35
+ literal_content: []
36
+ }
37
+ end
38
+
39
+ # render micron as html
40
+ def to_html
41
+ reset_state
42
+ output = ['<div class="micron-content">']
43
+
44
+ @lines.each do |line|
45
+ output << process_line_html(line)
46
+ end
47
+
48
+ output << '</div>'
49
+ output.join("\n")
50
+ end
51
+
52
+ # render micron as terminal text
53
+ def to_text
54
+ reset_state
55
+ output = []
56
+
57
+ @lines.each do |line|
58
+ output << process_line_text(line)
59
+ end
60
+
61
+ output.join("\n")
62
+ end
63
+
64
+ private
65
+
66
+ def process_line_html(line)
67
+ # Handle literal blocks
68
+ if line.start_with?('`=')
69
+ @state[:in_literal] = !@state[:in_literal]
70
+ if @state[:in_literal]
71
+ @state[:literal_content] = []
72
+ return '<pre class="literal">'
73
+ else
74
+ content = @state[:literal_content].join("\n")
75
+ @state[:literal_content] = []
76
+ return "#{CGI.escapeHTML(content)}</pre>"
77
+ end
78
+ end
79
+
80
+ if @state[:in_literal]
81
+ @state[:literal_content] << line
82
+ return ''
83
+ end
84
+
85
+ # Handle comments
86
+ return '' if line.start_with?('#')
87
+
88
+ # Handle dividers
89
+ return '<hr>' if line =~ /^-[∿~]?$/
90
+
91
+ # Handle sections
92
+ if line =~ /^(>+)(.*)$/
93
+ level = $1.length
94
+ heading = $2.strip
95
+ @state[:section_level] = level
96
+
97
+ if heading.empty?
98
+ return "<div class=\"section section-#{level}\">"
99
+ else
100
+ processed_heading = process_inline_html(heading)
101
+ return "<h#{[level, 6].min} class=\"section-heading\">#{processed_heading}</h#{[level, 6].min}>"
102
+ end
103
+ end
104
+
105
+ # Handle alignment
106
+ case line
107
+ when /^`c/
108
+ @state[:alignment] = :center
109
+ line = line[2..-1]
110
+ when /^`l/
111
+ @state[:alignment] = :left
112
+ line = line[2..-1]
113
+ when /^`r/
114
+ @state[:alignment] = :right
115
+ line = line[2..-1]
116
+ when /^`a/
117
+ @state[:alignment] = :left
118
+ line = line[2..-1]
119
+ end
120
+
121
+ return '' if line.strip.empty?
122
+
123
+ processed = process_inline_html(line)
124
+ align_class = case @state[:alignment]
125
+ when :center then ' class="align-center"'
126
+ when :right then ' class="align-right"'
127
+ else ''
128
+ end
129
+
130
+ "<p#{align_class}>#{processed}</p>"
131
+ end
132
+
133
+ def process_inline_html(text)
134
+ result = ''
135
+ i = 0
136
+ current_styles = []
137
+
138
+ while i < text.length
139
+ if text[i] == '\\' && i + 1 < text.length
140
+ # Escaped character
141
+ result << CGI.escapeHTML(text[i + 1])
142
+ i += 2
143
+ next
144
+ end
145
+
146
+ if text[i] == '`' && i + 1 < text.length
147
+ tag = text[i + 1]
148
+
149
+ case tag
150
+ when '!'
151
+ # Bold
152
+ if current_styles.include?(:bold)
153
+ result << '</strong>'
154
+ current_styles.delete(:bold)
155
+ else
156
+ result << '<strong>'
157
+ current_styles << :bold
158
+ end
159
+ i += 2
160
+ when '_'
161
+ # Underline
162
+ if current_styles.include?(:underline)
163
+ result << '</u>'
164
+ current_styles.delete(:underline)
165
+ else
166
+ result << '<u>'
167
+ current_styles << :underline
168
+ end
169
+ i += 2
170
+ when '*'
171
+ # Italic
172
+ if current_styles.include?(:italic)
173
+ result << '</em>'
174
+ current_styles.delete(:italic)
175
+ else
176
+ result << '<em>'
177
+ current_styles << :italic
178
+ end
179
+ i += 2
180
+ when 'F'
181
+ # Foreground color
182
+ if i + 4 < text.length
183
+ color = text[i + 2, 3]
184
+ result << "<span style=\"color: ##{color}\">"
185
+ current_styles << :fg_color
186
+ i += 5
187
+ else
188
+ result << CGI.escapeHTML(text[i])
189
+ i += 1
190
+ end
191
+ when 'f'
192
+ # Reset foreground
193
+ if current_styles.include?(:fg_color)
194
+ result << '</span>'
195
+ current_styles.delete(:fg_color)
196
+ end
197
+ i += 2
198
+ when 'B'
199
+ # Background color
200
+ if i + 4 < text.length
201
+ color = text[i + 2, 3]
202
+ result << "<span style=\"background-color: ##{color}\">"
203
+ current_styles << :bg_color
204
+ i += 5
205
+ else
206
+ result << CGI.escapeHTML(text[i])
207
+ i += 1
208
+ end
209
+ when 'b'
210
+ # Reset background
211
+ if current_styles.include?(:bg_color)
212
+ result << '</span>'
213
+ current_styles.delete(:bg_color)
214
+ end
215
+ i += 2
216
+ when '`'
217
+ # Reset all formatting
218
+ while current_styles.any?
219
+ style = current_styles.pop
220
+ case style
221
+ when :bold then result << '</strong>'
222
+ when :italic then result << '</em>'
223
+ when :underline then result << '</u>'
224
+ when :fg_color, :bg_color then result << '</span>'
225
+ end
226
+ end
227
+ i += 2
228
+ when '['
229
+ # Link
230
+ link_match = text[i..-1].match(/`\[([^\`]*)`([^\]]+)\]/)
231
+ if link_match
232
+ label = link_match[1].empty? ? link_match[2] : link_match[1]
233
+ url = link_match[2]
234
+ result << "<a href=\"#{CGI.escapeHTML(url)}\">#{CGI.escapeHTML(label)}</a>"
235
+ i += link_match[0].length
236
+ else
237
+ result << CGI.escapeHTML(text[i])
238
+ i += 1
239
+ end
240
+ when '<'
241
+ # Field input
242
+ field_match = text[i..-1].match(/`<([^`]*)`([^>]*)>/)
243
+ if field_match
244
+ field_config = field_match[1]
245
+ field_value = field_match[2]
246
+ result << render_field_html(field_config, field_value)
247
+ i += field_match[0].length
248
+ else
249
+ result << CGI.escapeHTML(text[i])
250
+ i += 1
251
+ end
252
+ else
253
+ result << CGI.escapeHTML(text[i])
254
+ i += 1
255
+ end
256
+ else
257
+ result << CGI.escapeHTML(text[i])
258
+ i += 1
259
+ end
260
+ end
261
+
262
+ # Close any remaining open tags
263
+ while current_styles.any?
264
+ style = current_styles.pop
265
+ case style
266
+ when :bold then result << '</strong>'
267
+ when :italic then result << '</em>'
268
+ when :underline then result << '</u>'
269
+ when :fg_color, :bg_color then result << '</span>'
270
+ end
271
+ end
272
+
273
+ result
274
+ end
275
+
276
+ def render_field_html(config, value)
277
+ parts = config.split('|')
278
+
279
+ # Parse field configuration
280
+ masked = parts[0] == '!'
281
+ size = nil
282
+ name = nil
283
+
284
+ if parts.length == 1
285
+ name = parts[0].delete('!')
286
+ elsif parts.length == 2
287
+ if parts[0] =~ /\d+/
288
+ size = parts[0].to_i
289
+ name = parts[1]
290
+ else
291
+ name = parts[0].delete('!')
292
+ end
293
+ elsif parts.length >= 2
294
+ first = parts[0].delete('!')
295
+ if first =~ /\d+/
296
+ size = first.to_i
297
+ name = parts[1]
298
+ else
299
+ size = parts[1].to_i if parts[1] =~ /\d+/
300
+ name = parts[0].delete('!')
301
+ end
302
+ end
303
+
304
+ type = masked ? 'password' : 'text'
305
+ size_attr = size ? " size=\"#{size}\"" : ''
306
+
307
+ "<input type=\"#{type}\" name=\"#{CGI.escapeHTML(name)}\" value=\"#{CGI.escapeHTML(value)}\"#{size_attr}>"
308
+ end
309
+
310
+ def process_line_text(line)
311
+ # Handle literal blocks
312
+ if line.start_with?('`=')
313
+ @state[:in_literal] = !@state[:in_literal]
314
+ if @state[:in_literal]
315
+ @state[:literal_content] = []
316
+ return ''
317
+ else
318
+ content = @state[:literal_content].join("\n")
319
+ @state[:literal_content] = []
320
+ return content
321
+ end
322
+ end
323
+
324
+ if @state[:in_literal]
325
+ @state[:literal_content] << line
326
+ return ''
327
+ end
328
+
329
+ # Handle comments
330
+ return '' if line.start_with?('#')
331
+
332
+ # Handle dividers
333
+ if line =~ /^-([∿~]?)$/
334
+ char = $1.empty? ? '─' : $1
335
+ return char * 80
336
+ end
337
+
338
+ # Handle sections
339
+ if line =~ /^(>+)(.*)$/
340
+ level = $1.length
341
+ heading = $2.strip
342
+ @state[:section_level] = level
343
+
344
+ if heading.empty?
345
+ return ''
346
+ else
347
+ indent = ' ' * (level - 1)
348
+ processed_heading = process_inline_text(heading)
349
+ return "#{indent}#{processed_heading.bold}"
350
+ end
351
+ end
352
+
353
+ # Handle alignment (note: terminal alignment is approximate)
354
+ alignment = @state[:alignment]
355
+ case line
356
+ when /^`c/
357
+ alignment = :center
358
+ line = line[2..-1]
359
+ when /^`l/
360
+ alignment = :left
361
+ line = line[2..-1]
362
+ when /^`r/
363
+ alignment = :right
364
+ line = line[2..-1]
365
+ when /^`a/
366
+ alignment = :left
367
+ line = line[2..-1]
368
+ end
369
+
370
+ return '' if line.strip.empty?
371
+
372
+ # Add section indentation
373
+ indent = ' ' * @state[:section_level]
374
+
375
+ processed = process_inline_text(line)
376
+
377
+ # Apply alignment (approximate for terminal)
378
+ case alignment
379
+ when :center
380
+ processed = processed.center(80)
381
+ when :right
382
+ processed = processed.rjust(80)
383
+ end
384
+
385
+ "#{indent}#{processed}"
386
+ end
387
+
388
+ def process_inline_text(text)
389
+ result = []
390
+ i = 0
391
+
392
+ # Track current formatting
393
+ bold = false
394
+ italic = false
395
+ underline = false
396
+ fg_color = nil
397
+ bg_color = nil
398
+
399
+ while i < text.length
400
+ if text[i] == '\\' && i + 1 < text.length
401
+ # Escaped character
402
+ result << text[i + 1]
403
+ i += 2
404
+ next
405
+ end
406
+
407
+ if text[i] == '`' && i + 1 < text.length
408
+ tag = text[i + 1]
409
+
410
+ case tag
411
+ when '!'
412
+ # Toggle bold
413
+ bold = !bold
414
+ i += 2
415
+ when '_'
416
+ # Toggle underline
417
+ underline = !underline
418
+ i += 2
419
+ when '*'
420
+ # Toggle italic (terminal may not support)
421
+ italic = !italic
422
+ i += 2
423
+ when 'F'
424
+ # Foreground color
425
+ if i + 4 < text.length
426
+ fg_color = text[i + 2, 3]
427
+ i += 5
428
+ else
429
+ result << text[i]
430
+ i += 1
431
+ end
432
+ when 'f'
433
+ # Reset foreground
434
+ fg_color = nil
435
+ i += 2
436
+ when 'B'
437
+ # Background color
438
+ if i + 4 < text.length
439
+ bg_color = text[i + 2, 3]
440
+ i += 5
441
+ else
442
+ result << text[i]
443
+ i += 1
444
+ end
445
+ when 'b'
446
+ # Reset background
447
+ bg_color = nil
448
+ i += 2
449
+ when '`'
450
+ # Reset all formatting
451
+ bold = false
452
+ italic = false
453
+ underline = false
454
+ fg_color = nil
455
+ bg_color = nil
456
+ i += 2
457
+ when '['
458
+ # Link - just extract and display the label or URL
459
+ link_match = text[i..-1].match(/`\[([^\`]*)`([^\]]+)\]/)
460
+ if link_match
461
+ label = link_match[1].empty? ? link_match[2] : link_match[1]
462
+ # Apply current formatting to link
463
+ formatted = apply_text_formatting(label, bold, underline, fg_color, bg_color)
464
+ result << formatted
465
+ i += link_match[0].length
466
+ else
467
+ result << text[i]
468
+ i += 1
469
+ end
470
+ when '<'
471
+ # Field - just show the value
472
+ field_match = text[i..-1].match(/`<([^`]*)`([^>]*)>/)
473
+ if field_match
474
+ field_value = field_match[2]
475
+ result << "[#{field_value}]"
476
+ i += field_match[0].length
477
+ else
478
+ result << text[i]
479
+ i += 1
480
+ end
481
+ else
482
+ result << text[i]
483
+ i += 1
484
+ end
485
+ else
486
+ # Regular character - apply formatting
487
+ char = text[i]
488
+ formatted = apply_text_formatting(char, bold, underline, fg_color, bg_color)
489
+ result << formatted
490
+ i += 1
491
+ end
492
+ end
493
+
494
+ result.join("")
495
+ end
496
+
497
+ def apply_text_formatting(text, bold, underline, fg_color, bg_color)
498
+ result = text
499
+
500
+ # Apply colorization
501
+ if fg_color
502
+ color = hex_to_ansi_color(fg_color)
503
+ result = result.colorize(color) if color
504
+ end
505
+
506
+ if bg_color
507
+ color = hex_to_ansi_color(bg_color)
508
+ result = result.colorize(background: color) if color
509
+ end
510
+
511
+ # Apply text styles
512
+ result = result.bold if bold
513
+ result = result.underline if underline
514
+
515
+ result
516
+ end
517
+
518
+ def hex_to_ansi_color(hex)
519
+ # Convert 3-char hex to closest ANSI color
520
+ # This is a simplified mapping
521
+ r, g, b = hex.chars.map { |c| c.to_i(16) }
522
+
523
+ # Simple brightness-based mapping
524
+ brightness = (r + g + b) / 3.0
525
+
526
+ if brightness < 4
527
+ :black
528
+ elsif r > g && r > b
529
+ brightness > 8 ? :light_red : :red
530
+ elsif g > r && g > b
531
+ brightness > 8 ? :light_green : :green
532
+ elsif b > r && b > g
533
+ brightness > 8 ? :light_blue : :blue
534
+ elsif r > 8 && g > 8 && b < 4
535
+ :yellow
536
+ elsif r > 8 && b > 8 && g < 4
537
+ :magenta
538
+ elsif g > 8 && b > 8 && r < 4
539
+ :cyan
540
+ elsif brightness > 10
541
+ :white
542
+ else
543
+ :light_black
544
+ end
545
+ end
546
+
547
+ # Utility method to generate a complete HTML document with CSS
548
+ def to_html_document(title: "Micron Document")
549
+ <<~HTML
550
+ <!DOCTYPE html>
551
+ <html>
552
+ <head>
553
+ <meta charset="UTF-8">
554
+ <title>#{CGI.escapeHTML(title)}</title>
555
+ <style>
556
+ body {
557
+ font-family: 'Courier New', monospace;
558
+ background: #1e1e1e;
559
+ color: #d4d4d4;
560
+ padding: 20px;
561
+ line-height: 1.6;
562
+ }
563
+ .micron-content {
564
+ max-width: 800px;
565
+ margin: 0 auto;
566
+ }
567
+ .align-center {
568
+ text-align: center;
569
+ }
570
+ .align-right {
571
+ text-align: right;
572
+ }
573
+ .section {
574
+ margin-left: 2em;
575
+ }
576
+ .section-heading {
577
+ font-weight: bold;
578
+ margin-top: 1em;
579
+ margin-bottom: 0.5em;
580
+ }
581
+ hr {
582
+ border: none;
583
+ border-top: 1px solid #444;
584
+ margin: 1em 0;
585
+ }
586
+ pre.literal {
587
+ background: #2d2d2d;
588
+ padding: 1em;
589
+ overflow-x: auto;
590
+ border-left: 3px solid #0078d4;
591
+ }
592
+ a {
593
+ color: #4a9eff;
594
+ text-decoration: underline;
595
+ }
596
+ input {
597
+ background: #2d2d2d;
598
+ color: #d4d4d4;
599
+ border: 1px solid #444;
600
+ padding: 4px 8px;
601
+ font-family: inherit;
602
+ }
603
+ </style>
604
+ </head>
605
+ <body>
606
+ #{render_html}
607
+ </body>
608
+ </html>
609
+ HTML
610
+ end
611
+ end
612
+
613
+ def self.render micron
614
+ Renderer.new(micron)
615
+ end
616
+ end
@@ -0,0 +1,4 @@
1
+ module MicronMarkup
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: micron_markup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Erik Olson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2026-02-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: cgi
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ - xorgnak@xorgnak.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - CHANGELOG.md
49
+ - CODE_OF_CONDUCT.md
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - lib/micron_markup.rb
55
+ - lib/micron_markup/version.rb
56
+ - sig/micron_markup.rbs
57
+ homepage: https://github.com/xorgnak/micron_markup
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 2.6.0
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubygems_version: 3.3.15
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Render Micron Markup in Ruby
80
+ test_files: []