Skip to content

Commit c414132

Browse files
committed
add images to wikkawiki conversion
1 parent 9a34d3c commit c414132

File tree

3 files changed

+13
-39
lines changed

3 files changed

+13
-39
lines changed

lib/caramelize/filters/wikka_to_markdown.rb

+8-14
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ def replace_formatting
3535
target_body.gsub!(%r{(//)(.*?)(//)}, '*\2*') # italic
3636
target_body.gsub!(/(__)(.*?)(__)/) { |_s| "<u>#{::Regexp.last_match(2)}</u>" } # underline
3737
target_body.gsub!(/(---)/, ' ') # forced linebreak
38-
target_body.gsub!(/(^ )/, ' ') # preformatted line
3938
end
4039

4140
def replace_lists
@@ -65,20 +64,15 @@ def replace_code_block
6564
target_body.gsub!(/^%%\s(.*?)%%\s?/m) { "```\n#{::Regexp.last_match(1)}```\n" }
6665
end
6766

68-
def replace_images
69-
# {{image class="center" alt="DVD logo" title="An image link" url="images/dvdvideo.gif" link="RecentChanges"}}
70-
target_body.gsub!(/{{image\s(.*)}}/) do |match|
71-
puts match.inspect
72-
url = match[1].match(/url="([^"]*)"/)
73-
link = match[1].match(/link="([^"]*)"/)
74-
alt = match[1].match(/alt="([^"]*)"/)
75-
76-
return "![#{alt}](#{url})" if link.nil? || link.empty?
77-
78-
"[[<img src=\"#{url}\" alt=\"#{alt}\">]]"
79-
end
80-
67+
def replace_images
68+
# {{image class="center" alt="DVD logo" title="An image link" url="images/dvdvideo.gif" link="RecentChanges"}}
69+
target_body.gsub!(/{{image\s(.*)}}/) do |image_match|
70+
url = image_match.match(/url="([^"]*)"/)[1]
71+
link = image_match.match(/link="([^"]*)"/) && image_match.match(/link="([^"]*)"/)[1]
72+
alt = image_match.match(/alt="([^"]*)"/) && image_match.match(/alt="([^"]*)"/)[1]
8173

74+
link.nil? ? "![#{alt}](#{url})" : "[[<img src=\"#{url}\" alt=\"#{alt}\">|#{link}]]"
75+
end
8276
end
8377

8478
def target_body

lib/caramelize/input_wiki/media_wiki.rb

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ def read_pages
5959

6060
def read_authors
6161
database.query(authors_query).each do |row|
62-
puts row.inspect
6362
name = row['user_real_name'].empty? ? row['user_name'] : 'Anonymous'
6463
email = row['user_email'].empty? ? nil : row['user_email']
6564
authors[row['user_id']] = { name:, email: }

spec/lib/caramelize/filters/wikka_to_markdown_spec.rb

+5-24
Original file line numberDiff line numberDiff line change
@@ -71,37 +71,19 @@
7171
end
7272

7373
context 'when unordered list entry' do
74-
context 'with tab based' do
74+
context 'with tabs' do
7575
let(:body) { "\t-unordered list entry" }
7676

7777
it { is_expected.to eq '- unordered list entry' }
7878
end
7979

80-
context 'with tabs' do
80+
context 'with tilde' do
8181
let(:body) { '~-unordered list entry' }
8282

8383
it { is_expected.to eq '- unordered list entry' }
8484
end
8585

8686
context 'with spaces' do
87-
let(:body) { ' -unordered list entry' }
88-
89-
it { is_expected.to eq '- unordered list entry' }
90-
end
91-
92-
context 'with tab based with space' do
93-
let(:body) { "\t- unordered list entry" }
94-
95-
it { is_expected.to eq '- unordered list entry' }
96-
end
97-
98-
context 'with another tab based with space' do
99-
let(:body) { '~- unordered list entry' }
100-
101-
it { is_expected.to eq '- unordered list entry' }
102-
end
103-
104-
context 'with space based with space' do
10587
let(:body) { ' - unordered list entry' }
10688

10789
it { is_expected.to eq '- unordered list entry' }
@@ -129,7 +111,7 @@
129111
it { is_expected.to eq '[[LemmaLemma]]' }
130112
end
131113

132-
context 'with only url sklfs' do
114+
context 'with only wikilink' do
133115
let(:body) { "\n [[ComunitySiteIdeas]] \n" }
134116

135117
it { is_expected.to eq "\n [[ComunitySiteIdeas]] \n" }
@@ -266,13 +248,13 @@
266248
context 'with link' do
267249
let(:body) { '{{image class="center" alt="DVD logo" title="An image link" url="images/dvdvideo.gif" link="RecentChanges"}}' }
268250

269-
it { is_expected.to eq '[<img src="images/dvdvideo.gif" alt="DVD Logo">](RecentChanges]])' }
251+
it { is_expected.to eq '[[<img src="images/dvdvideo.gif" alt="DVD logo">|RecentChanges]]' }
270252
end
271253

272254
context 'with alt and with title' do
273255
let(:body) { '{{image class="center" alt="DVD logo" title="An image link" url="images/dvdvideo.gif"}}' }
274256

275-
it { is_expected.to eq '![DVD Logo](images/dvdvideo.gif)' }
257+
it { is_expected.to eq '![DVD logo](images/dvdvideo.gif)' }
276258
end
277259

278260
context 'without alt and with title' do
@@ -287,6 +269,5 @@
287269
it { is_expected.to eq '![](images/dvdvideo.gif)' }
288270
end
289271
end
290-
291272
end
292273
end

0 commit comments

Comments
 (0)