commit 8e240a9612dbae8860954bd4bb39aa65f7c8bd14
parent 73c1187069565f10ca6ee1436ce225f4c983fa4b
Author: David Eisinger <[email protected]>
Date: Wed, 15 Nov 2023 21:26:57 -0500
remove old renumber script
Diffstat:
| D | bin/renumber | | | 52 | ---------------------------------------------------- |
1 file changed, 0 insertions(+), 52 deletions(-)
diff --git a/bin/renumber b/bin/renumber
@@ -1,52 +0,0 @@
-#!/usr/bin/env ruby
-
-fix = ARGV.shift if ARGV.first == "--fix"
-files = Array(ARGV.shift || Dir.glob("./**/*.md"))
-
-files.each do |file|
- content = File.read(file)
-
- # First, scan for all references ([#]: at beginning of line)
- # and look for duplicates
- refs = content.scan(/^\[\d+\]:/)
- dups = refs.combination(2).filter_map { |i, j| i if i == j }
-
- # If duplicate refs detected, this won't work, so bail out
- if dups.any?
- warn "Duplicate refs detected in #{file} (#{dups * ", "})"
- exit 1
- end
-
- idx = 0
- code_block = false
- cache = {}
-
- # Find all numbered links (in text + references) + code delimeters
- # (for fenced code blocks, "`" suffices because "```" is an odd number)
- updated = content.gsub(/\[\d+\]|`/) do |token|
- case token
- when "`"
- # We don't want to do substitution inside code blocks
- # (where `[#]` sometimes occurs) but we do want to toggle
- # whether or not we're in a code block
- code_block = !code_block
- token
- else
- # If we're in a code block, just return the token
- # Otherwise, check if the reference has already been assigned
- # - If so, return the cached value
- # - If not, bump the index, cache the value, and return it
- code_block ? token : cache[token] ||= "[#{idx += 1}]"
- end
- end
-
- if content != updated
- warn "Links in #{file} are not in order"
-
- if fix
- File.write(file, updated)
- else
- exit 1
- end
- end
-end