yard-fence 0.3.0 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5baded4374cd088861f834e9979c206e08dac16af4c52fdbf3d28ea1e7ce8c58
4
- data.tar.gz: bf14fe77229b435e7361883d6dd6128bcff08f58ed8a7742fb88eb9223148a2d
3
+ metadata.gz: '0909353a8e193134a57cf571979c154be5c08adb0ce6c53855282996ea8d96de'
4
+ data.tar.gz: 69400f31490fb97d56aa19a79519c7f15c160b689b48ca6d0228df640410655b
5
5
  SHA512:
6
- metadata.gz: 0c10875a2282e3e6613bdc39bcf37b5aa3507489a5f94406ded819765e3a9feb3ab1581c8a9a3e9c4b11e22564bafb0c7f137db6f7f038248e4d59827080cbdf
7
- data.tar.gz: fae576e37e8f9c840bb5e6c772cfdfa7e8eb5e3a065ae9c3deda8d23860595a6827f52f529ae7d12944be2321d4fe0a74753e752505b8b2574a4df49704f1803
6
+ metadata.gz: e7e3af604e115d051dac3bb1763df43aeacdd693c947504ace79f8864f12e343ea54e065be3b3b13e55b4b29bc8d193fcb939c44fbcad3a6f0307df5c55dd06e
7
+ data.tar.gz: 28c385b149403931cf456ad76223a33b12df2272fa47bcde51cfff31344e43b699227a7a10902f27e910beced70db24fd674b0831e2652ef7dc487669139ca78
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -30,6 +30,38 @@ Please file a bug if you notice a violation of semantic versioning.
30
30
 
31
31
  ### Security
32
32
 
33
+ ## [0.5.0] - 2025-11-07
34
+
35
+ - TAG: [v0.5.0][0.5.0t]
36
+ - COVERAGE: 100.00% -- 98/98 lines in 4 files
37
+ - BRANCH COVERAGE: 100.00% -- 22/22 branches in 4 files
38
+ - 34.62% documented
39
+
40
+ ### Added
41
+
42
+ - Support multi-line braces
43
+ - 100% lines / 100% branches test coverage
44
+
45
+ ## [0.4.0] - 2025-11-07
46
+
47
+ - TAG: [v0.4.0][0.4.0t]
48
+ - COVERAGE: 96.43% -- 81/84 lines in 4 files
49
+ - BRANCH COVERAGE: 93.75% -- 15/16 branches in 4 files
50
+ - 29.17% documented
51
+
52
+ ### Added
53
+
54
+ - Docs: Document importance of `require: false` in `Gemfile` for this gem
55
+
56
+ ### Changed
57
+
58
+ - Docs: Improved markdown syntax in README.md for Kramdown => HTML
59
+
60
+ ### Fixed
61
+
62
+ - Use namespaced directory in `tmp/` (`tmp/yard-fence`)
63
+ - avoids polluting, and pollution from, other garbage in `tmp/`
64
+
33
65
  ## [0.3.0] - 2025-11-07
34
66
 
35
67
  - TAG: [v0.3.0][0.3.0t]
@@ -62,7 +94,11 @@ Please file a bug if you notice a violation of semantic versioning.
62
94
 
63
95
  - Initial release
64
96
 
65
- [Unreleased]: https://github.com/galtzo-floss/yard-fence/compare/v0.3.0...HEAD
97
+ [Unreleased]: https://github.com/galtzo-floss/yard-fence/compare/v0.5.0...HEAD
98
+ [0.5.0]: https://github.com/galtzo-floss/yard-fence/compare/v0.4.0...v0.5.0
99
+ [0.5.0t]: https://github.com/galtzo-floss/yard-fence/releases/tag/v0.5.0
100
+ [0.4.0]: https://github.com/galtzo-floss/yard-fence/compare/v0.3.0...v0.4.0
101
+ [0.4.0t]: https://github.com/galtzo-floss/yard-fence/releases/tag/v0.4.0
66
102
  [0.3.0]: https://github.com/galtzo-floss/yard-fence/compare/v0.2.0...v0.3.0
67
103
  [0.3.0t]: https://github.com/galtzo-floss/yard-fence/releases/tag/v0.3.0
68
104
  [0.2.0]: https://github.com/galtzo-floss/yard-fence/compare/v0.1.0...v0.2.0
data/README.md CHANGED
@@ -51,7 +51,8 @@
51
51
  A brace converter for the markdown fences in your YARD docs to prevent the `InvalidLink` warning.
52
52
 
53
53
  Just the important bits:
54
- - Preprocesses top-level README and other `.md`/`.txt` files into `tmp/` replacing ASCII braces inside fenced code blocks, inline code spans, and simple placeholders like `{issuer}` or `{{TOKEN}}` with visually identical fullwidth braces.
54
+
55
+ - Preprocesses top-level README and other `.md`/`.txt` files into `tmp/yard-fence/` replacing ASCII braces inside fenced code blocks, inline code spans, and simple placeholders like `{issuer}` or `{{TOKEN}}` with visually identical fullwidth braces.
55
56
  - This prevents YARD from emitting `InvalidLink` warnings.
56
57
  - Prioritizes Kramdown's GFM parser so tables and fenced code blocks render correctly.
57
58
  - After YARD finishes generating HTML, restores fullwidth braces back to normal ASCII braces so code examples are copy‑pastable.
@@ -61,13 +62,13 @@ Create a `.yardopts` file like this:
61
62
  ```text
62
63
  --plugin fence
63
64
  -e yard/fence/hoist.rb
64
- --readme tmp/README.md
65
+ --readme tmp/yard-fence/README.md
65
66
  --markup markdown
66
67
  --output docs
67
68
  'lib/**/*.rb'
68
69
  -
69
- 'tmp/*.md'
70
- 'tmp/*.txt'
70
+ 'tmp/yard-fence/*.md'
71
+ 'tmp/yard-fence/*.txt'
71
72
  ```
72
73
 
73
74
  See the configuration and usage sections for more details.
@@ -97,7 +98,7 @@ Compatible with MRI Ruby 3.2.0+, and concordant releases of JRuby, and TruffleRu
97
98
 
98
99
  ### Federated DVCS
99
100
 
100
- <details>
101
+ <details markdown="1">
101
102
  <summary>Find this repo on federated forges (Coming soon!)</summary>
102
103
 
103
104
  | Federated [DVCS][💎d-in-dvcs] Repository | Status | Issues | PRs | Wiki | CI | Discussions |
@@ -115,7 +116,7 @@ Compatible with MRI Ruby 3.2.0+, and concordant releases of JRuby, and TruffleRu
115
116
 
116
117
  Available as part of the Tidelift Subscription.
117
118
 
118
- <details>
119
+ <details markdown="1">
119
120
  <summary>Need enterprise-level guarantees?</summary>
120
121
 
121
122
  The maintainers of this and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source packages you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use.
@@ -139,7 +140,18 @@ Alternatively:
139
140
  Install the gem and add to the application's Gemfile by executing:
140
141
 
141
142
  ```console
142
- bundle add yard-fence
143
+ bundle add yard-fence --require false
144
+ ```
145
+
146
+ NOTE: if you add it directly to your Gemfile,
147
+ be sure to include `require: false` so bundler doesn't load it when bootstrapping.
148
+ This is important because this gem has a global `at_exit` callback that only makes sense to run after yard runs.
149
+ As such this gem should only be loaded by YARD itself via the `--plugin fence` option.
150
+
151
+ Example:
152
+
153
+ ```ruby
154
+ gem "yard-fence", "~> 0.3", require: false
143
155
  ```
144
156
 
145
157
  If bundler is not being used to manage dependencies, install the gem by executing:
@@ -150,7 +162,7 @@ gem install yard-fence
150
162
 
151
163
  ### 🔒 Secure Installation
152
164
 
153
- <details>
165
+ <details markdown="1">
154
166
  <summary>For Medium or High Security Installations</summary>
155
167
 
156
168
  This gem is cryptographically signed, and has verifiable [SHA-256 and SHA-512][💎SHA_checksums] checksums by
@@ -185,24 +197,25 @@ NOTE: Be prepared to track down certs for signed gems and add them the same way
185
197
 
186
198
  ## ⚙️ Configuration
187
199
 
188
- Yard::Fence writes sanitized copies of top‑level Markdown/TXT into tmp/ at load time. To avoid YARD parsing the unsanitized originals, point YARD at the tmp/ copies.
200
+ NOTE: `Yard::Fence` writes sanitized copies of top‑level Markdown/TXT into `tmp/yard-fence/` at load time. To avoid YARD parsing the unsanitized originals, point YARD at the `tmp/yard-fence/` copies.
189
201
 
190
202
  Recommended .yardopts (noise‑free):
191
203
 
192
204
  ```text
193
205
  --plugin fence
194
206
  -e yard/fence/hoist.rb
195
- --readme tmp/README.md
207
+ --readme tmp/yard-fence/README.md
196
208
  --markup markdown
197
209
  --output docs
198
210
  'lib/**/*.rb'
199
211
  -
200
- 'tmp/*.md'
201
- 'tmp/*.txt'
212
+ 'tmp/yard-fence/*.md'
213
+ 'tmp/yard-fence/*.txt'
202
214
  ```
203
215
 
204
- Why tmp/?
205
- - The plugin converts ASCII `{ }` to fullwidth `{ }` only in `tmp/` so YARD won’t treat brace content as reference tags and emit InvalidLink warnings. After docs are generated, the HTML is restored back to normal ASCII braces for easy copy/paste.
216
+ Why tmp/yard-fence/?
217
+
218
+ - The plugin converts ASCII `{ }` to fullwidth `{ }` only in `tmp/yard-fence/` so YARD won’t treat brace content as reference tags and emit `InvalidLink` warnings. After docs are generated, the HTML is restored back to normal ASCII braces for easy copy/paste.
206
219
 
207
220
  ## 🔧 Basic Usage
208
221
 
@@ -212,8 +225,8 @@ CLI example that would be similar to what is accomplished by the `.yardopts` fro
212
225
  yard doc \
213
226
  --plugin fence \
214
227
  -e yard/fence/hoist.rb \
215
- --readme tmp/README.md \
216
- lib/**/*.rb - tmp/*.md tmp/*.txt
228
+ --readme tmp/yard-fence/README.md \
229
+ lib/**/*.rb - tmp/yard-fence/*.md tmp/yard-fence/*.txt
217
230
  ```
218
231
 
219
232
  ## 🦷 FLOSS Funding
@@ -344,10 +357,10 @@ the [Pessimistic Version Constraint][📌pvc] with two digits of precision.
344
357
  For example:
345
358
 
346
359
  ```ruby
347
- spec.add_dependency("yard-fence", "~> 1.0")
360
+ spec.add_dependency("yard-fence", "~> 0.4")
348
361
  ```
349
362
 
350
- <details>
363
+ <details markdown="1">
351
364
  <summary>📌 Is "Platform Support" part of the public API? More details inside.</summary>
352
365
 
353
366
  SemVer should, IMO, but doesn't explicitly, say that dropping support for specific Platforms
@@ -573,7 +586,7 @@ Thanks for RTFM. ☺️
573
586
  [📌gitmoji]: https://gitmoji.dev
574
587
  [📌gitmoji-img]: https://img.shields.io/badge/gitmoji_commits-%20%F0%9F%98%9C%20%F0%9F%98%8D-34495e.svg?style=flat-square
575
588
  [🧮kloc]: https://www.youtube.com/watch?v=dQw4w9WgXcQ
576
- [🧮kloc-img]: https://img.shields.io/badge/KLOC-0.084-FFDD67.svg?style=for-the-badge&logo=YouTube&logoColor=blue
589
+ [🧮kloc-img]: https://img.shields.io/badge/KLOC-0.098-FFDD67.svg?style=for-the-badge&logo=YouTube&logoColor=blue
577
590
  [🔐security]: SECURITY.md
578
591
  [🔐security-img]: https://img.shields.io/badge/security-policy-259D6C.svg?style=flat
579
592
  [📄copyright-notice-explainer]: https://opensource.stackexchange.com/questions/5778/why-do-licenses-such-as-the-mit-license-specify-a-single-year
@@ -3,7 +3,7 @@
3
3
  module Yard
4
4
  module Fence
5
5
  module Version
6
- VERSION = "0.3.0"
6
+ VERSION = "0.5.0"
7
7
  end
8
8
  VERSION = Version::VERSION
9
9
  end
data/lib/yard/fence.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Prepare sanitized copies of Markdown/TXT files in tmp/ for YARD consumption.
3
+ # Prepare sanitized copies of Markdown/TXT files in tmp/yard-fence/ for YARD consumption.
4
4
  #
5
5
  # Why this exists
6
6
  # - YARD treats any `{…}` sequence in extra files (like README.md) as a potential link
@@ -14,8 +14,8 @@
14
14
  # no backslash escapes sprinkled throughout examples).
15
15
  # - We need YARD to stop interpreting code-fenced braces as links.
16
16
  #
17
- # Strategy (tmp/ preprocessor)
18
- # - At doc build time, copy top-level *.md/*.txt into tmp/ and transform only the risky
17
+ # Strategy (tmp/yard-fence/ preprocessor)
18
+ # - At doc build time, copy top-level *.md/*.txt into tmp/yard-fence/ and transform only the risky
19
19
  # brace pairs in contexts YARD misinterprets:
20
20
  # * inside triple‑backtick fenced code blocks
21
21
  # * inside single‑backtick inline code spans
@@ -28,7 +28,7 @@
28
28
  #
29
29
  # Key lines to see:
30
30
  # - Transform to fullwidth: str.tr('{}', '{}')
31
- # This replaces ASCII { and } with their fullwidth Unicode counterparts in sanitized tmp files.
31
+ # This replaces ASCII { and } with their fullwidth Unicode counterparts in sanitized tmp/yard-fence files.
32
32
  # - Restore to ASCII (HTML): out = src.tr('{}', '{}')
33
33
  # This runs after docs are generated and rewrites the HTML contents back to normal { and }.
34
34
  #
@@ -61,12 +61,19 @@ module Yard
61
61
  module Fence
62
62
  ASCII_BRACES = "{}"
63
63
  FULLWIDTH_BRACES = "{}"
64
+ # IMPORTANT: YARD expects :const to be a String.
65
+ # YARD concatenates with a String prefix (e.g., "::" + const),
66
+ # so a Symbol here will break provider resolution. Some static analyzers
67
+ # suggest making this a Symbol to match types, but that is incorrect for YARD.
68
+ # Do NOT change this to a Symbol.
64
69
  KRAMDOWN_PROVIDER = {lib: :kramdown, const: "KramdownGfmDocument"}
65
70
  GLOB_PATTERN = "*.{md,MD,txt,TXT}"
66
71
  TRIPLE_TICK_FENCE = /^\s*```/
67
72
  INLINE_TICK_FENCE = /`([^`]+)`/
68
73
  DOUBLE_BRACE_PLACEHOLDER_REGEX = /{{([^{}]+)}}/
69
74
  SINGLE_BRACE_PLACEHOLDER_REGEX = /{([A-Za-z0-9_:\-]+)}/
75
+ # Lines that are part of a classic indented code block (CommonMark: 4 spaces)
76
+ INDENTED_CODE_LINE = /^ {4,}\S/
70
77
 
71
78
  class Error < StandardError; end
72
79
  # :nocov:
@@ -84,7 +91,11 @@ module Yard
84
91
 
85
92
  # Escape braces inside inline `code` spans only.
86
93
  def sanitize_inline_code(line)
87
- line.gsub(INLINE_TICK_FENCE) { |_| "`#{fullwidth_braces($1)}`" }
94
+ # Use Regexp.last_match to safely access capture; to_s guards against nil
95
+ line.gsub(INLINE_TICK_FENCE) do |_|
96
+ inner = Regexp.last_match(1).to_s
97
+ "`#{fullwidth_braces(inner)}`"
98
+ end
88
99
  end
89
100
 
90
101
  # Walk the text, toggling a simple in_fence state on ``` lines.
@@ -92,13 +103,31 @@ module Yard
92
103
  # and disarm simple prose placeholders like {issuer} or {{something}}.
93
104
  def sanitize_fenced_blocks(text)
94
105
  in_fence = false
106
+ in_indented_block = false
95
107
 
96
108
  text.each_line.map do |line|
97
109
  if line.match?(TRIPLE_TICK_FENCE)
110
+ # Toggle fenced block state; leaving indented block if switching into explicit fence
98
111
  in_fence = !in_fence
112
+ in_indented_block = false if in_fence
99
113
  line
100
114
  elsif in_fence
101
115
  fullwidth_braces(line)
116
+ elsif in_indented_block
117
+ # Continue indented block until a blank line or non-indented line breaks it
118
+ if line.strip.empty? || !line.match?(INDENTED_CODE_LINE)
119
+ in_indented_block = false
120
+ # Process this line as normal prose outside block
121
+ ln = sanitize_inline_code(line)
122
+ ln = ln.gsub(DOUBLE_BRACE_PLACEHOLDER_REGEX) { |m| fullwidth_braces(m) }
123
+ ln.gsub(SINGLE_BRACE_PLACEHOLDER_REGEX) { |m| fullwidth_braces(m) }
124
+ else
125
+ fullwidth_braces(line)
126
+ end
127
+ elsif line.match?(INDENTED_CODE_LINE)
128
+ # Enter indented code block on first qualifying line
129
+ in_indented_block = true
130
+ fullwidth_braces(line)
102
131
  else
103
132
  ln = sanitize_inline_code(line)
104
133
  # IMPORTANT: handle double-brace placeholders first so we don't partially
@@ -114,10 +143,10 @@ module Yard
114
143
  sanitize_fenced_blocks(text)
115
144
  end
116
145
 
117
- # Copy top-level *.md/*.txt into tmp/ with the above sanitization applied.
146
+ # Copy top-level *.md/*.txt into tmp/yard-fence/ with the above sanitization applied.
118
147
  def prepare_tmp_files
119
148
  root = Dir.pwd
120
- outdir = File.join(root, "tmp")
149
+ outdir = File.join(root, "tmp", "yard-fence")
121
150
  FileUtils.mkdir_p(outdir)
122
151
 
123
152
  candidates = Dir.glob(File.join(root, GLOB_PATTERN))
@@ -161,6 +190,10 @@ module Yard
161
190
  end
162
191
  # :nocov:
163
192
  providers = ::YARD::Templates::Helpers::MarkupHelper::MARKUP_PROVIDERS[:markdown]
193
+ # NOTE: Intentionally using String for :const in KRAMDOWN_PROVIDER.
194
+ # YARD performs string concatenation with this value (e.g., "::" + const).
195
+ # Changing it to a Symbol to satisfy static type hints breaks runtime behavior.
196
+ # Suppress type fuzz complaints: expected Hash{Symbol->Symbol}, actual includes String by design.
164
197
  providers.unshift(KRAMDOWN_PROVIDER)
165
198
  providers.uniq! { |p| [p[:lib].to_s, p[:const].to_s] }
166
199
  true
@@ -168,14 +201,16 @@ module Yard
168
201
  warn("Yard::Fence.use_kramdown_gfm!: failed to load YARD helper: #{e.class}: #{e.message}")
169
202
  false
170
203
  end
171
- end
172
204
 
173
- # Execute at load-time so files exist before YARD scans tmp/*.md
174
- begin
175
- Yard::Fence.prepare_tmp_files
176
- rescue => e
177
- warn("Yard::Fence: failed to prepare tmp files: #{e.class}: #{e.message}")
205
+ def at_load_hook
206
+ Yard::Fence.prepare_tmp_files
207
+ rescue => e
208
+ warn("Yard::Fence: failed to prepare tmp/yard-fence files: #{e.class}: #{e.message}")
209
+ end
178
210
  end
211
+
212
+ # Execute at load-time so files exist before YARD scans tmp/yard-fence/*.md
213
+ Yard::Fence.at_load_hook
179
214
  end
180
215
 
181
216
  # Extend the Version with VersionGem::Basic to provide semantic version helpers.
@@ -183,6 +218,8 @@ Yard::Fence::Version.class_eval do
183
218
  extend VersionGem::Basic
184
219
  end
185
220
 
221
+ # :nocov:
222
+ # Not checking coverage of the at_exit hook, because it would require a forked process.
186
223
  unless ENV["YARD_FENCE_SKIP_AT_EXIT"] == "1"
187
224
  # After YARD completes, restore ASCII braces in generated HTML docs.
188
225
  # This guarantees the published docs (docs/*.html) show and copy normal { }.
@@ -190,3 +227,4 @@ unless ENV["YARD_FENCE_SKIP_AT_EXIT"] == "1"
190
227
  Yard::Fence.postprocess_html_docs
191
228
  end
192
229
  end
230
+ # :nocov:
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yard-fence
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter H. Boling
@@ -316,10 +316,10 @@ licenses:
316
316
  - MIT
317
317
  metadata:
318
318
  homepage_uri: https://yard-fence.galtzo.com/
319
- source_code_uri: https://github.com/galtzo-floss/yard-fence/tree/v0.3.0
320
- changelog_uri: https://github.com/galtzo-floss/yard-fence/blob/v0.3.0/CHANGELOG.md
319
+ source_code_uri: https://github.com/galtzo-floss/yard-fence/tree/v0.5.0
320
+ changelog_uri: https://github.com/galtzo-floss/yard-fence/blob/v0.5.0/CHANGELOG.md
321
321
  bug_tracker_uri: https://github.com/galtzo-floss/yard-fence/issues
322
- documentation_uri: https://www.rubydoc.info/gems/yard-fence/0.3.0
322
+ documentation_uri: https://www.rubydoc.info/gems/yard-fence/0.5.0
323
323
  funding_uri: https://github.com/sponsors/pboling
324
324
  wiki_uri: https://github.com/galtzo-floss/yard-fence/wiki
325
325
  news_uri: https://www.railsbling.com/tags/yard-fence
metadata.gz.sig CHANGED
Binary file