markdown2confluence 0.0.1a

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ *.swp
data/.rvmrc ADDED
@@ -0,0 +1,3 @@
1
+ rvm use ruby-1.8.7
2
+ rvm gemset use markdown2confluence
3
+ alias markdown2confluence="bundle exec markdown2confluence"
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "markdown2confluence", :path => "."
data/README.markdown ADDED
@@ -0,0 +1,33 @@
1
+ This code is a quick hack for converting markdown to [Atlassian confluence](http://atlassian.com/confluence) markup language.
2
+ It's nowhere near doing a full conversion, but I will continue to improve where possible.
3
+
4
+ The gem is based on [Kramdown](https://github.com/gettalong/kramdown)
5
+
6
+ ### Installation:
7
+
8
+ #### Via gem
9
+
10
+ NOTE: *only a prelease version has been released*
11
+
12
+ $ gem install markdown2confluence --pre
13
+
14
+ #### From github:
15
+
16
+ $ gem install bundler
17
+ $ git clone git://github.com/jedi4ever/markdown2confluence.git
18
+ $ bundle install vendor
19
+
20
+ ### Usage:
21
+
22
+ If using Gem:
23
+
24
+ $ markdown2confluence <inputfile>
25
+
26
+ If using bundler:
27
+
28
+ $ bundle exec bin/markdown2confluence <inputfile>
29
+
30
+ ### Extending/Improving it:
31
+
32
+ there is really one class to edit - see lib/markdown2confluence/convertor/confluence.rb
33
+ Feel free to enhance or improve tag handling.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/setup'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'markdown2confluence'
4
+
5
+ filename=ARGV[0]
6
+ if ARGV.size < 1
7
+ puts "We need at least on file argument"
8
+ exit -1
9
+ end
10
+
11
+ begin
12
+ text=File.read(filename)
13
+ s=Kramdown::Document.new(text).to_confluence
14
+ puts s
15
+ rescue Exception => ex
16
+ warn "There was an error running the convertor: \n#{ex}"
17
+ end
@@ -0,0 +1,217 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ #--
4
+ # This file is part of based on kramdown.Confluence convertor
5
+ #
6
+ # kramdown is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+ #
20
+
21
+ require 'rexml/parsers/baseparser'
22
+
23
+ module Kramdown
24
+
25
+ module Converter
26
+
27
+ # Converts a Kramdown::Document to Confluence ML
28
+ #
29
+ # You can customize the Confluence converter by sub-classing it and overriding the +convert_NAME+
30
+ # methods. Each such method takes the following parameters:
31
+ #
32
+ # [+el+] The element of type +NAME+ to be converted.
33
+ #
34
+ # [+indent+] A number representing the current amount of spaces for indent (only used for
35
+ # block-level elements).
36
+ #
37
+ # The return value of such a method has to be a string containing the element +el+ formatted as
38
+ # Confluence element.
39
+ class Confluence < Base
40
+
41
+ # The amount of indentation used when nesting Confluence tags.
42
+ attr_accessor :indent
43
+
44
+ # Initialize the Confluence converter with the given Kramdown document +doc+.
45
+ def initialize(root, options)
46
+ super
47
+ @indent = 2
48
+ @stack = []
49
+ end
50
+
51
+ # The mapping of element type to conversion method.
52
+ DISPATCHER = Hash.new {|h,k| h[k] = "convert_#{k}"}
53
+
54
+ # Dispatch the conversion of the element +el+ to a +convert_TYPE+ method using the +type+ of
55
+ # the element.
56
+ def convert(el, indent = -@indent)
57
+ send(DISPATCHER[el.type], el, indent)
58
+ end
59
+
60
+ # Return the converted content of the children of +el+ as a string. The parameter +indent+ has
61
+ # to be the amount of indentation used for the element +el+.
62
+ #
63
+ # Pushes +el+ onto the @stack before converting the child elements and pops it from the stack
64
+ # afterwards.
65
+ def inner(el, indent)
66
+ result = ''
67
+ indent += @indent
68
+ @stack.push(el)
69
+ el.children.each do |inner_el|
70
+ result << send(DISPATCHER[inner_el.type], inner_el, indent)
71
+ end
72
+ @stack.pop
73
+ result
74
+ end
75
+
76
+ def convert_blank(el, indent)
77
+ "\n"
78
+ end
79
+
80
+ def convert_text(el, indent)
81
+ el.value
82
+ end
83
+
84
+ def convert_p(el, indent)
85
+ "#{' '*indent}#{inner(el, indent)}\n\n"
86
+ end
87
+
88
+
89
+ def convert_blockquote(el, indent)
90
+ "#{' '*indent}bq. #{inner(el, indent)}\n"
91
+ end
92
+
93
+ def convert_header(el, indent)
94
+ "h#{el.options[:level]}. #{inner(el, indent)}\n"
95
+ end
96
+
97
+ def convert_hr(el, indent)
98
+ "#{' '*indent}----\n"
99
+ end
100
+
101
+ def convert_ul(el, indent)
102
+ ""
103
+ end
104
+ alias :convert_ol :convert_ul
105
+ alias :convert_dl :convert_ul
106
+
107
+ def convert_li(el, indent)
108
+ "#{'-'*el.options[:level]} #{inner(el, indent)}\n"
109
+ end
110
+ alias :convert_dd :convert_li
111
+
112
+ def convert_dt(el, indent)
113
+ inner(el, indent)
114
+ end
115
+
116
+ def convert_html_element(el, indent)
117
+ inner(el, indent)
118
+ end
119
+
120
+ def convert_xml_comment(el, indent)
121
+ ""
122
+ end
123
+ alias :convert_xml_pi :convert_xml_comment
124
+
125
+ def convert_table(el, indent)
126
+ ""
127
+ end
128
+
129
+ def convert_thead(el, indent)
130
+ inner(el, indent)
131
+ end
132
+
133
+ def convert_empty(el, indent)
134
+ ""
135
+ end
136
+ alias :convert_tbody :convert_empty
137
+ alias :convert_tfoot :convert_empty
138
+ alias :convert_tr :convert_empty
139
+
140
+ def convert_td(el, indent)
141
+ inner(el, indent)
142
+ end
143
+
144
+ def convert_comment(el, indent)
145
+ inner(el, indent)
146
+ end
147
+
148
+ def convert_br(el, indent)
149
+ "\\"
150
+ end
151
+
152
+ def convert_a(el, indent)
153
+ text=inner(el,indent)
154
+ link=el.attr['href']
155
+ markup="[#{text+'|' unless text.nil?}#{link}]"
156
+ return markup
157
+ end
158
+
159
+ def convert_img(el, indent)
160
+ src=el.attr['src']
161
+ alt=el.attr['alt']
162
+ markup="!#{src}#{"|alt=" unless alt.nil?}!"
163
+ return markup
164
+ end
165
+
166
+ def convert_codeblock(el, indent)
167
+ "#{' '*indent}{code}#{inner(el, ident)}{code}\n"
168
+ end
169
+
170
+ def convert_codespan(el, indent)
171
+ "#{' '*indent}{code}#{inner(el, ident)}{code}\n"
172
+ end
173
+
174
+ def convert_footnote(el, indent)
175
+ inner(el, indent)
176
+ end
177
+
178
+ def convert_raw(el, indent)
179
+ inner(el, indent)
180
+ end
181
+
182
+ def convert_em(el, indent)
183
+ "_#{inner(el, indent)}_"
184
+ end
185
+
186
+ def convert_strong(el, indent)
187
+ "*#{inner(el, indent)}*"
188
+ end
189
+
190
+ def convert_entity(el, indent)
191
+ inner(el,indent)
192
+ end
193
+
194
+ def convert_typographic_sym(el, indent)
195
+ inner(el,indent)
196
+ end
197
+
198
+ def convert_smart_quote(el, indent)
199
+ inner(el,indent)
200
+ end
201
+
202
+ def convert_math(el, indent)
203
+ inner(el,indent)
204
+ end
205
+
206
+ def convert_abbreviation(el, indent)
207
+ inner(el,indent)
208
+ end
209
+
210
+ def convert_root(el, indent)
211
+ inner(el, indent)
212
+ end
213
+
214
+ end
215
+
216
+ end
217
+ end
@@ -0,0 +1,6 @@
1
+ module Markdown2Confluence
2
+ end
3
+
4
+ unless defined?(Markdown2Confluence::VERSION)
5
+ ::Markdown2Confluence::VERSION = "0.0.1a"
6
+ end
@@ -0,0 +1,2 @@
1
+ require 'kramdown'
2
+ require 'markdown2confluence/convertor/confluence'
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/markdown2confluence/version", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "markdown2confluence"
6
+ s.version = Markdown2Confluence::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Patrick Debois"]
9
+ s.email = ["patrick.debois@jedi.be"]
10
+ s.homepage = "http://github.com/jedi4ever/markdown2confluence/"
11
+ s.summary = %q{Convert Markdown to confluence wiki style}
12
+ s.description = %q{Based on Kramdown, a convert object .to_confluence}
13
+
14
+ s.required_rubygems_version = ">= 1.3.6"
15
+ s.rubyforge_project = "markdown2confluence"
16
+
17
+ s.add_dependency "kramdown"
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
21
+ s.require_path = 'lib'
22
+ end
23
+
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: markdown2confluence
3
+ version: !ruby/object:Gem::Version
4
+ hash: 46
5
+ prerelease: 5
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ - a
11
+ version: 0.0.1a
12
+ platform: ruby
13
+ authors:
14
+ - Patrick Debois
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-12-13 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :runtime
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ prerelease: false
33
+ name: kramdown
34
+ version_requirements: *id001
35
+ description: Based on Kramdown, a convert object .to_confluence
36
+ email:
37
+ - patrick.debois@jedi.be
38
+ executables:
39
+ - markdown2confluence
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - .gitignore
46
+ - .rvmrc
47
+ - Gemfile
48
+ - README.markdown
49
+ - Rakefile
50
+ - bin/markdown2confluence
51
+ - lib/markdown2confluence.rb
52
+ - lib/markdown2confluence/convertor/confluence.rb
53
+ - lib/markdown2confluence/version.rb
54
+ - markdown2confluence.gemspec
55
+ homepage: http://github.com/jedi4ever/markdown2confluence/
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options: []
60
+
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 3
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 23
78
+ segments:
79
+ - 1
80
+ - 3
81
+ - 6
82
+ version: 1.3.6
83
+ requirements: []
84
+
85
+ rubyforge_project: markdown2confluence
86
+ rubygems_version: 1.8.12
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Convert Markdown to confluence wiki style
90
+ test_files: []
91
+