diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index 8017f8b..9bccf74 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -314,10 +314,9 @@ module GitHubChangelogGenerator intro = 'Implemented enhancement' end - dict[:title].gsub! '>', '\>' - dict[:title].gsub! '*', '\*' - dict[:title].gsub! '_', '\_' - merge = "*#{intro}:* #{dict[:title]} [\\##{dict[:number]}](#{dict.html_url})\n\n" + enc_string = @generator.encapsulate_string dict[:title] + + merge = "*#{intro}:* #{enc_string} [\\##{dict[:number]}](#{dict.html_url})\n\n" log += "- #{merge}" } end diff --git a/lib/github_changelog_generator/generator.rb b/lib/github_changelog_generator/generator.rb index 1fa7cda..6918db8 100644 --- a/lib/github_changelog_generator/generator.rb +++ b/lib/github_changelog_generator/generator.rb @@ -1,16 +1,14 @@ module GitHubChangelogGenerator class Generator - def initialize(options) + def initialize(options = nil) @options = options end def get_string_for_pull_request(pull_request) - pull_request[:title].gsub! '>', '\>' - pull_request[:title].gsub! '*', '\*' - pull_request[:title].gsub! '_', '\_' + encapsulated_title = self.encapsulate_string pull_request[:title] - merge = "#{@options[:merge_prefix]}#{pull_request[:title]} [\\##{pull_request[:number]}](#{pull_request.html_url})" + merge = "#{@options[:merge_prefix]}#{encapsulated_title} [\\##{pull_request[:number]}](#{pull_request.html_url})" if @options[:author] merge += " ([#{pull_request.user.login}](#{pull_request.user.html_url}))\n\n" else @@ -19,5 +17,18 @@ module GitHubChangelogGenerator merge end + def encapsulate_string(string) + + string.gsub! '\\', '\\\\' + + encpas_chars = %w(> * _ \( \) [ ]) + encpas_chars.each{ |char| + string.gsub! char, "\\#{char}" + } + + string + end + end + end \ No newline at end of file