Class: Markdown::Read

Inherits:
Object
  • Object
show all
Defined in:
lib/tool-markdown/markdown/read.rb

Class Method Summary collapse

Class Method Details



30
31
32
33
34
# File 'lib/tool-markdown/markdown/read.rb', line 30

def self.extract_link_data_from_line(line)
  result = /[\*A-Za-záéíóú0-9%¿?=.:!\|\s\-\/]*\[([A-Za-záéíóú0-9%¿?=.:!\|\s\-\/]*)\]\(([A-Za-z0-9%¿?=.:\s\-\/]*)\)\s*/.match(line)
  # Debug.match_data(result)
  { text: result.to_a[1], url: result.to_a[2]}
end


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/tool-markdown/markdown/read.rb', line 10

def self.get_lines_with_links_into(filename)
  selected = []
  all = File.read(filename).split("\n")
  all.each_with_index do |line, index|
    if line.include? ']('
      linkdata = extract_link_data_from_line(line)
      url = linkdata[:url]
      # require 'pry-byebug'; binding.pry
      unless url.nil? or url.start_with?('http')
        selected << { filename: filename,
                      lineindex: index,
                      line: line,
                      linktext: linkdata[:text],
                      linkurl: linkdata[:url]}
      end
    end
  end
  selected
end

.locate_md_filenames_from(dirname) ⇒ Object



6
7
8
# File 'lib/tool-markdown/markdown/read.rb', line 6

def self.locate_md_filenames_from(dirname)
  Dir.glob(File.join(dirname,'**','*.md'))
end