Class: Gfm2Confluence::Converter

Inherits:
Redcarpet::Render::Base
  • Object
show all
Defined in:
lib/gfm2confluence/converter.rb

Overview

TODO: parse <pre> tags for code tags TODO: parse <p> tags to paragraphs TODO: parse <iframe> tags

Instance Method Summary collapse

Instance Method Details



47
48
49
# File 'lib/gfm2confluence/converter.rb', line 47

def autolink(link, link_type)
	"[#{link}]"
end

#block_code(code, language) ⇒ Object



10
11
12
# File 'lib/gfm2confluence/converter.rb', line 10

def block_code(code, language)
	"{code}\n#{code}{code}\n\n"
end

#block_html(raw_html) ⇒ Object



18
19
20
21
# File 'lib/gfm2confluence/converter.rb', line 18

def block_html(raw_html)
	#TODO: try to parse the html body and replce tags where possible
	raw_html
end

#block_quote(quote) ⇒ Object



14
15
16
# File 'lib/gfm2confluence/converter.rb', line 14

def block_quote(quote)
	"{quote}\n#{quote}{quote}\n"
end

#codespan(code) ⇒ Object



51
52
53
# File 'lib/gfm2confluence/converter.rb', line 51

def codespan(code)
	"{code}#{code}{code}"
end

#double_emphasis(text) ⇒ Object



55
56
57
# File 'lib/gfm2confluence/converter.rb', line 55

def double_emphasis(text)
	"*#{text}*"
end

#emphasis(text) ⇒ Object



59
60
61
# File 'lib/gfm2confluence/converter.rb', line 59

def emphasis(text)
	"_#{text}_"
end

#entity(text) ⇒ Object



92
93
94
# File 'lib/gfm2confluence/converter.rb', line 92

def entity(text)
	"#{text}"
end

#escape(text) ⇒ Object



100
101
102
103
# File 'lib/gfm2confluence/converter.rb', line 100

def escape(text)
	#TODO: Check if anything else needs to be escaped
	text.gsub(/\{|\}/, '\\\\\0') #This replaces { with \{
end

#header(text, header_level) ⇒ Object



23
24
25
# File 'lib/gfm2confluence/converter.rb', line 23

def header(text, header_level)
	"h#{header_level}. #{text}\n"
end

#hruleObject



27
28
29
# File 'lib/gfm2confluence/converter.rb', line 27

def hrule()
	"----\n"
end

#image(link, title, alt_text) ⇒ Object



63
64
65
# File 'lib/gfm2confluence/converter.rb', line 63

def image(link, title, alt_text)
	alt_text.to_s.empty? ? "!#{link}!" : "!#{link}|alt=#{alt_text}!"
end

#linebreakObject



67
68
69
# File 'lib/gfm2confluence/converter.rb', line 67

def linebreak()
	"\n"
end


71
72
73
# File 'lib/gfm2confluence/converter.rb', line 71

def link(link, title, alt_text)
	alt_text.to_s.empty? ? "[#{link}]" : "[#{alt_text}|#{link}]"
end

#list(contents, list_type) ⇒ Object



31
32
33
# File 'lib/gfm2confluence/converter.rb', line 31

def list(contents, list_type)
	"#{contents}\n"
end

#list_item(text, list_type) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/gfm2confluence/converter.rb', line 35

def list_item(text, list_type)
	marker = '-'
	if list_type.to_s == "ordered"
		marker = '#'
	end
	"#{marker} #{text}"
end

#normal_text(text) ⇒ Object



96
97
98
# File 'lib/gfm2confluence/converter.rb', line 96

def normal_text(text)
	escape "#{text}"
end

#paragraph(text) ⇒ Object



43
44
45
# File 'lib/gfm2confluence/converter.rb', line 43

def paragraph(text)
	"#{text}\n\n"
end

#raw_html(raw_html) ⇒ Object



75
76
77
78
# File 'lib/gfm2confluence/converter.rb', line 75

def raw_html(raw_html)
	#TODO: parse the separate tags along with block_html and make replacements where applicable
	raw_html
end

#strikethrough(text) ⇒ Object



84
85
86
# File 'lib/gfm2confluence/converter.rb', line 84

def strikethrough(text)
	"-#{text}-"
end

#superscript(text) ⇒ Object



88
89
90
# File 'lib/gfm2confluence/converter.rb', line 88

def superscript(text)
	"^#{text}^"
end

#triple_emphasis(text) ⇒ Object



80
81
82
# File 'lib/gfm2confluence/converter.rb', line 80

def triple_emphasis(text)
	"*#{text}*"
end