markdown_exec 1.3.9 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8fb58efae22bb345c1c1a863aa9dbf62bd6682cda0154d15d8e114cdf1b8ae64
4
- data.tar.gz: eb0f7696597c1c53fc529e0a538e0ca9b2b684418242605574d01c449a47bf67
3
+ metadata.gz: 6655d4d2fdbf1334fd7eb786e8b8e3e8401ac0e8cb0e10927c1e426be9422d83
4
+ data.tar.gz: 5e2e1272f186e8fb00d240fd11501cdc5630ab497298fcc02e43c42c9b3e0f45
5
5
  SHA512:
6
- metadata.gz: 0520a2e9c8c224e511821e362c189aa648f1f76a2e72876d1d87132d7f76f3ecbf2e84adbb6c4852d07b44aa52ddb08b40cd5f913dbd6540cf459794762b682f
7
- data.tar.gz: 8acbbc2f5bde35a2e41b9852951349ff5ee5bd561c42a283675d25d6edc8d915540ea33de8cc48f72e92692ce31edff8b33a1583e3d8a983f8c28b01e82799f9
6
+ metadata.gz: 63ab33098867f8f1af0b0281690e816cd657d9fc42181cdb895ee78ab2e722cc5c63303d2c2be7f9791a7cacc9503cbfc45d9277b1a35e5cdb33ef4217a8607a
7
+ data.tar.gz: 4535992b37f72e175388264c3e7ab9f5189a06e57b8a973521d95f62ea75a22de445518f19577563d78a81ebc2c8a99c3cc3e24639f04f792ad9017780c426bb
data/.pryrc ADDED
@@ -0,0 +1,13 @@
1
+ if defined?(PryByebug)
2
+ Pry.config.pager = false
3
+ Pry.commands.alias_command 'c', 'continue'
4
+ Pry.commands.alias_command 'd', 'down'
5
+ Pry.commands.alias_command 'f', 'finish'
6
+ Pry.commands.alias_command 'n', 'next'
7
+ Pry.commands.alias_command 's', 'step'
8
+ Pry.commands.alias_command 'u', 'up'
9
+
10
+ Pry::Commands.command /^$/, 'repeat last command' do
11
+ _pry_.run_command Pry.history.to_a.last
12
+ end
13
+ end
data/.rubocop.yml CHANGED
@@ -15,7 +15,6 @@ Layout/LineContinuationLeadingSpace:
15
15
 
16
16
  Layout/LineLength:
17
17
  Max: 96
18
- # Max: 120
19
18
 
20
19
  Lint/Debugger:
21
20
  Enabled: false
@@ -65,6 +64,9 @@ Style/DoubleNegation:
65
64
  Style/EmptyElse:
66
65
  Enabled: false
67
66
 
67
+ Style/FormatStringToken:
68
+ Enabled: false
69
+
68
70
  Style/GlobalVars:
69
71
  Enabled: false
70
72
 
@@ -74,6 +76,18 @@ Style/MixinUsage:
74
76
  Style/MultilineBlockChain:
75
77
  Enabled: false
76
78
 
79
+ Style/PerlBackrefs: # Prefer ::Regexp.last_match.post_match over $'.
80
+ Enabled: false
81
+
82
+ Style/RegexpLiteral:
83
+ Enabled: false
84
+
85
+ Style/Semicolon: # Do not use semicolons to terminate expressions.
86
+ Enabled: false
87
+
88
+ Style/SingleLineMethods: # Avoid single-line method definitions.
89
+ Enabled: false
90
+
77
91
  Style/SlicingWithRange:
78
92
  Enabled: false
79
93
 
data/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.4.1] - 2023-11-02
4
+
5
+ ### Added
6
+
7
+ - Support for nested links.
8
+ A Link block name can be followed by the block name to execute in the linked document.
9
+ Nested links result in scripts with nested required blocks.
10
+
11
+ ## [1.4] - 2023-10-31
12
+
13
+ ### Added
14
+
15
+ - Add required code blocks to link block types.
16
+ Allows for nested required code as links are navigated.
17
+
18
+ - Add fg_rgbh_* methods to process hex RGB specifications.
19
+
3
20
  ## [1.3.9] - 2023-10-29
4
21
 
5
22
  Add block types for linking and variable control
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- markdown_exec (1.3.9)
4
+ markdown_exec (1.4.1)
5
5
  clipboard (~> 1.3.6)
6
6
  open3 (~> 0.1.1)
7
7
  optparse (~> 0.1.1)
data/bin/bmde ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # encoding=utf-8
5
+
6
+ require 'bundler/setup'
7
+ Bundler.require(:default)
8
+
9
+ require_relative '../lib/markdown_exec'
10
+
11
+ MarkdownExec::MarkParse.new.run
@@ -13,7 +13,7 @@ __filedirs_all()
13
13
  }
14
14
 
15
15
  _mde_echo_version() {
16
- echo "1.3.9"
16
+ echo "1.4.1"
17
17
  }
18
18
 
19
19
  _mde() {
@@ -138,4 +138,4 @@ _mde() {
138
138
 
139
139
  complete -o filenames -o nospace -F _mde mde
140
140
  # _mde_echo_version
141
- # echo "Updated: 2023-10-29 19:38:35 UTC"
141
+ # echo "Updated: 2023-11-02 13:20:09 UTC"
data/examples/linked1.md CHANGED
@@ -3,26 +3,27 @@
3
3
  ::: * This is document 1 *
4
4
  ::: This document links to a matching document to demonstrate navigation between documents.
5
5
 
6
- ::: This Bash block displays the value of variables "linked1var" and "linked2var"
6
+ ::: This Bash block displays the value of variables "page1_var_via_environment" and "page2_var_via_environment"
7
7
 
8
- ```bash :page1_show_vars
8
+ ```bash :show_vars
9
9
  source bin/colorize_env_vars.sh
10
- colorize_env_vars 'on page1' linked1var linked2var
10
+ colorize_env_vars 'vars for page2' PAGE2_VAR_VIA_INHERIT page2_var_via_environment
11
+ colorize_env_vars 'vars for page3' PAGE3_VAR_VIA_INHERIT page3_var_via_environment
11
12
  ```
12
13
 
13
- ::: This Link block sets variable "linked2var" and navigates to document 2.
14
+ ::: This Link block
15
+ ::: 1. requires a block that sets environment variable PAGE2_VAR_VIA_INHERIT,
16
+ ::: 2. navigates to document 2, and
17
+ ::: 3. executes block "show_vars" to display the imported PAGE2_VAR_VIA_INHERIT.
18
+ ::: Any script generated by page 2 will contain the inherited code.
14
19
 
15
- ```link :linked2
16
- file: examples/linked2.md
17
- vars:
18
- linked2var: from_linked1
20
+ ```bash :(vars2)
21
+ PAGE2_VAR_VIA_INHERIT=for_page2_from_page1_via_inherited_code_file
19
22
  ```
20
23
 
21
- ::: This Link block sets variable "linked2var", navigates to document 2, and executes block "page2_show_vars".
22
-
23
- ```link :linked2_show_vars
24
+ ```link :linked2_import_vars +(vars2)
24
25
  file: examples/linked2.md
25
- block: page2_show_vars
26
+ block: show_vars
26
27
  vars:
27
- linked2var: from_linked1
28
+ page2_var_via_environment: for_page2_from_page1_via_current_environment
28
29
  ```
data/examples/linked2.md CHANGED
@@ -3,26 +3,26 @@
3
3
  ::: * This is document 2 *
4
4
  ::: This document links to a matching document to demonstrate navigation between documents.
5
5
 
6
- ::: This Bash block displays the value of variables "linked1var" and "linked2var"
6
+ ::: This Bash block displays the value of variables "page1_var_via_environment" and "page2_var_via_environment"
7
7
 
8
- ```bash :page2_show_vars
8
+ ```bash :show_vars
9
9
  source bin/colorize_env_vars.sh
10
- colorize_env_vars 'on page2' linked1var linked2var
10
+ colorize_env_vars 'vars for page2' PAGE2_VAR_VIA_INHERIT page2_var_via_environment
11
+ colorize_env_vars 'vars for page3' PAGE3_VAR_VIA_INHERIT page3_var_via_environment
11
12
  ```
12
13
 
13
- ::: This Link block sets variable "linked1var" and navigates to document 1.
14
+ ::: This Link block requires a block that
15
+ ::: 1. sets environment variable PAGE3_VAR_VIA_INHERIT,
16
+ ::: 2. navigates to document 3, and
17
+ ::: 3. executes block "show_vars" to display the imported PAGE3_VAR_VIA_INHERIT.
14
18
 
15
- ```link :linked1
16
- file: examples/linked1.md
17
- vars:
18
- linked1var: from_linked2
19
+ ```bash :(vars3)
20
+ PAGE3_VAR_VIA_INHERIT=for_page3_from_page2_via_inherited_code_file
19
21
  ```
20
22
 
21
- ::: This Link block sets variable "linked1var", navigates to document 1, and executes block "page1_show_vars".
22
-
23
- ```link :linked1_show_vars
24
- file: examples/linked1.md
25
- block: page1_show_vars
23
+ ```link :linked3_import_vars +(vars3)
24
+ file: examples/linked3.md
25
+ block: show_vars
26
26
  vars:
27
- linked1var: from_linked2
27
+ page3_var_via_environment: for_page3_from_page2_via_current_environment
28
28
  ```
@@ -0,0 +1,12 @@
1
+ # Demo document linking
2
+
3
+ ::: * This is document 3 *
4
+ ::: This document is linked from another document to demonstrate code transfer.
5
+
6
+ ::: This Bash block displays the value of variables "PAGE3_VAR_VIA_INHERIT" and "page3_var_via_environment"
7
+
8
+ ```bash :show_vars
9
+ source bin/colorize_env_vars.sh
10
+ colorize_env_vars 'vars for page2' PAGE2_VAR_VIA_INHERIT page2_var_via_environment
11
+ colorize_env_vars 'vars for page3' PAGE3_VAR_VIA_INHERIT page3_var_via_environment
12
+ ```
data/lib/block_types.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  BLOCK_TYPE_BASH = 'bash'
2
4
  BLOCK_TYPE_LINK = 'link'
3
5
  BLOCK_TYPE_OPTS = 'opts'
data/lib/colorize.rb CHANGED
@@ -2,81 +2,78 @@
2
2
 
3
3
  # encoding=utf-8
4
4
 
5
+ # Extends Ruby's native String class to include ANSI coloring functionality.
6
+ # Adds methods to apply RGB colors, named colors, and other formatting to strings.
5
7
  class String
6
- alias_method :original_method_missing, :method_missing
7
-
8
+ # Handles dynamic method calls to create RGB colors.
9
+ #
10
+ # @param method_name [Symbol] The name of the method being called.
11
+ # @param args [Array] The arguments passed to the method.
12
+ # @param block [Proc] An optional block.
13
+ # @return [String] The formatted string.
8
14
  def method_missing(method_name, *args, &block)
9
- if /^fg_rgb_/ =~ method_name.to_s
15
+ case method_name.to_s
16
+ when /^fg_rgb_/
10
17
  fg_rgb_color($'.gsub('_', ';'))
18
+ when /^fg_rgbh_/
19
+ hex_to_rgb($')
11
20
  else
12
- original_method_missing(method_name, *args, &block)
21
+ super
13
22
  end
14
23
  end
15
24
 
16
- # control sequence with reset
25
+ # Generates an ANSI control sequence for the string.
17
26
  #
27
+ # @return [String] The string wrapped in an ANSI control sequence.
18
28
  def ansi_control_sequence
19
29
  "\033[#{self}\033[0m"
20
30
  end
21
31
 
22
- # use 24-bit RGB foreground color spec
23
- # ex: 1;2;3
32
+ # Applies a 24-bit RGB foreground color to the string.
24
33
  #
34
+ # @param rgb [String] The RGB color, expressed as a string like "1;2;3".
35
+ # @return [String] The string with the applied RGB foreground color.
25
36
  def fg_rgb_color(rgb)
26
37
  "38;2;#{rgb}m#{self}".ansi_control_sequence
27
38
  end
28
39
 
29
- def plain
30
- self
31
- end
32
-
33
- # named colors
40
+ # Converts hex color codes to RGB and applies them to the string.
34
41
  #
35
- def black
36
- "30m#{self}".ansi_control_sequence
37
- end
38
-
39
- def red
40
- "31m#{self}".ansi_control_sequence
42
+ # @param hex_str [String] The RGB color, expressed as a hex string like "FF00FF".
43
+ # @return [String] The string with the applied RGB foreground color.
44
+ def hex_to_rgb(hex_str)
45
+ fg_rgb_color(
46
+ hex_str.split('_').map { |hex| hex.to_i(16).to_s }.join(';')
47
+ )
41
48
  end
42
49
 
43
- def bred
44
- "1;31m#{self}".ansi_control_sequence
45
- end
46
-
47
- def green
48
- "32m#{self}".ansi_control_sequence
49
- end
50
-
51
- def bgreen
52
- "1;32m#{self}".ansi_control_sequence
53
- end
54
-
55
- def yellow
56
- "33m#{self}".ansi_control_sequence
57
- end
58
-
59
- def byellow
60
- "1;33m#{self}".ansi_control_sequence
61
- end
62
-
63
- def blue
64
- "34m#{self}".ansi_control_sequence
65
- end
66
-
67
- def magenta
68
- "35m#{self}".ansi_control_sequence
69
- end
70
-
71
- def cyan
72
- "36m#{self}".ansi_control_sequence
73
- end
74
-
75
- def white
76
- "37m#{self}".ansi_control_sequence
50
+ # Provides a plain, unmodified version of the string.
51
+ #
52
+ # @return [String] The original string.
53
+ def plain
54
+ self
77
55
  end
78
56
 
79
- def bwhite
80
- "1;37m#{self}".ansi_control_sequence
81
- end
57
+ # A collection of methods for applying named colors.
58
+ #
59
+ # For example, #black applies a black foreground color to the string.
60
+ # These are provided for convenience and easy readability.
61
+
62
+ def black; "30m#{self}".ansi_control_sequence; end
63
+ def bred; "1;31m#{self}".ansi_control_sequence; end
64
+ def bgreen; "1;32m#{self}".ansi_control_sequence; end
65
+ def byellow; "1;33m#{self}".ansi_control_sequence; end
66
+ def magenta; "35m#{self}".ansi_control_sequence; end
67
+ def cyan; "36m#{self}".ansi_control_sequence; end
68
+ def white; "37m#{self}".ansi_control_sequence; end
69
+ def bwhite; "1;37m#{self}".ansi_control_sequence; end
70
+
71
+ # More named colors using RGB hex values
72
+ def blue; fg_rgbh_00_00_FF; end
73
+ def green; fg_rgbh_00_FF_00; end
74
+ def indigo; fg_rgbh_4B_00_82; end
75
+ def orange; fg_rgbh_FF_7F_00; end
76
+ def red; fg_rgbh_FF_00_00; end
77
+ def violet; fg_rgbh_94_00_D3; end
78
+ def yellow; fg_rgbh_FF_FF_00; end
82
79
  end
data/lib/filter.rb CHANGED
@@ -38,7 +38,7 @@ module MarkdownExec
38
38
  name = fcb.oname
39
39
  shell = fcb.fetch(:shell, '')
40
40
 
41
- apply_name_filters(options, filters, name) #if shell == 'bash'
41
+ apply_name_filters(options, filters, name)
42
42
  apply_shell_filters(options, filters, shell)
43
43
  apply_other_filters(options, filters, fcb)
44
44
 
@@ -125,7 +125,7 @@ module MarkdownExec
125
125
 
126
126
  return unless options[:bash_only]
127
127
 
128
- filters[:shell_default] = (shell == 'bash')
128
+ filters[:shell_default] = (shell == BLOCK_TYPE_BASH)
129
129
  end
130
130
 
131
131
  # Evaluates the filter settings to make a final decision on
@@ -239,7 +239,7 @@ if $PROGRAM_NAME == __FILE__
239
239
 
240
240
  def test_bash_only_condition_true
241
241
  @options[:bash_only] = true
242
- @fcb[:shell] = 'bash'
242
+ @fcb[:shell] = BLOCK_TYPE_BASH
243
243
  assert Filter.fcb_select?(@options, @fcb)
244
244
  end
245
245
 
@@ -7,5 +7,5 @@ module MarkdownExec
7
7
  BIN_NAME = 'mde'
8
8
  GEM_NAME = 'markdown_exec'
9
9
  TAP_DEBUG = 'MDE_DEBUG'
10
- VERSION = '1.3.9'
10
+ VERSION = '1.4.1'
11
11
  end