Page MenuHomePhabricator

Use newlines in WikiEditor search replacements
Open, In Progress, Needs TriagePublicFeature

Description

Description:
The built-in wikitext Search and Replace tool does not recognize \n as a newline character in the "Replace" field. This prevents users from introducing new line breaks into text.

The Issue:

  • Capture groups work: Using Search: (\n) and Replace: $1$1 successfully doubles existing newlines.
  • Literal insertion fails: If the search pattern does not contain a newline (e.g., searching for a period . to turn it into a newline), there is no way to represent a newline in the Replace box. Entering \n results in the literal text "\n" being inserted.

Steps to Reproduce:

  1. Open the Search and Replace tool.
  2. Search for any character (e.g., ,).
  3. Attempt to replace it with a newline by typing \n in the Replace field.
  4. Result: The tool inserts the literal string "\n" instead of a line break.

Expected Behavior:
The Replace field should interpret \n as a newline character (LF) so that users can introduce structural changes to the text without relying on existing capture groups.

Related Objects

Event Timeline

Aklapper changed the subtype of this task from "Task" to "Feature Request".Apr 29 2021, 9:44 AM

A little workaround I thought of (instead of using an external editor) is to replace with a substitution of a template that outputs a newline. I don't know of such a template on any wiki (for example, Template:Break on enwiki evaluates to <br />), so I put <onlyinclude></onlyinclude> surrounding a newline on my user page and now use {{subst:user:wqnvlz}}.

With wikitext:

foo, bar, baz, qux

searching for ,  and replacing with {{subst:user:wqnvlz}}*  then gives:

foo{{subst:user:wqnvlz}}* bar{{subst:user:wqnvlz}}* baz{{subst:user:wqnvlz}}* qux

which, when saved, becomes:

foo
* bar
* baz
* qux

Would it be sensible to create a whole template for wqnvlz's hack? I implemented the same and found minor issues, but it works. Is this an issue likely to be solved sooner... or later?

happy5214 renamed this task from Search and replace a newline to Use newlines in WikiEditor search replacements.Apr 25 2026, 6:59 PM

Change #1296086 had a related patch set uploaded (by Happy5214; author: Happy5214):

[mediawiki/extensions/WikiEditor@master] Allow common escape sequences in replacement strings

https://gerrit.wikimedia.org/r/1296086

happy5214 changed the task status from Open to In Progress.Sat, Oct 24, 3:16 AM