Skip to content

Instantly share code, notes, and snippets.

@miyohide
Created December 19, 2018 14:17
Show Gist options
  • Save miyohide/5695a901b6618399c25380495fb73c8d to your computer and use it in GitHub Desktop.
Save miyohide/5695a901b6618399c25380495fb73c8d to your computer and use it in GitHub Desktop.
class Pukiwiki2md
STRONG_REG = /''(.+?)''/
LINK_REG = /\[\[(.+?):(.+?)\]\]/
def convert_strong!(line)
line.gsub!(STRONG_REG, "**\\1**")
line
end
def convert_link!(line)
line.gsub!(LINK_REG, "[\\1](\\2)")
line
end
def convert_decorator(line)
[:convert_strong!, :convert_link!].each do |converter|
send(converter, line)
end
line
end
end
require 'minitest/autorun'
require './pukiwiki2md'
class Pukiwiki2mdTest < Minitest::Test
def setup
@p2m = Pukiwiki2md.new
end
def test_convert_strong
actual = @p2m.convert_decorator("aaaa''bbbb''cccc")
assert_equal "aaaa**bbbb**cccc", actual
end
def test_convert_strong_double
actual = @p2m.convert_decorator("aaaa''bbbb''cccc''ddddd''eeeee")
assert_equal "aaaa**bbbb**cccc**ddddd**eeeee", actual
end
def test_convert_strong_and_link
actual = @p2m.convert_decorator("aaa''bbbb''cccc[[hoge:https://hoge]]ddd")
assert_equal "aaa**bbbb**cccc[hoge](https://hoge)ddd", actual
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment