rdoc2md 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5711a7aad65981183498edc0cd6469b353d722d4
4
+ data.tar.gz: 35ea58f1409f79a4c4b2ca7d751e271b5468259b
5
+ SHA512:
6
+ metadata.gz: 613c9d061f4a9162d81bfb299bb8cf2091981a26f7835578e430a064d01c94e5f13c9f37e556c9cdecac424b85fb1a819fc5c5dfa416ad28f1966a1061d5acec
7
+ data.tar.gz: cfeedd93ee77f415e409246764bd90cdbeca55ca9f9bcc43d3f52adaa794994fd2221cd09717d09bab31d47389af19faa99f926d4887b68e6ba881b71826f4de
data/.autotest ADDED
@@ -0,0 +1,4 @@
1
+ # -*- ruby -*-
2
+
3
+ require "autotest/restart"
4
+
data/.gemtest ADDED
File without changes
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ === 0.1.0 / 2014-03-03
2
+
3
+ * First iteration at this gem. Quick and dirty. Probably doesn't cover all possible
4
+ scenarios exhaustively, but it works for converting a typical README.txt file created
5
+ by hoe into a README.md file that github expects.
6
+
data/Manifest.txt ADDED
@@ -0,0 +1,8 @@
1
+ .autotest
2
+ History.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ bin/rdoc2md
7
+ lib/rdoc2md.rb
8
+ test/test_rdoc2md.rb
data/README.txt ADDED
@@ -0,0 +1,68 @@
1
+ = rdoc2md
2
+
3
+ https://github.com/kirkbowers/rdoc2md
4
+
5
+ == Description
6
+
7
+ +rdoc2md+ is a utility for converting Rdoc style documents into markdown. The primary
8
+ motivation is to make a Hoe gem project more github friendly. Hoe depends on a README.txt
9
+ file in Rdoc format. Github expects a README.md file to display nicely on the webpage.
10
+ This utility lets you make the .txt file the master and autogenerate the .md version
11
+ without Repeating Yourself.
12
+
13
+ == Usage
14
+
15
+ To use +rdoc2md+, first install it:
16
+
17
+ [sudo] gem install rdoc2md
18
+
19
+ Most likely you will want to run it on the command line, like so:
20
+
21
+ rdoc2md README.txt > README.md
22
+
23
+ You can use it inside of a Ruby program by passing a +String+ to the initializer of the
24
+ +Rdoc2md::Document+ object and calling +to_md+:
25
+
26
+ require 'rdoc2md'
27
+
28
+ result = Rdoc2md::Document.new(text).to_md
29
+
30
+ I tried for the life of me to make it work as a Hoe plugin, but no luck. That may be a
31
+ future feature. In the meantime, add +require 'rdoc2md'+ near the top of your
32
+ +Rakefile+ and add this near the bottom:
33
+
34
+ task :readme do
35
+ readme = File.open("README.txt").read
36
+ File.open('README.md', 'w') do |file|
37
+ file.write(Rdoc2md::Document.new(readme).to_md)
38
+ end
39
+ end
40
+
41
+ This will allow you to run +rake readme+ before you commit to github and generate a
42
+ markdown version of your README.
43
+
44
+ == Dependencies
45
+
46
+ +rdoc2md+ does not depend on any other gem in order to run.
47
+
48
+ It does, however, depend on by hoe[https://github.com/seattlerb/hoe] and
49
+ shoulda[https://github.com/thoughtbot/shoulda] for development and testing.
50
+
51
+ == Developers/Contributing
52
+
53
+ After checking out the source, run:
54
+
55
+ rake newb
56
+
57
+ This task will install any missing dependencies, run the tests/specs,
58
+ and generate the RDoc.
59
+
60
+ This first pass is very ad-hoc. I make no claims that it exhaustively covers all
61
+ situations where Rdoc could be converted to an equivalent markdown notation. If you
62
+ find a shortcoming, by all means, feel free to upgrade it. I welcome all contributions.
63
+
64
+ I do prefer that such shortcomings be documented first in the Issues. I may be working on a fix already. No sense in two people fixing the same thing....
65
+
66
+ == License
67
+
68
+ +rdoc2md+ is released under the MIT license.
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ # -*- ruby -*-
2
+
3
+ require "rubygems"
4
+ require "hoe"
5
+ require "rdoc2md"
6
+
7
+ # Hoe.plugin :compiler
8
+ # Hoe.plugin :gem_prelude_sucks
9
+ # Hoe.plugin :inline
10
+ # Hoe.plugin :minitest
11
+ # Hoe.plugin :racc
12
+ # Hoe.plugin :rcov
13
+ # Hoe.plugin :rubyforge
14
+
15
+ Hoe.spec "rdoc2md" do
16
+ developer("Kirk Bowers", "kirkbowers@yahoo.com")
17
+
18
+ license "MIT" # this should match the license in the README
19
+ end
20
+
21
+ task :readme do
22
+ readme = File.open("README.txt").read
23
+ File.open('README.md', 'w') do |file|
24
+ file.write(Rdoc2md::Document.new(readme).to_md)
25
+ end
26
+ end
27
+
28
+ task :md2html, [:readme] do
29
+ `Markdown.pl README.md > README.html`
30
+ end
31
+
32
+ # vim: syntax=ruby
data/bin/rdoc2md ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rdoc2md'
4
+
5
+ def usage
6
+ puts <<EOF
7
+ rdoc2md <infile>
8
+
9
+ Converts the input file from an Rdoc style text file to a markdown file.
10
+ The results are sent to stdout.
11
+ It expects the input file to be a "README" type file with no hash marks
12
+ preceding the Rdoc mark ups.
13
+ EOF
14
+
15
+ abort
16
+ end
17
+
18
+ usage unless ARGV.length == 1
19
+
20
+ text = File.open(ARGV[0]).read
21
+ # Protect against goofy carriage returns on non-unix systems
22
+ text.gsub!(/\r\n?/, "\n")
23
+
24
+ print Rdoc2md::Document.new(text).to_md
25
+
data/lib/rdoc2md.rb ADDED
@@ -0,0 +1,67 @@
1
+
2
+ module Rdoc2md
3
+ VERSION = "0.1.0"
4
+
5
+ # Rdoc2md::Document takes a String representing a document in Rdoc format (sans leading
6
+ # hashmark comments) and converts it into a similar markdown document.
7
+ #
8
+ # Author:: Kirk Bowers (mailto:kirkbowers@yahoo.com)
9
+ # Copyright:: Copyright (c) 2014 Frabjous Apps LLC
10
+ # License:: MIT License
11
+ class Document
12
+ # The text is the document to be converted from rdoc style to markdown.
13
+ # It should be a String.
14
+ attr_accessor :text
15
+
16
+ # The initializer takes an optional text, which is the document to be converted from
17
+ # rdoc style to markdown.
18
+ def initialize(text = "")
19
+ @text = text
20
+ end
21
+
22
+ # Convert the existing document to markdown. The result is returned as a String.
23
+ def to_md
24
+ # Usually ruby is extremely readable, but I think "-1" means "give me all the
25
+ # trailing blank lines" is surprisingly opaque. That's what the -1 does...
26
+ lines = @text.split("\n", -1)
27
+ lines.collect do |line|
28
+ result = line
29
+
30
+ # Leave lines that start with 4 spaces alone. These are code blocks and
31
+ # should pass through unchanged.
32
+ unless result =~ /^\s{4,}/
33
+
34
+ # Convert headers
35
+ result.sub!(/^(=){1,6}/) { |s| "#" * s.length} unless result =~ /^={7,}/
36
+
37
+ # Convert strong to have two stars
38
+ # The matching pair of stars should start with a single star that is either at
39
+ # the beginning of the line or not following a backslash, have at least one
40
+ # non-star and non-backslash in between, then end in one star
41
+ result.gsub!(/(\A|[^\\\*])\*([^\*]*[^\*\\])\*/, '\1**\2**')
42
+
43
+ # Convert inline code spans to use backticks
44
+ result.gsub!(/(\A|[^\\])\+([^\+]*)\+/, '\1`\2`')
45
+
46
+ # Convert bare http:, mailto: and ftp: links
47
+ result.gsub!(/(\A|\s)(http:|https:|mailto:|ftp:)(\S*)/, '\1[\2\3](\2\3)')
48
+
49
+ # Convert bare www to an http: link
50
+ result.gsub!(/(\A|\s)www\.(\S*)/, '\1[www.\2](http://www.\2)')
51
+
52
+ # Convert link: links to refer to local files
53
+ result.gsub!(/(\A|\s)link:(\S*)/, '\1[\2](\2)')
54
+
55
+ # Convert multi word labels surrounded by {} with a url
56
+ result.gsub!(/\{([^\}]*)\}\[(\S*)\]/, '[\1](\2)')
57
+
58
+ # Convert one word labels with a url
59
+ result.gsub!(/(\A|\s)([^\{\s]\S*)\[(\S*)\]/, '\1[\2](\3)')
60
+
61
+ end
62
+
63
+ result
64
+ end.join("\n")
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,317 @@
1
+ require "shoulda-context"
2
+ require "rdoc2md"
3
+
4
+ class TestRdoc2md < Test::Unit::TestCase
5
+ context "When converting non-commented text" do
6
+ should "leave dashed bulleted lists untouched" do
7
+ text = <<EOF
8
+ - This is a bulleted list item
9
+ - So is this
10
+ EOF
11
+ result = Rdoc2md::Document.new(text).to_md
12
+ assert_equal text, result
13
+ end
14
+
15
+
16
+ should "leave starred bulleted lists untouched" do
17
+ text = <<EOF
18
+ * This is a starred list item
19
+ * So is this
20
+ EOF
21
+ result = Rdoc2md::Document.new(text).to_md
22
+ assert_equal text, result
23
+ end
24
+
25
+
26
+ should "leave numbered lists untouched" do
27
+ text = <<EOF
28
+ 1. This is a numbered list item
29
+ 2. So is this
30
+ EOF
31
+ result = Rdoc2md::Document.new(text).to_md
32
+ assert_equal text, result
33
+ end
34
+
35
+
36
+ should "leave paragraphs untouched" do
37
+ text = <<EOF
38
+ This is a paragraph.
39
+
40
+ This is a second paragraph that
41
+ continues on more than one line.
42
+ EOF
43
+ result = Rdoc2md::Document.new(text).to_md
44
+ assert_equal text, result
45
+ end
46
+
47
+
48
+ should "convert equal signs for headings to hashes" do
49
+ text = <<EOF
50
+ = Level 1 heading
51
+
52
+ == Level 2
53
+
54
+ === Level 3
55
+
56
+ ==== Level 4
57
+
58
+ ===== Level 5
59
+
60
+ ====== Level 6
61
+
62
+ ======= Not a heading
63
+ EOF
64
+
65
+ expected = <<EOF
66
+ # Level 1 heading
67
+
68
+ ## Level 2
69
+
70
+ ### Level 3
71
+
72
+ #### Level 4
73
+
74
+ ##### Level 5
75
+
76
+ ###### Level 6
77
+
78
+ ======= Not a heading
79
+ EOF
80
+
81
+ result = Rdoc2md::Document.new(text).to_md
82
+ assert_equal expected, result
83
+ end
84
+
85
+ should "leave emphasized untouched" do
86
+ text = <<EOF
87
+ This is _emphasized_ text.
88
+ EOF
89
+ result = Rdoc2md::Document.new(text).to_md
90
+ assert_equal text, result
91
+ end
92
+
93
+ should "convert strong to have two stars in the middle of the line" do
94
+ text = <<EOF
95
+ This is *strong* text.
96
+ EOF
97
+
98
+ expected = <<EOF
99
+ This is **strong** text.
100
+ EOF
101
+
102
+ result = Rdoc2md::Document.new(text).to_md
103
+ assert_equal expected, result
104
+ end
105
+
106
+
107
+ should "convert strong to have two stars at the start of the line" do
108
+ text = <<EOF
109
+ *strong* text at the beginning.
110
+ EOF
111
+
112
+ expected = <<EOF
113
+ **strong** text at the beginning.
114
+ EOF
115
+
116
+ result = Rdoc2md::Document.new(text).to_md
117
+ assert_equal expected, result
118
+ end
119
+
120
+
121
+ should "leave double stars untouched" do
122
+ text = <<EOF
123
+ This is **double starred** text.
124
+ EOF
125
+ result = Rdoc2md::Document.new(text).to_md
126
+ assert_equal text, result
127
+ end
128
+
129
+
130
+ should "leave backslashed stars untouched" do
131
+ text = <<EOF
132
+ This is \\*escaped starred* text.
133
+ EOF
134
+ result = Rdoc2md::Document.new(text).to_md
135
+ assert_equal text, result
136
+ end
137
+
138
+
139
+ should "convert typewriter to have backticks in the middle of the line" do
140
+ text = <<EOF
141
+ This is +code+ text.
142
+ EOF
143
+
144
+ expected = <<EOF
145
+ This is \`code\` text.
146
+ EOF
147
+
148
+ result = Rdoc2md::Document.new(text).to_md
149
+ assert_equal expected, result
150
+ end
151
+
152
+
153
+ should "convert typewriter to have backticks at the start of the line" do
154
+ text = <<EOF
155
+ +code+ text at the beginning.
156
+ EOF
157
+
158
+ expected = <<EOF
159
+ `code` text at the beginning.
160
+ EOF
161
+
162
+ result = Rdoc2md::Document.new(text).to_md
163
+ assert_equal expected, result
164
+ end
165
+
166
+
167
+ should "leave backslashed typewriter untouched" do
168
+ text = <<EOF
169
+ This is \\+escaped code+ text.
170
+ EOF
171
+ result = Rdoc2md::Document.new(text).to_md
172
+ assert_equal text, result
173
+ end
174
+
175
+
176
+ should "convert typewriter and allow backslashes inside code span" do
177
+ text = <<EOF
178
+ +code\\+ containing a backslash.
179
+ EOF
180
+
181
+ expected = <<EOF
182
+ `code\\` containing a backslash.
183
+ EOF
184
+
185
+ result = Rdoc2md::Document.new(text).to_md
186
+ assert_equal expected, result
187
+ end
188
+
189
+
190
+ should "convert bare http reference to square bracketed with url as label" do
191
+ text = <<EOF
192
+ Ruby : http://www.ruby-lang.org
193
+ EOF
194
+
195
+ expected = <<EOF
196
+ Ruby : [http://www.ruby-lang.org](http://www.ruby-lang.org)
197
+ EOF
198
+
199
+ result = Rdoc2md::Document.new(text).to_md
200
+ assert_equal expected, result
201
+ end
202
+
203
+
204
+ should "convert bare http reference at beginning of line" do
205
+ text = <<EOF
206
+ http://www.ruby-lang.org is the url to follow
207
+ EOF
208
+
209
+ expected = <<EOF
210
+ [http://www.ruby-lang.org](http://www.ruby-lang.org) is the url to follow
211
+ EOF
212
+
213
+ result = Rdoc2md::Document.new(text).to_md
214
+ assert_equal expected, result
215
+ end
216
+
217
+
218
+ should "convert bare https reference to square bracketed with url as label" do
219
+ text = <<EOF
220
+ https://github.com/kirkbowers/rdoc2md
221
+ EOF
222
+
223
+ expected = <<EOF
224
+ [https://github.com/kirkbowers/rdoc2md](https://github.com/kirkbowers/rdoc2md)
225
+ EOF
226
+
227
+ result = Rdoc2md::Document.new(text).to_md
228
+ assert_equal expected, result
229
+ end
230
+
231
+
232
+ should "convert bare mailto reference to square bracketed with url as label" do
233
+ text = <<EOF
234
+ Email me at mailto:someone@example.com
235
+ EOF
236
+
237
+ expected = <<EOF
238
+ Email me at [mailto:someone@example.com](mailto:someone@example.com)
239
+ EOF
240
+
241
+ result = Rdoc2md::Document.new(text).to_md
242
+ assert_equal expected, result
243
+ end
244
+
245
+
246
+ should "convert bare ftp reference to square bracketed with url as label" do
247
+ text = <<EOF
248
+ Download at ftp://phonyurl.com today!
249
+ EOF
250
+
251
+ expected = <<EOF
252
+ Download at [ftp://phonyurl.com](ftp://phonyurl.com) today!
253
+ EOF
254
+
255
+ result = Rdoc2md::Document.new(text).to_md
256
+ assert_equal expected, result
257
+ end
258
+
259
+
260
+ should "convert www reference to square bracketed with url as label and http protocol" do
261
+ text = <<EOF
262
+ Get more details at www.ruby-lang.org
263
+ EOF
264
+
265
+ expected = <<EOF
266
+ Get more details at [www.ruby-lang.org](http://www.ruby-lang.org)
267
+ EOF
268
+
269
+ result = Rdoc2md::Document.new(text).to_md
270
+ assert_equal expected, result
271
+ end
272
+
273
+
274
+ should "convert link: reference to square bracketed with local link as label" do
275
+ text = <<EOF
276
+ Check the link:faq.html file for more info.
277
+ EOF
278
+
279
+ expected = <<EOF
280
+ Check the [faq.html](faq.html) file for more info.
281
+ EOF
282
+
283
+ result = Rdoc2md::Document.new(text).to_md
284
+ assert_equal expected, result
285
+ end
286
+
287
+
288
+ should "convert label[url] references where label is one word" do
289
+ text = <<EOF
290
+ Visit the Ruby[http://www.ruby-lang.com] site.
291
+ EOF
292
+
293
+ expected = <<EOF
294
+ Visit the [Ruby](http://www.ruby-lang.com) site.
295
+ EOF
296
+
297
+ result = Rdoc2md::Document.new(text).to_md
298
+ assert_equal expected, result
299
+ end
300
+
301
+
302
+ should "convert {label}[url] references where label can be multiple words" do
303
+ text = <<EOF
304
+ Visit the {Ruby website}[http://www.ruby-lang.com]
305
+ EOF
306
+
307
+ expected = <<EOF
308
+ Visit the [Ruby website](http://www.ruby-lang.com)
309
+ EOF
310
+
311
+ result = Rdoc2md::Document.new(text).to_md
312
+ assert_equal expected, result
313
+ end
314
+
315
+
316
+ end
317
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rdoc2md
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kirk Bowers
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rdoc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: hoe
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '3.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '3.9'
41
+ description: |-
42
+ +rdoc2md+ is a utility for converting Rdoc style documents into markdown. The primary
43
+ motivation is to make a Hoe gem project more github friendly. Hoe depends on a README.txt
44
+ file in Rdoc format. Github expects a README.md file to display nicely on the webpage.
45
+ This utility lets you make the .txt file the master and autogenerate the .md version
46
+ without Repeating Yourself.
47
+ email:
48
+ - kirkbowers@yahoo.com
49
+ executables:
50
+ - rdoc2md
51
+ extensions: []
52
+ extra_rdoc_files:
53
+ - History.txt
54
+ - Manifest.txt
55
+ - README.txt
56
+ files:
57
+ - .autotest
58
+ - .gemtest
59
+ - History.txt
60
+ - Manifest.txt
61
+ - README.txt
62
+ - Rakefile
63
+ - bin/rdoc2md
64
+ - lib/rdoc2md.rb
65
+ - test/test_rdoc2md.rb
66
+ homepage: https://github.com/kirkbowers/rdoc2md
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options:
72
+ - --main
73
+ - README.txt
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project: rdoc2md
88
+ rubygems_version: 2.2.2
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: +rdoc2md+ is a utility for converting Rdoc style documents into markdown
92
+ test_files:
93
+ - test/test_rdoc2md.rb