From b914b871b104579c19caf6dd78f03e7818e4bb02 Mon Sep 17 00:00:00 2001 From: pjht Date: Sat, 14 Apr 2018 11:36:04 -0500 Subject: [PATCH] Initial Commit --- Gemfile | 2 ++ Gemfile.lock | 15 ++++++++ browse.rb | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 browse.rb diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..e0814bc --- /dev/null +++ b/Gemfile @@ -0,0 +1,2 @@ +source "https://rubygems.org" +gem "nokogiri" diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..199c048 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,15 @@ +GEM + remote: https://rubygems.org/ + specs: + mini_portile2 (2.3.0) + nokogiri (1.8.2) + mini_portile2 (~> 2.3.0) + +PLATFORMS + ruby + +DEPENDENCIES + nokogiri + +BUNDLED WITH + 1.15.4 diff --git a/browse.rb b/browse.rb new file mode 100644 index 0000000..a298096 --- /dev/null +++ b/browse.rb @@ -0,0 +1,99 @@ +require "nokogiri" +$mode="" +pages={} + +pages["/"]=<<-ENDPAGE + +

Welcome to my website!

+

Bold

+

Italics

+A page +Another page + +ENDPAGE + +pages["/page"]=<<-ENDPAGE + +

A page

+

Bold and Italic

+Home +Another page + +ENDPAGE + +pages["/anotherpage"]=<<-ENDPAGE + +

Here is more info

+A page +Home + +ENDPAGE +currentpage="/" + +def showtext(text,nline=true) + case $mode + when "b" + puts "\e[1m#{text}\e[0m" if nline + print "\e[1m#{text}\e[0m" if !nline + when "i" + puts "\e[3m#{text}\e[0m" if nline + print "\e[3m#{text}\e[0m" if !nline + when "ib" + puts "\e[1m\e[3m#{text}\e[0m" if nline + print "\e[1m\e[3m#{text}\e[0m" if !nline + when "" + puts text if nline + print text if !nline + end +end +def dispelem(elem) + if elem.class==Nokogiri::XML::Text + showtext(elem) + return + end + case elem.name + when "p" + elem.children.each do |elem| + dispelem(elem) + end + when "a" + $links.push(elem["href"]) + showtext(elem.children[0],false) + puts "[#{$linkid}]" + $linkid+=1 + when "b" + if $mode=="i" + $mode="ib" + else + $mode="b" + end + elem.children.each do |elem| + dispelem(elem) + end + $mode="" + when "i" + if $mode=="b" + $mode="ib" + else + $mode="i" + end + elem.children.each do |elem| + dispelem(elem) + end + $mode="" + end +end +while true + $links=[] + $linkid=1 + system("clear") + doctext=pages[currentpage].gsub("\n","") + doc=Nokogiri::Slop(doctext) + doc.html.body.children.each do |elem| + dispelem(elem) + end + print "Link ID/exit:" + id=gets.chomp!.downcase + break if id=="exit" + currentpage=$links[id.to_i-1] +end