inline_fn 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: 2aea4c765086fc66c89701e21aa1731b859d45b656c59e8eb68c9f4a1d7810fe
4
+ data.tar.gz: 7f07d0969719a474ed98e57968db739447c819cfa059ac4ed731ae05f0f2a4d3
5
+ SHA512:
6
+ metadata.gz: 23106280f4efadad18a2d10ed4f0414bc05e604c9160a11e48f81a28725df4298efe69f20b9a89bc82e89ebf28f1d97a0220134b25363c9eea478b4fe9ed2f6d
7
+ data.tar.gz: 68f76f271fc300e4a7f442f881206c4b0dfdbc39772239312ec759d81273a0cbd950423e4f091385edb471958fa44eb3078842bac09a1f12918a545d240d9d65
@@ -0,0 +1,16 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.0.2
14
+ bundler-cache: true
15
+ - name: Run the default task
16
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-08-25
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in inline_fn.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rubocop", "~> 1.7"
data/Gemfile.lock ADDED
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ inline_fn (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ parallel (1.20.1)
11
+ parser (3.0.2.0)
12
+ ast (~> 2.4.1)
13
+ rainbow (3.0.0)
14
+ rake (13.0.6)
15
+ regexp_parser (2.1.1)
16
+ rexml (3.2.5)
17
+ rubocop (1.19.1)
18
+ parallel (~> 1.10)
19
+ parser (>= 3.0.0.0)
20
+ rainbow (>= 2.2.2, < 4.0)
21
+ regexp_parser (>= 1.8, < 3.0)
22
+ rexml
23
+ rubocop-ast (>= 1.9.1, < 2.0)
24
+ ruby-progressbar (~> 1.7)
25
+ unicode-display_width (>= 1.4.0, < 3.0)
26
+ rubocop-ast (1.11.0)
27
+ parser (>= 3.0.1.1)
28
+ ruby-progressbar (1.11.0)
29
+ unicode-display_width (2.0.0)
30
+
31
+ PLATFORMS
32
+ arm64-darwin-20
33
+
34
+ DEPENDENCIES
35
+ inline_fn!
36
+ rake (~> 13.0)
37
+ rubocop (~> 1.7)
38
+
39
+ BUNDLED WITH
40
+ 2.2.25
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Bernardo C.D.A. Vasconcelos
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,71 @@
1
+ # InlineFn
2
+
3
+ There are two methods that work on strings. Use `str.inline_mmd` for Multimarkdown style or `str.inline_pandoc` for Pandoc style footnotes.
4
+
5
+
6
+ ## MMD
7
+
8
+ ```ruby
9
+ #!/usr/bin/env ruby
10
+ # frozen_string_literal: false
11
+
12
+ require 'inline_fn'
13
+
14
+ text = %(Lorem ipsum dolor sit amet[^1], consectetur adipisicing elit[^2], sed...
15
+ [^1]: Text of fn 1
16
+ [^2]: Text of fn 2)
17
+
18
+ puts text.inline_mmd
19
+ ```
20
+
21
+
22
+ ### Expected result
23
+
24
+ ```
25
+ Lorem ipsum dolor sit amet[^Text of fn 1], consectetur adipisicing elit[^Text of fn 2], sed...
26
+ ```
27
+
28
+ ## Pandoc
29
+
30
+ ```ruby
31
+ #!/usr/bin/env ruby
32
+ # frozen_string_literal: false
33
+
34
+ require 'inline_fn'
35
+
36
+ text = %(Lorem ipsum dolor sit amet[^1], consectetur adipisicing elit[^2], sed...
37
+ [^1]: Text of fn 1
38
+ [^2]: Text of fn 2)
39
+
40
+ puts text.inline_pandoc
41
+ ```
42
+
43
+ ### Expected result
44
+
45
+ ```
46
+ Lorem ipsum dolor sit amet^[Text of fn 1], consectetur adipisicing elit^[Text of fn 2], sed...
47
+ ```
48
+
49
+ ## Installation
50
+
51
+ Add this line to your application's Gemfile:
52
+
53
+ ```ruby
54
+ gem 'inline_fn'
55
+ ```
56
+
57
+ And then execute:
58
+
59
+ $ bundle install
60
+
61
+ Or install it yourself as:
62
+
63
+ $ gem install inline_fn
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bcdavasconcelos/inline_fn
68
+
69
+ ## License
70
+
71
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "inline_fn"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/inline_fn.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/inline_fn/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "inline_fn"
7
+ spec.version = InlineFn::VERSION
8
+ spec.authors = ["Bernardo C.D.A. Vasconcelos"]
9
+ spec.email = ["35749099+bcdavasconcelos@users.noreply.github.com"]
10
+
11
+ spec.summary = "Change markdown footnotes format from `[^1]/[^1]:Note` to inline Pandoc or MMD style `^[Note]/[^Note]`."
12
+ spec.description = "There are two methods that work on strings. Use `str.inline_mmd` for Multimarkdown style or `str.inline_pandoc` for Pandoc style footnotes."
13
+ spec.homepage = "https://github.com/bcdavasconcelos/inline_fn"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.4.0"
16
+
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/bcdavasconcelos/inline_fn.git"
20
+ spec.metadata["changelog_uri"] = "https://github.com/bcdavasconcelos/inline_fn/blob/master/CHANGELOG.md"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ # Uncomment to register a new dependency of your gem
32
+ # spec.add_dependency "example-gem", "~> 1.0"
33
+
34
+ # For more information and examples about making a new gem, checkout our
35
+ # guide at: https://bundler.io/guides/creating_gem.html
36
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module InlineFn
4
+ VERSION = "0.1.0"
5
+ end
data/lib/inline_fn.rb ADDED
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "inline_fn/version"
4
+
5
+ module InlineFn
6
+ class Error < StandardError; end
7
+ class String
8
+ def inline_mmd
9
+ text = self
10
+ counter = 0
11
+ pandoc_mode = false
12
+ loop do
13
+ counter += 1
14
+ cite = "[^#{counter}]"
15
+ ref = "[^#{counter}]:"
16
+ ref_start = text.index(ref)
17
+ break if ref_start.nil?
18
+
19
+ next_ref = "[^#{counter + 1}]:"
20
+ ref_end = text.index(next_ref).nil? ? -1 : text.index(next_ref) - 2
21
+ offset = counter.to_s.length + 5
22
+ note = pandoc_mode ? "^[#{text[ref_start + offset..ref_end].strip}]" : "[^#{text[ref_start + offset..ref_end].strip}]"
23
+
24
+ text.gsub!(cite, note)
25
+ end
26
+
27
+ if counter >= 1
28
+ text = pandoc_mode ? text.gsub(/\n\s*\^\[/, "\n^[") : text.gsub(/\n\s*\[\^/, "\n[^")
29
+ cut_point = pandoc_mode ? text.index("\n^") : text.index("\n[^")
30
+ text = text[0, cut_point]
31
+ # puts "#{counter -= 1} notes replaced."
32
+ end
33
+ puts text
34
+ end
35
+
36
+ def inline_pandoc
37
+ text = self
38
+ counter = 0
39
+ pandoc_mode = true
40
+ loop do
41
+ counter += 1
42
+ cite = "[^#{counter}]"
43
+ ref = "[^#{counter}]:"
44
+ ref_start = text.index(ref)
45
+ break if ref_start.nil?
46
+
47
+ next_ref = "[^#{counter + 1}]:"
48
+ ref_end = text.index(next_ref).nil? ? -1 : text.index(next_ref) - 2
49
+ offset = counter.to_s.length + 5
50
+ note = pandoc_mode ? "^[#{text[ref_start + offset..ref_end].strip}]" : "[^#{text[ref_start + offset..ref_end].strip}]"
51
+
52
+ text.gsub!(cite, note)
53
+ end
54
+
55
+ if counter >= 1
56
+ text = pandoc_mode ? text.gsub(/\n\s*\^\[/, "\n^[") : text.gsub(/\n\s*\[\^/, "\n[^")
57
+ cut_point = pandoc_mode ? text.index("\n^") : text.index("\n[^")
58
+ text = text[0, cut_point]
59
+ # puts "#{counter -= 1} notes replaced."
60
+ end
61
+ puts text
62
+ end
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inline_fn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bernardo C.D.A. Vasconcelos
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-09-05 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: There are two methods that work on strings. Use `str.inline_mmd` for
14
+ Multimarkdown style or `str.inline_pandoc` for Pandoc style footnotes.
15
+ email:
16
+ - 35749099+bcdavasconcelos@users.noreply.github.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".github/workflows/main.yml"
22
+ - ".gitignore"
23
+ - ".rubocop.yml"
24
+ - CHANGELOG.md
25
+ - Gemfile
26
+ - Gemfile.lock
27
+ - LICENSE.txt
28
+ - README.md
29
+ - Rakefile
30
+ - bin/console
31
+ - bin/setup
32
+ - inline_fn.gemspec
33
+ - lib/inline_fn.rb
34
+ - lib/inline_fn/version.rb
35
+ homepage: https://github.com/bcdavasconcelos/inline_fn
36
+ licenses:
37
+ - MIT
38
+ metadata:
39
+ homepage_uri: https://github.com/bcdavasconcelos/inline_fn
40
+ source_code_uri: https://github.com/bcdavasconcelos/inline_fn.git
41
+ changelog_uri: https://github.com/bcdavasconcelos/inline_fn/blob/master/CHANGELOG.md
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 2.4.0
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubygems_version: 3.2.22
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: Change markdown footnotes format from `[^1]/[^1]:Note` to inline Pandoc or
61
+ MMD style `^[Note]/[^Note]`.
62
+ test_files: []