markdown_exec 2.7.1 → 2.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +33 -1
- data/Gemfile.lock +1 -1
- data/Rakefile +29 -11
- data/bats/block-type-opts.bats +23 -0
- data/bats/block-type-vars.bats +26 -0
- data/bats/block-types.bats +0 -36
- data/bats/border.bats +8 -0
- data/bats/document-shell.bats +9 -0
- data/bats/line-wrapping.bats +8 -0
- data/bin/tab_completion.sh +1 -1
- data/docs/dev/block-type-opts.md +4 -1
- data/docs/dev/block-type-vars.md +15 -4
- data/docs/dev/border.md +7 -0
- data/docs/dev/command-substitution.md +1 -0
- data/docs/dev/document-shell.md +6 -0
- data/docs/dev/line-wrapping.md +24 -0
- data/examples/link-blocks-vars.md +69 -41
- data/lib/colorize.rb +11 -37
- data/lib/fcb.rb +16 -4
- data/lib/filter.rb +3 -24
- data/lib/format_table.rb +0 -1
- data/lib/hash_delegator.rb +340 -173
- data/lib/input_sequencer.rb +7 -0
- data/lib/markdown_exec/version.rb +1 -1
- data/lib/markdown_exec.rb +1 -2
- data/lib/mdoc.rb +10 -13
- data/lib/menu.src.yml +8 -4
- data/lib/menu.yml +7 -3
- data/lib/ww.rb +4 -2
- metadata +11 -3
- /data/examples/{wrap.md → wrapped-blocks.md} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c35f2f729da73920db53053340bbe0ced75bfbb16ad59697fa6ba4016b62ae74
|
4
|
+
data.tar.gz: c20943723250feaa3e1b7218710cede9ebf4da4dd6eebf68584a805b9647b7d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 185f571fd39b4bdce955a455695413390b83c3635236871a83098bd595b184b5a79a2cd2b2778fb1fa795d658566237ed251e751fe1981a71aff192ce22da376
|
7
|
+
data.tar.gz: 19248dd05c973d9657362145826312fd2a07a7f6b4ad6834e623a19f289b35dc4d32c9c16401fc73a7e6309f4fc7ba9a5f63cc82a7db78299b623ea0d3b471f0
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,37 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [2.7.3] - 2025-01-29
|
4
|
+
|
5
|
+
### Added
|
6
|
+
|
7
|
+
- Automatic loading of multiple Opts and Vars blocks when opening a document.
|
8
|
+
|
9
|
+
### Changed
|
10
|
+
|
11
|
+
- Fix text displayed when text is wrapped to the next line.
|
12
|
+
- Handle and report failure of single tests.
|
13
|
+
|
14
|
+
## [2.7.2] - 2025-01-03
|
15
|
+
|
16
|
+
### Added
|
17
|
+
|
18
|
+
- Block name comparison in FCB class.
|
19
|
+
- Option for automatic shell block per document.
|
20
|
+
|
21
|
+
### Changed
|
22
|
+
|
23
|
+
- Disable command substitution in comments.
|
24
|
+
- Fix the source reported by debug function ww0.
|
25
|
+
- Inverse the entire line to highlight the active menu line.
|
26
|
+
- Return single file if no globs in load block.
|
27
|
+
- Update the calculation and use of IDs for blocks used to retrieve the block selected from the menu.
|
28
|
+
|
29
|
+
## [2.7.1] - 2024-12-10
|
30
|
+
|
31
|
+
### Changed
|
32
|
+
|
33
|
+
- Register console dimensions prior to arguments.
|
34
|
+
|
3
35
|
## [2.7.0] - 2024-12-09
|
4
36
|
|
5
37
|
### Added
|
@@ -399,7 +431,7 @@ Rename options to match use.
|
|
399
431
|
These blocks can be hidden blocks and required in a script.
|
400
432
|
|
401
433
|
- Add a "wrap" fenced code block type to facilitate script generation.
|
402
|
-
See document `examples/
|
434
|
+
See document `examples/wrapped-blocks.md`.
|
403
435
|
These blocks are hidden and can be required by one or more blocks.
|
404
436
|
|
405
437
|
### Changed
|
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
@@ -74,14 +74,38 @@ task :clean do
|
|
74
74
|
system 'rm *.gem'
|
75
75
|
end
|
76
76
|
|
77
|
+
def execute_with_error_handling(iterator)
|
78
|
+
all_error_level = 0
|
79
|
+
all_failed_files = []
|
80
|
+
|
81
|
+
iterator.each do |item|
|
82
|
+
command = yield(item)
|
83
|
+
next unless command # Skip if command is nil
|
84
|
+
|
85
|
+
result = system(command)
|
86
|
+
error_level = $?.exitstatus
|
87
|
+
|
88
|
+
if error_level != 0
|
89
|
+
puts "Error: Command '#{command}' failed with exit status #{error_level}."
|
90
|
+
all_error_level = error_level
|
91
|
+
all_failed_files << command
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
if all_error_level != 0
|
96
|
+
puts "Error: #{all_failed_files.join(', ')} failed."
|
97
|
+
exit all_error_level
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
77
101
|
desc 'bats'
|
78
102
|
task :bats do
|
79
|
-
FileList['bats/**/*.bats']
|
80
|
-
next if %w[bats/bats.bats bats/fail.bats].include?(file)
|
103
|
+
execute_with_error_handling(FileList['bats/**/*.bats']) do |file|
|
104
|
+
next nil if %w[bats/bats.bats bats/fail.bats].include?(file)
|
81
105
|
|
82
106
|
# temporary clear WW to disable debugging
|
83
107
|
# WW pollutes output expected by BATS tests
|
84
|
-
|
108
|
+
"unset WW; bats #{file}"
|
85
109
|
end
|
86
110
|
end
|
87
111
|
|
@@ -118,14 +142,8 @@ task :minitest do
|
|
118
142
|
'./lib/dev/process_template.rb --test'
|
119
143
|
]
|
120
144
|
|
121
|
-
commands
|
122
|
-
|
123
|
-
error_level = $?.exitstatus
|
124
|
-
|
125
|
-
if error_level != 0
|
126
|
-
puts "Error: Command '#{command}' failed with exit status #{error_level}."
|
127
|
-
exit error_level
|
128
|
-
end
|
145
|
+
execute_with_error_handling(commands) do |command|
|
146
|
+
"bundle exec ruby #{command}"
|
129
147
|
end
|
130
148
|
end
|
131
149
|
task mini: %i[minitest]
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env bats
|
2
|
+
|
3
|
+
load 'test_helper'
|
4
|
+
|
5
|
+
# Type: Opts
|
6
|
+
|
7
|
+
@test 'Opts block - before' {
|
8
|
+
skip 'Fails because command executes after the block is processed'
|
9
|
+
spec_mde_xansi_dname_doc_blocks_expect docs/dev/block-type-opts.md \
|
10
|
+
'BEFORE Species_menu_note_format: "AFTER %{line}" '
|
11
|
+
}
|
12
|
+
|
13
|
+
@test 'Opts block - after' {
|
14
|
+
spec_mde_xansi_dname_doc_blocks_expect docs/dev/block-type-opts.md \
|
15
|
+
'[decorate-note]' \
|
16
|
+
'AFTER Species_menu_note_format: "AFTER %{line}"'
|
17
|
+
}
|
18
|
+
|
19
|
+
@test 'Opts block - show that menu has changed' {
|
20
|
+
skip 'Unable to show that menu has changed'
|
21
|
+
spec_mde_args_expect docs/dev/block-type-opts.md '[decorate-note]' \
|
22
|
+
'AFTER Species'
|
23
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env bats
|
2
|
+
|
3
|
+
load 'test_helper'
|
4
|
+
|
5
|
+
# Type: Vars
|
6
|
+
|
7
|
+
# includes output from automatic vars blocks
|
8
|
+
@test 'Vars block - auto load' {
|
9
|
+
BATS_OUTPUT_FILTER=A
|
10
|
+
spec_mde_args_expect docs/dev/block-type-vars.md show \
|
11
|
+
'Species = Not specified Genus = Not specified Species: Not specified VAULT:'
|
12
|
+
}
|
13
|
+
|
14
|
+
# includes output from assignment and from shell block
|
15
|
+
@test 'Vars block - set variable' {
|
16
|
+
BATS_OUTPUT_FILTER=A
|
17
|
+
spec_mde_args_expect docs/dev/block-type-vars.md '[set_vault_1]' show \
|
18
|
+
'Species = Not specified Genus = Not specified VAULT = 1 Species: Not specified VAULT: 1'
|
19
|
+
}
|
20
|
+
|
21
|
+
# handles invalid YAML in block
|
22
|
+
@test 'Vars block - invalid YAML' {
|
23
|
+
BATS_OUTPUT_FILTER=A
|
24
|
+
spec_mde_args_expect docs/dev/block-type-vars.md '[invalid_yaml]' show \
|
25
|
+
'Species = Not specified Genus = Not specified Species: Not specified VAULT:'
|
26
|
+
}
|
data/bats/block-types.bats
CHANGED
@@ -47,26 +47,6 @@ load 'test_helper'
|
|
47
47
|
run_mde_specs_md_args_expect_xansi '[VARIABLE1]' '(echo-VARIABLE1)' ' VARIABLE1: 1 VARIABLE1: 1'
|
48
48
|
}
|
49
49
|
|
50
|
-
# Type: Opts
|
51
|
-
|
52
|
-
@test 'Opts block - before' {
|
53
|
-
skip 'Fails because command executes after the block is processed'
|
54
|
-
spec_mde_xansi_dname_doc_blocks_expect docs/dev/block-type-opts.md \
|
55
|
-
'BEFORE Species_menu_note_format: "AFTER %{line}" '
|
56
|
-
}
|
57
|
-
|
58
|
-
@test 'Opts block - after' {
|
59
|
-
spec_mde_xansi_dname_doc_blocks_expect docs/dev/block-type-opts.md \
|
60
|
-
'[decorate-note]' \
|
61
|
-
'AFTER Species_menu_note_format: "AFTER %{line}"'
|
62
|
-
}
|
63
|
-
|
64
|
-
@test 'Opts block - show that menu has changed' {
|
65
|
-
skip 'Unable to show that menu has changed'
|
66
|
-
spec_mde_args_expect docs/dev/block-type-opts.md '[decorate-note]' \
|
67
|
-
'AFTER Species'
|
68
|
-
}
|
69
|
-
|
70
50
|
# Type: Port
|
71
51
|
|
72
52
|
# includes output from assignment and from shell block
|
@@ -81,19 +61,3 @@ load 'test_helper'
|
|
81
61
|
spec_mde_args_expect docs/dev/block-type-port.md VAULT-is-export show \
|
82
62
|
' VAULT: This variable has not been set.'
|
83
63
|
}
|
84
|
-
|
85
|
-
# Type: Vars
|
86
|
-
|
87
|
-
# includes output from automatic vars block
|
88
|
-
@test 'Vars block - auto load' {
|
89
|
-
BATS_OUTPUT_FILTER=A
|
90
|
-
spec_mde_args_expect docs/dev/block-type-vars.md show \
|
91
|
-
'Species = Not specified Species: Not specified VAULT:'
|
92
|
-
}
|
93
|
-
|
94
|
-
# includes output from assignment and from shell block
|
95
|
-
@test 'Vars block - set variable' {
|
96
|
-
BATS_OUTPUT_FILTER=A
|
97
|
-
spec_mde_args_expect docs/dev/block-type-vars.md '[set_vault_1]' show \
|
98
|
-
'Species = Not specified VAULT = 1 Species: Not specified VAULT: 1'
|
99
|
-
}
|
data/bats/border.bats
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
#!/usr/bin/env bats
|
2
|
+
|
3
|
+
load 'test_helper'
|
4
|
+
|
5
|
+
@test 'Text and Headings' {
|
6
|
+
spec_mde_xansi_dname_doc_blocks_expect docs/dev/line-wrapping.md \
|
7
|
+
" DEMO WRAPPING LONG LINES__MDE detects the screen's dimensions:_height (lines) and width (characters)__Normal document text is displayed as_disabled menu lines. The width of these_lines is limited according to the screen's_width.__Test Indented Lines__ Indented with two spaces, this line_ should wrap in an aesthetically pleasing_ way.__ Indented with a tab, this line should_ wrap in an aesthetically pleasing way.__ SPECIES GENUS FAMILY ORDER CLASS PHYLUM_ KINGDOM DOMAIN_species genus family order class phylum_kingdom domain"
|
8
|
+
}
|
data/bin/tab_completion.sh
CHANGED
data/docs/dev/block-type-opts.md
CHANGED
@@ -6,6 +6,9 @@ menu_note_format: "AFTER %{line}"
|
|
6
6
|
```opts :(document_opts)
|
7
7
|
menu_final_divider:
|
8
8
|
menu_for_saved_lines: false
|
9
|
+
```
|
10
|
+
/ Demonstrate multiple (document_opts) in a single file
|
11
|
+
```opts :(document_opts)
|
9
12
|
menu_initial_divider:
|
10
13
|
menu_note_format: "BEFORE %{line}"
|
11
|
-
```
|
14
|
+
```
|
data/docs/dev/block-type-vars.md
CHANGED
@@ -1,11 +1,22 @@
|
|
1
|
+
```vars :(document_vars)
|
2
|
+
Species: Not specified
|
3
|
+
```
|
4
|
+
```vars :(document_vars)
|
5
|
+
Genus: Not specified
|
6
|
+
```
|
1
7
|
```vars :[set_vault_1]
|
2
8
|
VAULT: 1
|
3
9
|
```
|
10
|
+
```vars :[invalid_yaml]
|
11
|
+
this is not yaml
|
12
|
+
```
|
4
13
|
```bash :show
|
5
14
|
echo "Species: $Species"
|
6
15
|
echo "VAULT: $VAULT"
|
7
16
|
```
|
8
|
-
|
9
|
-
|
10
|
-
Species
|
11
|
-
|
17
|
+
| Variable| Value
|
18
|
+
| -| -
|
19
|
+
| Species| ${Species}
|
20
|
+
| Genus| ${Genus}
|
21
|
+
| VAULT| ${VAULT}
|
22
|
+
@import bats-document-configuration.md
|
data/docs/dev/border.md
ADDED
@@ -11,6 +11,7 @@ echo "current base name is now $(basename `pwd`)"
|
|
11
11
|
```link
|
12
12
|
load: file_$(basename `pwd`).sh
|
13
13
|
```
|
14
|
+
/ This should not be evaluated $(err). It errs with "Error: HashDelegator.blocks_from_nested_files -- Shell script execution failed: /bin/bash: line 2: err: command not found"
|
14
15
|
@import bats-document-configuration.md
|
15
16
|
```opts :(document_opts)
|
16
17
|
heading1_center: false
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Demo wrapping long lines
|
2
|
+
|
3
|
+
MDE detects the screen's dimensions: height (lines) and width (characters)
|
4
|
+
|
5
|
+
Normal document text is displayed as disabled menu lines. The width of these lines is limited according to the screen's width.
|
6
|
+
|
7
|
+
::: Test Indented Lines
|
8
|
+
|
9
|
+
Indented with two spaces, this line should wrap in an aesthetically pleasing way.
|
10
|
+
|
11
|
+
Indented with a tab, this line should wrap in an aesthetically pleasing way.
|
12
|
+
|
13
|
+
# species genus family order class phylum kingdom domain
|
14
|
+
## species genus family order class phylum kingdom domain
|
15
|
+
@import bats-document-configuration.md
|
16
|
+
```opts :(document_opts)
|
17
|
+
divider4_center: false
|
18
|
+
heading1_center: true
|
19
|
+
heading2_center: false
|
20
|
+
screen_width: 48
|
21
|
+
|
22
|
+
menu_note_match: "^(?<indent>[ \t]*)(?<line>(?!/)(?<text>.*?)(?<trailing>[ \t]*))?$"
|
23
|
+
|
24
|
+
```
|
@@ -1,59 +1,87 @@
|
|
1
|
-
# Demonstrate
|
2
|
-
|
3
|
-
```
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
pause_after_script_execution: true
|
1
|
+
# Demonstrate Setting Variables in the Inherited Lines
|
2
|
+
|
3
|
+
```link :select-a-folder +(select-a-folder)
|
4
|
+
eval: true
|
5
|
+
```
|
6
|
+
```bash :(select-a-folder)
|
7
|
+
echo "PT=$(osascript -e 'do shell script "echo " & quoted form of POSIX path of (choose folder with prompt "Please select a folder:")' 2>/dev/null)"
|
9
8
|
```
|
10
9
|
|
11
|
-
|
12
|
-
::: Select below to trigger. If it prints "VARIABLE1: 1", the Link block was processed.
|
10
|
+
This table displays the value of variables in the context of the current inherited lines. At first, the variable is empty unless it exists in the current shell environment.
|
13
11
|
|
14
12
|
| Variable| Value
|
15
13
|
| -| -
|
16
|
-
|
|
14
|
+
| SPECIES| ${SPECIES}
|
15
|
+
|
16
|
+
## Current Inherited Lines
|
17
|
+
|
18
|
+
```view
|
19
|
+
View the current inherited lines.
|
20
|
+
```
|
21
|
+
|
22
|
+
The inherited lines can also be displayed automatically within the menu by enabling this option:
|
23
|
+
|
24
|
+
```opts
|
25
|
+
menu_with_inherited_lines: true
|
26
|
+
```
|
27
|
+
|
28
|
+
## Setting Variables in the Inherited Lines
|
29
|
+
|
30
|
+
You can set environment variables in the inherited lines by adding shell expressions. For example, a line such as `SPECIES=Unknown` in the inherited lines defines a variable that can be used in the rest of the executed script.
|
31
|
+
|
32
|
+
Below are several ways to add such expressions to the inherited lines:
|
33
|
+
|
34
|
+
### Vars Block
|
35
|
+
|
36
|
+
This block (YAML) adds a variable and its value to the inherited lines:
|
37
|
+
|
38
|
+
```vars
|
39
|
+
SPECIES: Tapanuli Orangutan
|
40
|
+
```
|
41
|
+
|
42
|
+
### Link Block
|
43
|
+
|
44
|
+
This block (YAML) also adds a variable and its value to the inherited lines:
|
17
45
|
|
18
|
-
The block sets VARIABLE1.
|
19
|
-
For each environment variable in `vars`, append an inherited line that assigns the variable the specified value.
|
20
46
|
```link
|
21
47
|
vars:
|
22
|
-
|
48
|
+
SPECIES: Psychedelic Frogfish
|
23
49
|
```
|
24
50
|
|
25
|
-
|
26
|
-
This block "[bash_set_to_3]" is required below. It sets the variable "ALPHA".
|
27
|
-
```bash :[bash_set_to_3]
|
28
|
-
ALPHA=3
|
29
|
-
```
|
30
|
-
::: Select below to trigger. If it prints "ALPHA: 3", the Link block was processed.
|
31
|
-
These blocks require the *code* of the named shell block.
|
32
|
-
```link +[bash_set_to_3]
|
33
|
-
block: "(display_variable_ALPHA)"
|
34
|
-
```
|
35
|
-
```link +[bash_set_to_3]
|
36
|
-
next_block: "(display_variable_ALPHA)"
|
37
|
-
```
|
51
|
+
### Link+Bash Blocks
|
38
52
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
These blocks require the *output* of the execution of the code in the named shell block.
|
45
|
-
```link +[bash_set_to_4]
|
46
|
-
eval: true
|
47
|
-
block: "(display_variable_ALPHA)"
|
53
|
+
::: Adding Code to the Inherited Lines
|
54
|
+
|
55
|
+
This Link block (YAML) appends the Bash code defined in the referenced block to the inherited lines:
|
56
|
+
|
57
|
+
```link :add-bash-code +[bash_species]
|
48
58
|
```
|
49
|
-
|
59
|
+
```bash :[bash_species] @disable
|
60
|
+
SPECIES='Ruby Seadragon'
|
61
|
+
```
|
62
|
+
|
63
|
+
If necessary to extract environment variable values displayed in the menu, inherited lines are executed every time the menu displayed. Therefore, do add code that has unwanted side effects when executed multiple times.
|
64
|
+
|
65
|
+
::: Adding Evaluated Code Output to the Inherited Lines
|
66
|
+
|
67
|
+
This Link block (YAML) appends the output of the Bash code to the inherited lines. The Bash code is executed first to generate the output:
|
68
|
+
|
69
|
+
```link :add-evaluated-bash-code +[bash_species_code]
|
50
70
|
eval: true
|
51
|
-
next_block: "(display_variable_ALPHA)"
|
52
71
|
```
|
72
|
+
```bash :[bash_species_code] @disable
|
73
|
+
echo "SPECIES='Illacme tobini (Millipede)'"
|
74
|
+
```
|
53
75
|
|
54
76
|
| Variable| Value
|
55
77
|
| -| -
|
56
|
-
|
|
78
|
+
| SPECIES| ${SPECIES}
|
57
79
|
|
58
|
-
|
59
|
-
```
|
80
|
+
@import example-document-opts.md
|
81
|
+
```opts :(document_opts)
|
82
|
+
execute_in_own_window: false
|
83
|
+
menu_with_inherited_lines: false
|
84
|
+
output_execution_report: false
|
85
|
+
output_execution_summary: false
|
86
|
+
pause_after_script_execution: true
|
87
|
+
```
|
data/lib/colorize.rb
CHANGED
@@ -13,23 +13,15 @@ class String
|
|
13
13
|
# @return [String] The formatted string.
|
14
14
|
def method_missing(method_name, *args, &block)
|
15
15
|
case method_name.to_s
|
16
|
-
# when /^bg_rgb_/
|
17
|
-
# bytes = $'.split('_')
|
18
|
-
# bg_rgb_color(bytes[0..2].join(';'))
|
19
16
|
when /^fg_bg_rgb_/
|
20
|
-
pp [__LINE__, caller[0]]; binding.irb
|
21
17
|
bytes = $'.split('_')
|
22
18
|
fg_bg_rgb_color(bytes[0..2].join(';'), bytes[3..5].join(';'))
|
23
19
|
when /^fg_bg_rgbh_/
|
24
|
-
pp [__LINE__, caller[0]]; binding.irb
|
25
20
|
hex_to_fg_bg_rgb($')
|
26
21
|
when /^fg_rgb_/
|
27
|
-
pp [__LINE__, caller[0]]; binding.irb
|
28
22
|
fg_rgb_color($'.gsub('_', ';'))
|
29
23
|
when /^fg_rgbh_/
|
30
|
-
pp [__LINE__, caller[0]]; binding.irb
|
31
24
|
hex_to_rgb($')
|
32
|
-
|
33
25
|
when 'to_a', 'to_ary', 'to_hash', 'to_int', 'to_io', 'to_regexp'
|
34
26
|
nil
|
35
27
|
else
|
@@ -41,24 +33,14 @@ class String
|
|
41
33
|
#
|
42
34
|
# @return [String] The string wrapped in an ANSI control sequence.
|
43
35
|
def ansi_control_sequence
|
44
|
-
pp [__LINE__, caller[0]]; binding.irb
|
45
36
|
"\033[#{self}\033[0m"
|
46
37
|
end
|
47
38
|
|
48
|
-
# # Applies a 24-bit RGB background color to the string.
|
49
|
-
# #
|
50
|
-
# # @param rgb [String] The RGB color, expressed as a string like "1;2;3".
|
51
|
-
# # @return [String] The string with the applied RGB foreground color.
|
52
|
-
# def bg_rgb_color(rgb)
|
53
|
-
# "48;2;#{rgb}m#{self}".ansi_control_sequence
|
54
|
-
# end
|
55
|
-
|
56
39
|
# Applies a 24-bit RGB foreground color to the string.
|
57
40
|
#
|
58
41
|
# @param rgb [String] The RGB color, expressed as a string like "1;2;3".
|
59
42
|
# @return [String] The string with the applied RGB foreground color.
|
60
43
|
def fg_bg_rgb_color(fg_rgb, bg_rgb)
|
61
|
-
pp [__LINE__, caller[0]]; binding.irb
|
62
44
|
"38;2;#{fg_rgb}m\033[48;2;#{bg_rgb}m#{self}".ansi_control_sequence
|
63
45
|
end
|
64
46
|
|
@@ -67,7 +49,6 @@ class String
|
|
67
49
|
# @param rgb [String] The RGB color, expressed as a string like "1;2;3".
|
68
50
|
# @return [String] The string with the applied RGB foreground color.
|
69
51
|
def fg_rgb_color(rgb)
|
70
|
-
pp [__LINE__, caller[0]]; binding.irb
|
71
52
|
"38;2;#{rgb}m#{self}".ansi_control_sequence
|
72
53
|
end
|
73
54
|
|
@@ -76,7 +57,6 @@ class String
|
|
76
57
|
# @param hex_str [String] The RGB color, expressed as a hex string like "FF00FF".
|
77
58
|
# @return [String] The string with the applied RGB foreground color.
|
78
59
|
def hex_to_fg_bg_rgb(hex_str)
|
79
|
-
pp [__LINE__, caller[0]]; binding.irb
|
80
60
|
values = hex_str.split('_').map { |hex| hex.to_i(16).to_s }
|
81
61
|
fg_bg_rgb_color(
|
82
62
|
values[0..2].join(';'),
|
@@ -89,7 +69,6 @@ class String
|
|
89
69
|
# @param hex_str [String] The RGB color, expressed as a hex string like "FF00FF".
|
90
70
|
# @return [String] The string with the applied RGB foreground color.
|
91
71
|
def hex_to_rgb(hex_str)
|
92
|
-
pp [__LINE__, caller[0]]; binding.irb
|
93
72
|
fg_rgb_color(
|
94
73
|
hex_str.split('_').map { |hex| hex.to_i(16).to_s }.join(';')
|
95
74
|
)
|
@@ -99,7 +78,6 @@ class String
|
|
99
78
|
#
|
100
79
|
# @return [String] The original string.
|
101
80
|
def plain
|
102
|
-
pp [__LINE__, caller[0]]; binding.irb
|
103
81
|
self
|
104
82
|
end
|
105
83
|
|
@@ -126,20 +104,16 @@ class String
|
|
126
104
|
def violet; fg_rgbh_94_00_D3; end
|
127
105
|
def yellow; fg_rgbh_FF_FF_00; end
|
128
106
|
|
129
|
-
def x
|
130
|
-
pp [__LINE__, caller[1]]; binding.irb
|
131
|
-
end
|
132
|
-
|
133
107
|
# graphics modes
|
134
|
-
def bold;
|
135
|
-
def bold_italic;
|
136
|
-
def bold_underline;
|
137
|
-
def dim;
|
138
|
-
def italic;
|
139
|
-
def underline;
|
140
|
-
def underline_italic;
|
141
|
-
def blinking;
|
142
|
-
def inverse;
|
143
|
-
def hidden;
|
144
|
-
def strikethrough;
|
108
|
+
def bold; "\033[1m#{self}\033[22m"; end
|
109
|
+
def bold_italic; "\033[1m\033[3m#{self}\033[22m\033[23m"; end
|
110
|
+
def bold_underline; "\033[1m\033[4m#{self}\033[22m\033[24m"; end
|
111
|
+
def dim; "\033[2m#{self}\033[22m"; end
|
112
|
+
def italic; "\033[3m#{self}\033[23m"; end
|
113
|
+
def underline; "\033[4m#{self}\033[24m"; end
|
114
|
+
def underline_italic; "\033[4m\033[3m#{self}\033[23m\033[24m"; end
|
115
|
+
def blinking; "\033[5m#{self}\033[25m"; end
|
116
|
+
def inverse; "\033[7m#{self}\033[27m"; end
|
117
|
+
def hidden; "\033[8m#{self}\033[28m"; end
|
118
|
+
def strikethrough; "\033[9m#{self}\033[29m"; end
|
145
119
|
end
|
data/lib/fcb.rb
CHANGED
@@ -35,6 +35,14 @@ module MarkdownExec
|
|
35
35
|
}.merge(options)
|
36
36
|
end
|
37
37
|
|
38
|
+
def code_name_included?(*names)
|
39
|
+
names.include?(@attrs[:oname])
|
40
|
+
end
|
41
|
+
|
42
|
+
def code_name_exp?(regexp)
|
43
|
+
Regexp.new(regexp) =~ @attrs[:oname]
|
44
|
+
end
|
45
|
+
|
38
46
|
# Derives a title from the body of an FCB object.
|
39
47
|
# @param fcb [Object] The FCB object whose title is to be derived.
|
40
48
|
# @return [String] The derived title.
|
@@ -152,23 +160,27 @@ module MarkdownExec
|
|
152
160
|
@attrs.to_yaml
|
153
161
|
end
|
154
162
|
|
155
|
-
# Expand variables in
|
163
|
+
# Expand variables in attributes
|
164
|
+
####
|
156
165
|
def expand_variables_in_attributes!(pattern, replacements)
|
157
|
-
|
158
|
-
|
159
|
-
# Replace variables in `dname` using the replacements dictionary
|
166
|
+
@attrs[:raw_dname] ||= @attrs[:dname]
|
160
167
|
@attrs[:dname] = @attrs[:dname]&.gsub(pattern) do |match|
|
161
168
|
replacements[match]
|
162
169
|
end
|
170
|
+
|
171
|
+
@attrs[:raw_s0printable] ||= @attrs[:s0printable]
|
163
172
|
@attrs[:s0printable] = @attrs[:s0printable]&.gsub(pattern) do |match|
|
164
173
|
replacements[match]
|
165
174
|
end
|
175
|
+
|
176
|
+
@attrs[:raw_s1decorated] ||= @attrs[:s1decorated]
|
166
177
|
@attrs[:s1decorated] = @attrs[:s1decorated]&.gsub(pattern) do |match|
|
167
178
|
replacements[match]
|
168
179
|
end
|
169
180
|
|
170
181
|
# Replace variables in each line of `body` if `body` is present
|
171
182
|
if @attrs[:body]
|
183
|
+
@attrs[:raw_body] ||= @attrs[:body]
|
172
184
|
@attrs[:body] = @attrs[:body]&.map do |line|
|
173
185
|
if line.empty?
|
174
186
|
line
|