1
0
mirror of https://github.com/mgcaret/of816.git synced 2024-12-28 10:30:21 +00:00
of816/utils/index2md.rb

65 lines
1.7 KiB
Ruby
Raw Normal View History

2020-01-14 00:58:39 +00:00
#!/usr/bin/ruby
require 'yaml'
require 'date'
def usage
puts <<EOF
Usage: #{$0} index-file|- [dictionary-title]
reads index file (- for stdin) and produces markdown-
formatted output documenting non-headerless words for the
indexed dictionary.
2020-01-14 00:58:39 +00:00
if dictionary-title is specified, it is used as the top
level heading instead of the file name.
EOF
exit 1
end
index_file = ARGV.shift || usage
if index_file == '-'
index = YAML.load(STDIN.read)
else
File.readable?(index_file) || abort("#{index_file} not found!")
index = YAML.load(File.read(index_file))
end
dname = ARGV.shift || File.basename(index_file, File.extname(index_file))
puts "# #{dname}"
puts
puts "Updated: #{Time.new}"
puts
index.keys.sort.each do |word|
word_info = index[word]
next if word_info['headerless']
cword = word.gsub(/^(#+)$/) { "\\#{$1}" } # let '#' display properly
cword.gsub!(/^([<>])/) { "\\#{$1}" }
puts "## #{cword}"
2020-01-14 00:58:39 +00:00
puts
if word_info['flags']
puts "- Immediate." if word_info['flags'].include?('F_IMMED')
if word_info['flags'].include?('F_CONLY')
if word_info['flags'].include?('F_TEMPD')
puts "- In interpretation state, starts temporary definition."
else
puts "- Compile-only."
end
end
puts
end
2020-01-14 00:58:39 +00:00
if word_info['help']
word_info['help'].each_with_index do |line, i|
line.gsub!(/[(](.+?--.+?)[)]/, '_(\1)_') # emphasize stack effects
if line =~ /^\s*\S+:/
# space for separating interpretation/compilation/etc.
puts if i > 0
2020-01-14 00:58:39 +00:00
end
puts line
end
puts
end
end