-
-
Save neingeist/d22f157bc29a7bcc31020d1c1ffcc8be to your computer and use it in GitHub Desktop.
Revisions
-
lypanov created this gist
Jan 9, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ require "json" require "pp" state = false references_raw, content = *(`elinks -dump /tmp/dump4`.lines.partition { |line| state = true if line == "References\n" ; state } ) content_began, delayed_link = false, nil references = references_raw.inject({}) do |hsh, line| if line =~ /Visible links$/ content_began = true next hsh end if content_began && !delayed_link.nil? line =~ /\s*(.*)$/ hsh[delayed_link] = $1 delayed_link = nil elsif content_began line =~ /\s*(\d+?)\. (([a-z]+:.*)|(.*))$/ if $3 hsh[$1.to_i] = $2 else delayed_link = $1.to_i end end hsh end content.each do |line| loop do if line =~ /^(.*?)\[(\d+)\](.*)$/ before, ref, after = $1, $2, $3 print before url = references[ref.to_i] spacer = url.nil? ? " " : "@" text = spacer * (ref.length + 2) print "\033[31;1m\e]8;;#{url}\e\\#{text}\e]8;;\e\\\033[0m" line = after else print line.chomp break end end puts end