class MarkdownToTeX::TextProcessor
Public Class Methods
bib_name_map(n)
click to toggle source
Citation Handling
# File lib/markdown_to_tex/text_processor.rb, line 33 def self.bib_name_map(n) @@cite_map.has_key?(n) ? @@cite_map[n] : n end
comment_line(s)
click to toggle source
# File lib/markdown_to_tex/text_processor.rb, line 124 def self.comment_line(s) px = (78 - 1 - s.length) px = 1 if px < 1 "%" * px + " " + s + "\n" end
label_name_map(n)
click to toggle source
# File lib/markdown_to_tex/text_processor.rb, line 45 def self.label_name_map(n) if @@tag_namespace == nil return bib_name_map(n) end if n =~ /(chap|part|sec|subsec|subsubsec|fig|table|eq):(.+)/ r = $1 + ":" + self.tag_name_map($2) else r = self.bib_name_map(n) end r end
label_split(s)
click to toggle source
# File lib/markdown_to_tex/text_processor.rb, line 80 def self.label_split(s) label = "" if s.sub!(/\s*\[([^\]]+)\]/, '') label = $1 end [s, label] end
level_tag(d)
click to toggle source
# File lib/markdown_to_tex/text_processor.rb, line 97 def self.level_tag(d) @@level_tag[d + @@level_shift] end
process_final(text, macros)
click to toggle source
Process on whole output text
# File lib/markdown_to_tex/text_processor.rb, line 118 def self.process_final(text, macros) # Macro expansions macros.each {|m, v| text.gsub!(m, v) } text end
process_header(text, level)
click to toggle source
Process a header
# File lib/markdown_to_tex/text_processor.rb, line 102 def self.process_header(text, level) name, label = self.label_split(text) name, name_short = self.short_desc(name) tag = self.level_tag(level) the_label = self.label_name_map(label) star = "" # star ? "*" : "" s = self.comment_line(tag.upcase + ": #{name}") s << "\\#{tag}#{star}#{name_short}{#{name}}" s << "\\label{#{the_label}}" unless label.empty? s << "\n" s end
process_paragraph(text)
click to toggle source
Process a paragraph
# File lib/markdown_to_tex/text_processor.rb, line 26 def self.process_paragraph(text) text.gsub!(/\(\((.*)\)\)/, '\\ITEM{\1}') # description format self.reference(text) end
ref_name_map(n)
click to toggle source
# File lib/markdown_to_tex/text_processor.rb, line 58 def self.ref_name_map(n) self.label_name_map(n) end
ref_name_map_cite(k)
click to toggle source
# File lib/markdown_to_tex/text_processor.rb, line 62 def self.ref_name_map_cite(k) cite = "CITE" text = k.split(/\s*,\s*/).each.map {|kk| self.ref_name_map(kk)}.join(",") if text =~ /"(.*)"/ r = "[#{$1}]" else r = "\\#{cite}{#{text}}" end r end
reference(text)
click to toggle source
# File lib/markdown_to_tex/text_processor.rb, line 73 def self.reference(text) text. gsub(/\[(this|prev|next):(chap|part|sec|subsec|subsubsec|fig|table)\]/) { "\\#{$1}#{$2}KEY{}" }. gsub(/\[((chap|part|sec|subsec|subsubsec|fig|table):[^\]]+)\]/) { "\\#{$2}REF{#{self.ref_name_map($1)}}" }. gsub(/\[([^\]]+)\]/) { self.ref_name_map_cite($1);} end
short_desc(s)
click to toggle source
# File lib/markdown_to_tex/text_processor.rb, line 88 def self.short_desc(s) # map short|long s_short = "" if s =~ /\s*([^\|]+)\s*\|\s*(.+)\s*/ s_short = "[#{$1}]" s = $2 end [s, s_short] end
tag_name_map(n)
click to toggle source
# File lib/markdown_to_tex/text_processor.rb, line 37 def self.tag_name_map(n) return "" if n == nil if @@tag_namespace == nil or n =~ /#{@@tag_namespace}:/ return n end @@tag_namespace + ":" + n end