Module: Tokenize

Included in:
DocbookRenderer, HtmlRenderer, OdtRenderer, SpecRenderer
Defined in:
lib/notroff/tokenize.rb

Instance Method Summary collapse

Instance Method Details



40
41
42
# File 'lib/notroff/tokenize.rb', line 40

def parse_link(link_token)
  link_token.split('->').map {|s| s.strip}
end

#remove_escapes(text) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/notroff/tokenize.rb', line 50

def remove_escapes( text )
  text = text.clone

  results = ''

  until text.empty?
    match = /\\(.)/.match( text )
    if match.nil?
      results << text
      text = ''
    else
      unless match.pre_match.empty?
        results << match.pre_match
      end
      results << match[1]
      text = match.post_match
    end
  end
  results
end

#token_text(token) ⇒ Object



44
45
46
47
48
# File 'lib/notroff/tokenize.rb', line 44

def token_text( token )
  result = token.sub( /^../, '' ).sub( /..$/, '')
  #print "token text for #{token} [[#{result}]]"
  result
end

#token_type(token) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/notroff/tokenize.rb', line 25

def token_type( token )
  case token
  when /^\~/
    :italic
  when /^\@/
    :code
  when /^\{/
    :footnote
  when /^!/
    :bold
  when /^\^/
    :link
  end
end

#tokenize_body_text(text) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/notroff/tokenize.rb', line 4

def tokenize_body_text( text )
  text = text.dup
  re = /\~\~.*?\~\~|\@\@.*?\@\@+|\{\{.*?\}\}|!!.*?!!|\^\^.*?\^\^/
  results = []
  until text.empty?
    match = re.match( text )
    if match.nil?
      results << Text.new(text, :type=>:normal)
      text = ''
    else
      unless match.pre_match.empty?
        results << Text.new(match.pre_match, :type=>:normal)
      end
      token =  match.to_s
      results << Text.new(token_text(token), :type=>token_type(token))
      text = match.post_match
    end
  end
  results
end