Commit 8e283cc6 authored by Robert Schroll's avatar Robert Schroll Committed by Charles Lindsay

Fix regex for restoring quotes in plain text construction

The character following the token is found through a look-ahead, to
avoid consuming the opening of the next token.  (There should be
newlines separating tokens, but in some poorly understood circumstances,
this doesn't happen.)  We don't use a look-behind at the beginning, so
that the second consecutive token doesn't insert a second newline
between the two.  (The first of the pair already gave us one.)

Closes: bgo #723742
parent 74ec08e0
......@@ -374,17 +374,17 @@ public string quote_lines(string text) {
public string resolve_nesting(string text, string[] values) {
try {
GLib.Regex tokenregex = new GLib.Regex("(.?)‘([0-9]*)’(.?)");
GLib.Regex tokenregex = new GLib.Regex("(.?)‘([0-9]*)’(?=(.?))");
return tokenregex.replace_eval(text, -1, 0, 0, (info, res) => {
int key = int.parse(info.fetch(2));
string prev_char = info.fetch(1), next_char = info.fetch(3);
string prev_char = info.fetch(1), next_char = info.fetch(3), insert_next = "";
// Make sure there's a newline before and after the quote.
if (prev_char != "" && prev_char != "\n")
prev_char = prev_char + "\n";
if (next_char != "" && next_char != "\n")
next_char = "\n" + next_char;
insert_next = "\n";
if (key >= 0 && key < values.length) {
res.append(prev_char + quote_lines(resolve_nesting(values[key], values)) + next_char);
res.append(prev_char + quote_lines(resolve_nesting(values[key], values)) + insert_next);
} else {
debug("Regex error in denesting blockquotes: Invalid key");
res.append("");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment