Improve title parsing logic (#88)
This commit is contained in:
parent
c1e623ebc2
commit
6f0a64c83f
2 changed files with 10 additions and 3 deletions
|
|
@ -10,7 +10,7 @@ class MarkdownFixer
|
|||
end
|
||||
|
||||
def add_quotes_to_title(markdown)
|
||||
markdown.gsub(/title:\s?(.*?)\n/m) do |target|
|
||||
markdown.gsub(/title:\s?(.*?)(\r\n|\n)/m) do |target|
|
||||
# $1 is the captured group (.*?)
|
||||
captured_title = $1
|
||||
# The query below checks if the whole title is wrapped in
|
||||
|
|
|
|||
|
|
@ -30,10 +30,17 @@ RSpec.describe MarkdownFixer do
|
|||
end
|
||||
|
||||
it "handles complex title" do
|
||||
legacy_title = %(Book review: "#{sample_title}", part 1 I'm #deep)
|
||||
expected_title = "\"Book review: \\\"#{sample_title}\\\", part 1 I'm #deep\""
|
||||
legacy_title = %(Book review: "#{sample_title}", part 1 I'm #testing)
|
||||
expected_title = "\"Book review: \\\"#{sample_title}\\\", part 1 I'm #testing\""
|
||||
test = described_class.fix_all(create_sample_markdown(legacy_title))
|
||||
expect(test).to eq create_sample_markdown(expected_title)
|
||||
end
|
||||
|
||||
it "handles title with \r\n" do
|
||||
title = "\"hmm\"\r\n"
|
||||
expected_title = "\"hmm\"\n"
|
||||
test = described_class.fix_all(create_sample_markdown(title))
|
||||
expect(test).to eq create_sample_markdown(expected_title)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue