1#!/usr/bin/env ruby 2# 3# Copyright (c) 2019 Baldur Karlsson 4# 5# SPDX-License-Identifier: Apache-2.0 6 7require 'pp' 8require 'json' 9 10data = [] 11 12ARGV.each do |file| 13 14 curdata = nil 15 extappendix = false 16 curext = "" 17 18 File.readlines(file).each do |line| 19 20 text = line.gsub(/<\/?[^>]*>/, "") 21 22 # Special case - set up high quality results for given structs 23 if line =~ /div id="([vV][kK][^"]*)"/ then 24 id = $1 25 26 data << { :id => File.basename(file) + "#" + id, :title => id, :body => id } 27 end 28 29 if line =~ /h[0-9]\s*id="([^"]*)"/ then 30 31 id = $1 32 33 if curdata != nil then 34 data << curdata 35 end 36 37 if text =~ /Appendix.*Extensions/ then 38 extappendix = true 39 end 40 41 if extappendix and text =~ /^VK_.*/ then 42 curext = text 43 elsif curext != "" then 44 text = "#{curext.strip} - #{text}" 45 end 46 47 curdata = { :id => File.basename(file) + "#" + id, :title => text, :body => "" } 48 elsif curdata != nil then 49 curdata[:body] += " " + text 50 end 51 52 end 53 54 if curdata != nil then 55 data << curdata 56 end 57 58end 59 60puts JSON.generate(data) 61