-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #288 from AyshaHakeem/wiki-fix
fix: patch to edit escaped characters in content field
- Loading branch information
Showing
2 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
wiki/wiki/doctype/wiki_page/patches/update_escaped_chars.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import re | ||
|
||
import frappe | ||
|
||
|
||
def execute(): | ||
wiki_pages = frappe.db.get_all("Wiki Page", fields=["name", "content"]) | ||
for page in wiki_pages: | ||
frappe.db.set_value("Wiki Page", page["name"], "content", edit_content(page["content"])) | ||
|
||
|
||
def edit_content(content): | ||
def replacer(match): | ||
code_content = match.group(0) | ||
# replace inside the code block | ||
code_content = code_content.replace(r"\"", '"') | ||
code_content = code_content.replace(r"\_", "_") | ||
code_content = code_content.replace(r"\t", "") | ||
code_content = code_content.replace(r"\G", "") | ||
code_content = code_content.replace(r"\n", "\n") | ||
return code_content | ||
|
||
content = re.sub(r"(```[\s\S]*?```|`[^`]*`)", replacer, content) | ||
|
||
content = content.replace(r"\*", "*") | ||
|
||
return content |