Class: W3MExtractLinks
- Inherits:
-
AbstractIndex
- Object
- AbstractIndex
- W3MExtractLinks
- Includes:
- StripTags
- Defined in:
- lib/langhelp/langhelp-base.rb
Overview
Extract links from an HTML file, and create lh-w3m hyperlinks.
Defined Under Namespace
Classes: Link
Constant Summary
Constants included from StripTags
StripTags::ALT, StripTags::NQ, StripTags::Q
Constants inherited from AbstractIndex
Constants included from LocalVariables
LocalVariables::ANCHOR_BEGIN, LocalVariables::ANCHOR_END
Constants included from KanjiConverter
Instance Attribute Summary
Attributes inherited from AbstractIndex
Instance Method Summary collapse
Methods included from StripTags
Methods inherited from AbstractIndex
Methods included from LocalVariables
Methods included from FilenameString
#abbreviate_filename, #abbreviate_filename!, #normalize_filename!
Methods included from KanjiConverter
Methods included from MkArray
Methods included from EmacsLispString
Constructor Details
This class inherits a constructor from AbstractIndex
Instance Method Details
#init(x = {}) ⇒ Object
230 231 232 233 234 235 236 |
# File 'lib/langhelp/langhelp-base.rb', line 230 def init(x={}) @html = arg1 normalize_filename! @html @base = URI.parse("file://#{x[:base] || @html}") @exclude_label = mkarray(x[:exclude_label]) @exclude_url = mkarray(x[:exclude_url]) end |
#links ⇒ Object
242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/langhelp/langhelp-base.rb', line 242 def links src = kconv{ File.read @html } src.scan(%r!<a .*?href=#{Q}(#{NQ})#{Q}.*?>(.+?)</a>!imo).map {|href,label| uri = @base.merge href url = uri.to_s path = uri.path html2txt! label next if @exclude_label.any?{|exclude| exclude === label} next if @exclude_url.any?{|exclude| exclude === href} abbreviate_filename! path url = path if uri.scheme == 'file' Link.new(url,label) }.compact end |