regexrx2md 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +111 -0
- data/LICENSE.txt +20 -0
- data/README.md +145 -0
- data/README.rdoc +3 -0
- data/Rakefile +87 -0
- data/buildnotes.md +47 -0
- data/lib/regexrx2md/regexrx.rb +135 -0
- data/lib/regexrx2md/string.rb +22 -0
- data/lib/regexrx2md/version.rb +5 -0
- data/lib/regexrx2md.rb +63 -0
- data/regexrx2md.gemspec +42 -0
- metadata +234 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cbc4f295a8392614cd5b1cb3570906f79486541a1985a0cc99890334c3da9bb4
|
4
|
+
data.tar.gz: da5f5ae49cffbbbc8ba0e8a1e0c1b71b59cebbbf79b1ea9fe7571917ae2bc5f9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3a1a1991065961d8ca0e2919c412942be21542260e108ac374b1e195ebd92abfdbe2d843bb670119d6bcd532929dcacf77af10378037b53d35d3f70e77bb6aeb
|
7
|
+
data.tar.gz: 07c7f48fd4d742f2381bf74015b59174d86499a65baf41caa7468dbffc1b5e1233de0d29eccea5c6c54c9e41dfa88c0a2741aac6256823793bdbb4bc73fb772d
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
### 1.0.0
|
2
|
+
|
3
|
+
2023-08-20 12:25
|
4
|
+
|
5
|
+
# Change Log
|
6
|
+
|
7
|
+
All notable changes to this project will be documented in this file.
|
8
|
+
|
9
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/)
|
10
|
+
and this project adheres to [Semantic Versioning](https://semver.org/).
|
11
|
+
|
12
|
+
## Unreleased
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
regexrx2md (1.0.0)
|
5
|
+
erb (~> 4.0)
|
6
|
+
nokogiri (~> 1.5)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ansi (1.5.0)
|
12
|
+
ast (2.4.2)
|
13
|
+
awesome_print (1.9.2)
|
14
|
+
cgi (0.3.6)
|
15
|
+
diff-lcs (1.5.0)
|
16
|
+
docile (1.4.0)
|
17
|
+
erb (4.0.2)
|
18
|
+
cgi (>= 0.3.3)
|
19
|
+
gem-release (2.2.2)
|
20
|
+
json (2.6.3)
|
21
|
+
language_server-protocol (3.17.0.2)
|
22
|
+
mini_portile2 (2.8.4)
|
23
|
+
multi_json (1.15.0)
|
24
|
+
nokogiri (1.15.4)
|
25
|
+
mini_portile2 (~> 2.8.2)
|
26
|
+
racc (~> 1.4)
|
27
|
+
parallel (1.22.1)
|
28
|
+
parse_gemspec (1.0.0)
|
29
|
+
parse_gemspec-cli (1.0.0)
|
30
|
+
multi_json
|
31
|
+
parse_gemspec
|
32
|
+
thor
|
33
|
+
parser (3.1.3.0)
|
34
|
+
ast (~> 2.4.1)
|
35
|
+
racc (1.7.1)
|
36
|
+
rainbow (3.1.1)
|
37
|
+
rake (13.0.6)
|
38
|
+
regexp_parser (2.6.1)
|
39
|
+
rexml (3.2.5)
|
40
|
+
rspec (3.12.0)
|
41
|
+
rspec-core (~> 3.12.0)
|
42
|
+
rspec-expectations (~> 3.12.0)
|
43
|
+
rspec-mocks (~> 3.12.0)
|
44
|
+
rspec-core (3.12.0)
|
45
|
+
rspec-support (~> 3.12.0)
|
46
|
+
rspec-expectations (3.12.1)
|
47
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
48
|
+
rspec-support (~> 3.12.0)
|
49
|
+
rspec-mocks (3.12.1)
|
50
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
51
|
+
rspec-support (~> 3.12.0)
|
52
|
+
rspec-support (3.12.0)
|
53
|
+
rubocop (1.40.0)
|
54
|
+
json (~> 2.3)
|
55
|
+
parallel (~> 1.10)
|
56
|
+
parser (>= 3.1.2.1)
|
57
|
+
rainbow (>= 2.2.2, < 4.0)
|
58
|
+
regexp_parser (>= 1.8, < 3.0)
|
59
|
+
rexml (>= 3.2.5, < 4.0)
|
60
|
+
rubocop-ast (>= 1.23.0, < 2.0)
|
61
|
+
ruby-progressbar (~> 1.7)
|
62
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
63
|
+
rubocop-ast (1.24.1)
|
64
|
+
parser (>= 3.1.1.0)
|
65
|
+
rubocop-performance (1.15.1)
|
66
|
+
rubocop (>= 1.7.0, < 2.0)
|
67
|
+
rubocop-ast (>= 0.4.0)
|
68
|
+
ruby-progressbar (1.11.0)
|
69
|
+
simplecov (0.22.0)
|
70
|
+
docile (~> 1.1)
|
71
|
+
simplecov-html (~> 0.11)
|
72
|
+
simplecov_json_formatter (~> 0.1)
|
73
|
+
simplecov-console (0.9.1)
|
74
|
+
ansi
|
75
|
+
simplecov
|
76
|
+
terminal-table
|
77
|
+
simplecov-html (0.12.3)
|
78
|
+
simplecov_json_formatter (0.1.4)
|
79
|
+
standard (1.20.0)
|
80
|
+
language_server-protocol (~> 3.17.0.2)
|
81
|
+
rubocop (= 1.40.0)
|
82
|
+
rubocop-performance (= 1.15.1)
|
83
|
+
terminal-table (3.0.2)
|
84
|
+
unicode-display_width (>= 1.1.1, < 3)
|
85
|
+
thor (1.2.1)
|
86
|
+
unicode-display_width (2.3.0)
|
87
|
+
yard (0.9.34)
|
88
|
+
|
89
|
+
PLATFORMS
|
90
|
+
arm64-darwin-21
|
91
|
+
x64-mingw-ucr
|
92
|
+
x64-mingw-ucrt
|
93
|
+
x64-mingw32
|
94
|
+
x86_64-darwin
|
95
|
+
x86_64-linux
|
96
|
+
|
97
|
+
DEPENDENCIES
|
98
|
+
awesome_print (~> 1.9)
|
99
|
+
bundler (~> 2.0)
|
100
|
+
gem-release (~> 2.2)
|
101
|
+
parse_gemspec-cli (~> 1.0)
|
102
|
+
rake (~> 13.0)
|
103
|
+
regexrx2md!
|
104
|
+
rspec (~> 3.0)
|
105
|
+
simplecov (~> 0.21)
|
106
|
+
simplecov-console (~> 0.9)
|
107
|
+
standard (~> 1.3)
|
108
|
+
yard (~> 0.9, >= 0.9.26)
|
109
|
+
|
110
|
+
BUNDLED WITH
|
111
|
+
2.4.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Brett Terpstra
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
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, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
# RegExRX2MD
|
2
|
+
|
3
|
+
[![RubyGems.org](https://img.shields.io/gem/v/regexrx2md)](https://rubygems.org/gems/regexrx2md)
|
4
|
+
|
5
|
+
Convert [RegExRX](https://apps.apple.com/us/app/regexrx/id498370702?mt=12) file to Markdown
|
6
|
+
|
7
|
+
<!--README-->
|
8
|
+
## Description
|
9
|
+
|
10
|
+
Converts native RegExRX documents to Markdown files containing code snippets that work with [Snibbets](https://brettterpstra.com/projects/snibbets/) or any Markdown viewer.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
```
|
15
|
+
$ gem install regexrx2md
|
16
|
+
```
|
17
|
+
|
18
|
+
If you run into errors, try:
|
19
|
+
|
20
|
+
```
|
21
|
+
$ gem install --user-install regexrx2md
|
22
|
+
```
|
23
|
+
|
24
|
+
### Usage
|
25
|
+
|
26
|
+
Run `regexrx2md` in a directory containing `.regexrx` files and all matching files will be processed to Markdown files in a `markdown` subdirectory.
|
27
|
+
|
28
|
+
If the argument is a directory, all `.regexrx` files in the directory will be processed and output to the `--output-dir` destination (which defaults to `markdown`). If the argument is a single `.regexrx` file, only that file will be processed. Markdown filenames will be based on the title of the RegExRX file, either from the built-in name field, or from the filename if it's untitled.
|
29
|
+
|
30
|
+
Options:
|
31
|
+
|
32
|
+
```
|
33
|
+
Usage: bin/regexrx2md [OPTIONS] [SOURCE FILE/DIR]
|
34
|
+
|
35
|
+
Converts RegExRx files to Markdown, optionally with template.
|
36
|
+
If source argument is empty, process all .regexrx files in current directory.
|
37
|
+
|
38
|
+
Options:
|
39
|
+
-o, --output-dir=DIRECTORY Output folder
|
40
|
+
Defaults to "./markdown"
|
41
|
+
-p, --prefix=PREFIX Prefix added before output filenames
|
42
|
+
Space automatically added after prefix
|
43
|
+
-t, --template=TEMPLATE Use alternate ERB template
|
44
|
+
-h, --help Display this screen
|
45
|
+
-x, --example Output the default ERB template to STDOUT
|
46
|
+
```
|
47
|
+
|
48
|
+
You can specify a prefix for filenames using the `--prefix` option. For example, using `--prefix="RX - "` would cause `URL detector.regexrx` to create `RX - URL detector.md` as the Markdown output file.
|
49
|
+
|
50
|
+
The default template outputs notes as block quotes and snippets as Ruby fenced code blocks. You can adjust this by using a custom ERB template. Just output the default template using `--example`, save it to a new file and edit as needed, then pass the new file using `--template=NEW_FILE.erb`. The template file must be named with an `erb` extension.
|
51
|
+
<!--END README-->
|
52
|
+
|
53
|
+
### Source code
|
54
|
+
|
55
|
+
The [source code] is hosted on GitHub.
|
56
|
+
Clone the project with
|
57
|
+
|
58
|
+
```
|
59
|
+
$ git clone git@github.com:ttscoff/regexrx2md.git
|
60
|
+
```
|
61
|
+
|
62
|
+
[source code]: https://github.com/ttscoff/regexrx2md
|
63
|
+
|
64
|
+
## Development and Testing
|
65
|
+
|
66
|
+
### Quickstart
|
67
|
+
|
68
|
+
```
|
69
|
+
$ git clone https://github.com/ttscoff/regexrx2md.git
|
70
|
+
$ cd regexrx2md
|
71
|
+
$ bundle install
|
72
|
+
```
|
73
|
+
|
74
|
+
Run the command below
|
75
|
+
|
76
|
+
```
|
77
|
+
$ bundle exec bin/regexrx2md
|
78
|
+
```
|
79
|
+
|
80
|
+
Open an interactive ruby console with
|
81
|
+
|
82
|
+
```
|
83
|
+
$ bundle exec rake console
|
84
|
+
```
|
85
|
+
|
86
|
+
Primary development tasks are defined as [rake] tasks in the `Rakefile`
|
87
|
+
and available via `rake`.
|
88
|
+
View them with
|
89
|
+
|
90
|
+
```
|
91
|
+
$ bundle exec rake -T
|
92
|
+
```
|
93
|
+
|
94
|
+
[rake]: https://ruby.github.io/rake/
|
95
|
+
|
96
|
+
### Requirements
|
97
|
+
|
98
|
+
You will need [Ruby] with [Bundler].
|
99
|
+
|
100
|
+
Be sure that all commands run under the correct Ruby version, e.g.,
|
101
|
+
if using [rbenv], install the correct version with
|
102
|
+
|
103
|
+
```
|
104
|
+
$ rbenv install
|
105
|
+
```
|
106
|
+
|
107
|
+
Install the development dependencies with
|
108
|
+
|
109
|
+
```
|
110
|
+
$ bundle install
|
111
|
+
```
|
112
|
+
|
113
|
+
[bundler]: https://bundler.io/
|
114
|
+
[ruby]: https://www.ruby-lang.org/
|
115
|
+
[rbenv]: https://github.com/rbenv/rbenv
|
116
|
+
|
117
|
+
## Contributing
|
118
|
+
|
119
|
+
Please submit and comment on bug reports and feature requests.
|
120
|
+
|
121
|
+
To submit a patch:
|
122
|
+
|
123
|
+
1. Fork it (https://github.com/ttscoff/regexrx2md/fork).
|
124
|
+
2. Create your feature branch (`git checkout -b my-new-feature`).
|
125
|
+
3. Make changes.
|
126
|
+
4. Commit your changes (`git commit -am 'Add some feature'`).
|
127
|
+
5. Push to the branch (`git push origin my-new-feature`).
|
128
|
+
6. Create a new Pull Request.
|
129
|
+
|
130
|
+
## License
|
131
|
+
|
132
|
+
This Ruby gem is licensed under the MIT license.
|
133
|
+
|
134
|
+
## Warranty
|
135
|
+
|
136
|
+
This software is provided by the copyright holders and contributors "as is" and
|
137
|
+
any express or implied warranties, including, but not limited to, the implied
|
138
|
+
warranties of merchantability and fitness for a particular purpose are
|
139
|
+
disclaimed. In no event shall the copyright holder or contributors be liable for
|
140
|
+
any direct, indirect, incidental, special, exemplary, or consequential damages
|
141
|
+
(including, but not limited to, procurement of substitute goods or services;
|
142
|
+
loss of use, data, or profits; or business interruption) however caused and on
|
143
|
+
any theory of liability, whether in contract, strict liability, or tort
|
144
|
+
(including negligence or otherwise) arising in any way out of the use of this
|
145
|
+
software, even if advised of the possibility of such damage.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
require "standard/rake"
|
6
|
+
require 'rdoc/task'
|
7
|
+
require 'yard'
|
8
|
+
|
9
|
+
Rake::RDocTask.new do |rd|
|
10
|
+
rd.main = "README.rdoc"
|
11
|
+
rd.rdoc_files.include("README.rdoc", "lib/**/*.rb", "bin/**/*")
|
12
|
+
rd.title = 'RegExRX2MD'
|
13
|
+
end
|
14
|
+
|
15
|
+
YARD::Rake::YardocTask.new do |t|
|
16
|
+
t.files = ['lib/na/*.rb']
|
17
|
+
t.options = ['--markup-provider=redcarpet', '--markup=markdown', '--no-private', '-p', 'yard_templates']
|
18
|
+
# t.stats_options = ['--list-undoc']
|
19
|
+
end
|
20
|
+
|
21
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
22
|
+
t.rspec_opts = "--pattern {spec,lib}/**/*_spec.rb"
|
23
|
+
end
|
24
|
+
|
25
|
+
task default: %i[lint test]
|
26
|
+
|
27
|
+
desc 'Alias for build'
|
28
|
+
task :package => :build
|
29
|
+
|
30
|
+
task test: "spec"
|
31
|
+
task lint: "standard"
|
32
|
+
task format: "standard:fix"
|
33
|
+
|
34
|
+
desc "Open an interactive ruby console"
|
35
|
+
task :console do
|
36
|
+
require "irb"
|
37
|
+
require "bundler/setup"
|
38
|
+
require "regexrx2md"
|
39
|
+
ARGV.clear
|
40
|
+
IRB.start
|
41
|
+
end
|
42
|
+
|
43
|
+
desc 'Development version check'
|
44
|
+
task :ver do
|
45
|
+
gver = `git ver`
|
46
|
+
cver = IO.read(File.join(File.dirname(__FILE__), 'CHANGELOG.md')).match(/^#+ (\d+\.\d+\.\d+(\w+)?)/)[1]
|
47
|
+
res = `grep VERSION lib/regexrx2md/version.rb`
|
48
|
+
version = res.match(/VERSION *= *['"](\d+\.\d+\.\d+(\w+)?)/)[1]
|
49
|
+
puts "git tag: #{gver}"
|
50
|
+
puts "version.rb: #{version}"
|
51
|
+
puts "changelog: #{cver}"
|
52
|
+
end
|
53
|
+
|
54
|
+
desc 'Changelog version check'
|
55
|
+
task :cver do
|
56
|
+
puts IO.read(File.join(File.dirname(__FILE__), 'CHANGELOG.md')).match(/^#+ (\d+\.\d+\.\d+(\w+)?)/)[1]
|
57
|
+
end
|
58
|
+
|
59
|
+
desc 'Bump incremental version number'
|
60
|
+
task :bump, :type do |_, args|
|
61
|
+
args.with_defaults(type: 'inc')
|
62
|
+
version_file = 'lib/regexrx2md/version.rb'
|
63
|
+
content = IO.read(version_file)
|
64
|
+
content.sub!(/VERSION = '(?<major>\d+)\.(?<minor>\d+)\.(?<inc>\d+)(?<pre>\S+)?'/) do
|
65
|
+
m = Regexp.last_match
|
66
|
+
major = m['major'].to_i
|
67
|
+
minor = m['minor'].to_i
|
68
|
+
inc = m['inc'].to_i
|
69
|
+
pre = m['pre']
|
70
|
+
|
71
|
+
case args[:type]
|
72
|
+
when /^maj/
|
73
|
+
major += 1
|
74
|
+
minor = 0
|
75
|
+
inc = 0
|
76
|
+
when /^min/
|
77
|
+
minor += 1
|
78
|
+
inc = 0
|
79
|
+
else
|
80
|
+
inc += 1
|
81
|
+
end
|
82
|
+
|
83
|
+
$stdout.puts "At version #{major}.#{minor}.#{inc}#{pre}"
|
84
|
+
"VERSION = '#{major}.#{minor}.#{inc}#{pre}'"
|
85
|
+
end
|
86
|
+
File.open(version_file, 'w+') { |f| f.puts content }
|
87
|
+
end
|
data/buildnotes.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
template: gem, git, project
|
2
|
+
executable: regexrx2md
|
3
|
+
readme: README.md
|
4
|
+
changelog: CHANGELOG.md
|
5
|
+
project: regexrx2md
|
6
|
+
|
7
|
+
# RegExRX2MD
|
8
|
+
|
9
|
+
Convert [RegExRX](https://apps.apple.com/us/app/regexrx/id498370702?mt=12) files to Markdown.
|
10
|
+
|
11
|
+
|
12
|
+
## Develop
|
13
|
+
|
14
|
+
@run(subl .)
|
15
|
+
|
16
|
+
## Dummy
|
17
|
+
|
18
|
+
@run(bundle exec bin/regexrx2md $@)
|
19
|
+
|
20
|
+
## Deploy
|
21
|
+
|
22
|
+
You no longer need to manually bump the version, it will be incremented when this task runs.
|
23
|
+
|
24
|
+
```run Update Changelog
|
25
|
+
#!/bin/bash
|
26
|
+
|
27
|
+
changelog -u
|
28
|
+
```
|
29
|
+
|
30
|
+
```run Update README
|
31
|
+
#!/bin/bash
|
32
|
+
|
33
|
+
changelog | git commit -a -F -
|
34
|
+
git pull
|
35
|
+
git push
|
36
|
+
```
|
37
|
+
|
38
|
+
@run(rake clobber package)
|
39
|
+
@include(gem:Release Gem) Release Gem
|
40
|
+
@include(project:Update Blog Project) Update Blog Project
|
41
|
+
@run(rake bump[patch]) Bump Version
|
42
|
+
|
43
|
+
@run(git commit -am 'Version bump')
|
44
|
+
|
45
|
+
@after
|
46
|
+
Don't forget to publish the website!
|
47
|
+
@end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RegExRX2MD
|
4
|
+
# Reads RegExRX document and outputs template
|
5
|
+
class RegexRX
|
6
|
+
attr_reader :title, :search, :flags, :replace, :source
|
7
|
+
|
8
|
+
def initialize(file)
|
9
|
+
doc = File.open(file) { |f| Nokogiri::XML(f) }
|
10
|
+
@content = doc.xpath('RegExRX_Document')
|
11
|
+
@title = doc.xpath('//Window').first['Title'].strip
|
12
|
+
@title = File.basename(file, '.regexrx') if @title =~ /^Untitled RegExRX/
|
13
|
+
|
14
|
+
@search = rx_search
|
15
|
+
@flags = rx_flags
|
16
|
+
@flags_desc = describe_flags
|
17
|
+
@replace = rx_replace
|
18
|
+
@source = rx_source
|
19
|
+
|
20
|
+
@search.sub!(/^(\(\?[-misUXxJ]+\))?/, "(?#{@flags})")
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_markdown(template)
|
24
|
+
out = ERB.new(template).result(binding)
|
25
|
+
|
26
|
+
out.force_encoding('utf-8')
|
27
|
+
end
|
28
|
+
|
29
|
+
def rx_search
|
30
|
+
grab_string('fldSearch')
|
31
|
+
end
|
32
|
+
|
33
|
+
def rx_replace
|
34
|
+
grab_pref('Do Replace') ? grab_string('fldReplace') : false
|
35
|
+
end
|
36
|
+
|
37
|
+
def rx_source
|
38
|
+
source = grab_string('fldSource')
|
39
|
+
source.empty? ? false : source
|
40
|
+
end
|
41
|
+
|
42
|
+
def rx_flags
|
43
|
+
positives = []
|
44
|
+
negatives = []
|
45
|
+
|
46
|
+
if grab_opt('Treat Target As One Line')
|
47
|
+
positives << 'm'
|
48
|
+
else
|
49
|
+
negatives << 'm'
|
50
|
+
end
|
51
|
+
|
52
|
+
if grab_opt('Dot Matches Newline')
|
53
|
+
positives << 's'
|
54
|
+
else
|
55
|
+
negatives << 's'
|
56
|
+
end
|
57
|
+
|
58
|
+
if grab_opt('Case Sensitive')
|
59
|
+
negatives << 'i'
|
60
|
+
else
|
61
|
+
positives << 'i'
|
62
|
+
end
|
63
|
+
|
64
|
+
negatives << 'U' if grab_opt('Greedy')
|
65
|
+
|
66
|
+
search_flags = flags_in_search
|
67
|
+
unless search_flags.nil?
|
68
|
+
ps = search_flags[0] || nil
|
69
|
+
ns = search_flags[1] || nil
|
70
|
+
positives.concat(ps.delete_if { |pos| positives.include?(pos) }) unless ps.nil?
|
71
|
+
negatives.concat(ns.delete_if { |neg| negatives.include?(neg) }) unless ns.nil?
|
72
|
+
end
|
73
|
+
|
74
|
+
flags = positives.sort.join('')
|
75
|
+
flags += "-#{negatives.sort.join('')}" unless negatives.empty?
|
76
|
+
|
77
|
+
flags.empty? ? false : flags
|
78
|
+
end
|
79
|
+
|
80
|
+
def flags_in_search
|
81
|
+
@search ||= rx_search
|
82
|
+
positives = []
|
83
|
+
negatives = []
|
84
|
+
|
85
|
+
res = @search.match(/\(\?([-msiUxXJ]+)\)/)
|
86
|
+
res ? res[1].split(/-/).map(&:split) : nil
|
87
|
+
end
|
88
|
+
|
89
|
+
def describe_flags
|
90
|
+
@flags ||= rx_flags
|
91
|
+
|
92
|
+
positives, negatives = @flags.split(/-/)
|
93
|
+
descs = {
|
94
|
+
m: ['Treat target as one line', 'Do not treat target as one line'],
|
95
|
+
i: ['Case insensitive', 'Case sensitive'],
|
96
|
+
s: ['Dot matches newline', 'Dot does not match newline'],
|
97
|
+
U: ['Not greedy', 'Greedy'],
|
98
|
+
x: ['Free spacing', 'No free spacing'],
|
99
|
+
X: ['Character following \ must have special meaning', 'Character following \ treated as literal'],
|
100
|
+
J: ['Allow duplicate group names', 'Disallow duplicate group names']
|
101
|
+
}
|
102
|
+
|
103
|
+
ps = positives.nil? ? [] : positives.split('').map(&:to_sym)
|
104
|
+
ns = negatives.nil? ? [] : negatives.split('').map(&:to_sym)
|
105
|
+
|
106
|
+
desc = []
|
107
|
+
|
108
|
+
%i[m i s U J X x].each do |flag|
|
109
|
+
desc << if ps.include?(flag)
|
110
|
+
"#{flag.to_s}: #{descs[flag][0]}"
|
111
|
+
elsif ns.include?(flag)
|
112
|
+
"-#{flag.to_s}: #{descs[flag][1]}"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
desc.delete_if(&:nil?).sort.map { |f| "* #{f}" }.join("\n")
|
117
|
+
end
|
118
|
+
|
119
|
+
def grab_string(name)
|
120
|
+
out = @content.xpath("//Control[@name=\"#{name}\"]").first
|
121
|
+
.content
|
122
|
+
.strip
|
123
|
+
.force_encoding('utf-8')
|
124
|
+
out.unpack
|
125
|
+
end
|
126
|
+
|
127
|
+
def grab_pref(name)
|
128
|
+
@content.xpath("//Preference[@name='#{name}']").first['value'] == 'true'
|
129
|
+
end
|
130
|
+
|
131
|
+
def grab_opt(name)
|
132
|
+
@content.xpath("//OptionMenu[@text='#{name}']").first['checked'] == 'true'
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# String helpers
|
4
|
+
class ::String
|
5
|
+
def unpack
|
6
|
+
[self].pack('H*').gsub(/\r/, "\n")
|
7
|
+
end
|
8
|
+
|
9
|
+
def indent
|
10
|
+
out = ''
|
11
|
+
split("\n").each { |line| out += " #{line}\n" }
|
12
|
+
out
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_js
|
16
|
+
gsub(%r{(?mi)(?<!\\)/}, '\/')
|
17
|
+
end
|
18
|
+
|
19
|
+
def snippet_note
|
20
|
+
split("\n").map { |line| "> #{line}" }.join("\n")
|
21
|
+
end
|
22
|
+
end
|
data/lib/regexrx2md.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'erb'
|
5
|
+
require_relative 'regexrx2md/version'
|
6
|
+
require_relative 'regexrx2md/string'
|
7
|
+
require_relative 'regexrx2md/regexrx'
|
8
|
+
|
9
|
+
def class_exists?(class_name)
|
10
|
+
klass = Module.const_get(class_name)
|
11
|
+
klass.is_a?(Class)
|
12
|
+
rescue NameError
|
13
|
+
false
|
14
|
+
end
|
15
|
+
|
16
|
+
if class_exists? 'Encoding'
|
17
|
+
Encoding.default_external = Encoding::UTF_8 if Encoding.respond_to?('default_external')
|
18
|
+
Encoding.default_internal = Encoding::UTF_8 if Encoding.respond_to?('default_internal')
|
19
|
+
end
|
20
|
+
|
21
|
+
module RegExRX2MD
|
22
|
+
DEFAULT_TEMPLATE = <<~ENDOFTEMPLATE
|
23
|
+
title: <%= @title %>
|
24
|
+
<% if @flags %>
|
25
|
+
## Flags
|
26
|
+
|
27
|
+
> Flags: `(?<%= @flags %>)`
|
28
|
+
|
29
|
+
<%= @flags_desc.snippet_note %>
|
30
|
+
<% end %>
|
31
|
+
## Regular Expression Search
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
/<%= @search %>/
|
35
|
+
```<% if @replace %>
|
36
|
+
|
37
|
+
## Replace
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
"<%= @replace.gsub(/\$/, '\\\\') %>"
|
41
|
+
```<% end %>
|
42
|
+
<% if @source %>
|
43
|
+
---
|
44
|
+
|
45
|
+
## Test string:
|
46
|
+
|
47
|
+
```text
|
48
|
+
<%= @source %>
|
49
|
+
```
|
50
|
+
<% end %>
|
51
|
+
|
52
|
+
ENDOFTEMPLATE
|
53
|
+
|
54
|
+
def self.process_file(file, options, template)
|
55
|
+
# Process the file, generating a new RegexRX object
|
56
|
+
rx = RegexRX.new(file)
|
57
|
+
# Name the file with output directory, prefix, and title, with .md extension
|
58
|
+
filename = File.join(options[:output], "#{options[:prefix]}#{rx.title}.md")
|
59
|
+
# Write the file
|
60
|
+
File.open(filename, 'w') { |f| f.print(rx.to_markdown(template)) }
|
61
|
+
warn "Regex written to #{filename}"
|
62
|
+
end
|
63
|
+
end
|
data/regexrx2md.gemspec
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/regexrx2md/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "regexrx2md"
|
7
|
+
spec.version = RegExRX2MD::VERSION
|
8
|
+
spec.author = "Brett Terpstra"
|
9
|
+
spec.email = "me@brettterpstra.com"
|
10
|
+
|
11
|
+
spec.summary = "RegExRX2MD"
|
12
|
+
spec.description = "Convert RegExRX file to Markdown"
|
13
|
+
spec.homepage = "https://github.com/ttscoff/regexrx2md"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 3.0.0"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
19
|
+
spec.metadata["bug_tracker_uri"] = "#{spec.metadata["source_code_uri"]}/issues"
|
20
|
+
spec.metadata["changelog_uri"] = "#{spec.metadata["source_code_uri"]}/blob/main/CHANGELOG.md"
|
21
|
+
spec.metadata["github_repo"] = "git@github.com:ttscoff/regexrx2md.git"
|
22
|
+
|
23
|
+
spec.bindir = "bin"
|
24
|
+
spec.executables = spec.files.grep(%r{\A#{spec.bindir}/}) { |f| File.basename(f) }
|
25
|
+
|
26
|
+
spec.files = Dir["lib/**/*.rb"].reject { |f| f.end_with?("_spec.rb") }
|
27
|
+
spec.files += Dir["[A-Z]*"]
|
28
|
+
|
29
|
+
spec.add_dependency "nokogiri", "~> 1.5"
|
30
|
+
spec.add_dependency "erb", "~> 4.0"
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
33
|
+
spec.add_development_dependency "awesome_print", "~> 1.9"
|
34
|
+
spec.add_development_dependency 'yard', '~> 0.9', '>= 0.9.26'
|
35
|
+
spec.add_development_dependency "gem-release", "~> 2.2"
|
36
|
+
spec.add_development_dependency "parse_gemspec-cli", "~> 1.0"
|
37
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
38
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
39
|
+
spec.add_development_dependency "simplecov", "~> 0.21"
|
40
|
+
spec.add_development_dependency "simplecov-console", "~> 0.9"
|
41
|
+
spec.add_development_dependency "standard", "~> 1.3"
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,234 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: regexrx2md
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brett Terpstra
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-08-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: erb
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: awesome_print
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.9'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: yard
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.9'
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 0.9.26
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - "~>"
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0.9'
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 0.9.26
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: gem-release
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '2.2'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '2.2'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: parse_gemspec-cli
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '1.0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '1.0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: rake
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '13.0'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '13.0'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: rspec
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '3.0'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '3.0'
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: simplecov
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - "~>"
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0.21'
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - "~>"
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0.21'
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
name: simplecov-console
|
161
|
+
requirement: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - "~>"
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0.9'
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - "~>"
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0.9'
|
173
|
+
- !ruby/object:Gem::Dependency
|
174
|
+
name: standard
|
175
|
+
requirement: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - "~>"
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '1.3'
|
180
|
+
type: :development
|
181
|
+
prerelease: false
|
182
|
+
version_requirements: !ruby/object:Gem::Requirement
|
183
|
+
requirements:
|
184
|
+
- - "~>"
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: '1.3'
|
187
|
+
description: Convert RegExRX file to Markdown
|
188
|
+
email: me@brettterpstra.com
|
189
|
+
executables: []
|
190
|
+
extensions: []
|
191
|
+
extra_rdoc_files: []
|
192
|
+
files:
|
193
|
+
- CHANGELOG.md
|
194
|
+
- Gemfile
|
195
|
+
- Gemfile.lock
|
196
|
+
- LICENSE.txt
|
197
|
+
- README.md
|
198
|
+
- README.rdoc
|
199
|
+
- Rakefile
|
200
|
+
- buildnotes.md
|
201
|
+
- lib/regexrx2md.rb
|
202
|
+
- lib/regexrx2md/regexrx.rb
|
203
|
+
- lib/regexrx2md/string.rb
|
204
|
+
- lib/regexrx2md/version.rb
|
205
|
+
- regexrx2md.gemspec
|
206
|
+
homepage: https://github.com/ttscoff/regexrx2md
|
207
|
+
licenses:
|
208
|
+
- MIT
|
209
|
+
metadata:
|
210
|
+
homepage_uri: https://github.com/ttscoff/regexrx2md
|
211
|
+
source_code_uri: https://github.com/ttscoff/regexrx2md
|
212
|
+
bug_tracker_uri: https://github.com/ttscoff/regexrx2md/issues
|
213
|
+
changelog_uri: https://github.com/ttscoff/regexrx2md/blob/main/CHANGELOG.md
|
214
|
+
github_repo: git@github.com:ttscoff/regexrx2md.git
|
215
|
+
post_install_message:
|
216
|
+
rdoc_options: []
|
217
|
+
require_paths:
|
218
|
+
- lib
|
219
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
220
|
+
requirements:
|
221
|
+
- - ">="
|
222
|
+
- !ruby/object:Gem::Version
|
223
|
+
version: 3.0.0
|
224
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
225
|
+
requirements:
|
226
|
+
- - ">="
|
227
|
+
- !ruby/object:Gem::Version
|
228
|
+
version: '0'
|
229
|
+
requirements: []
|
230
|
+
rubygems_version: 3.4.0.dev
|
231
|
+
signing_key:
|
232
|
+
specification_version: 4
|
233
|
+
summary: RegExRX2MD
|
234
|
+
test_files: []
|