Skip to content

Commit a7177b4

Browse files
authored
Merge pull request #288 from AyshaHakeem/wiki-fix
fix: patch to edit escaped characters in content field
2 parents 7983436 + 8aeaa17 commit a7177b4

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

wiki/patches.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ wiki.wiki.doctype.wiki_feedback.patches.delete_wiki_feedback_item
88
wiki.wiki.doctype.wiki_space.patches.wiki_sidebar_migration
99
wiki.wiki.doctype.wiki_settings.patches.wiki_navbar_item_migration
1010
wiki.wiki.doctype.wiki_page.patches.convert_wiki_content_to_markdown
11-
wiki.wiki.doctype.wiki_page.patches.update_escaped_code_content
11+
wiki.wiki.doctype.wiki_page.patches.update_escaped_code_content
12+
wiki.wiki.doctype.wiki_page.patches.update_escaped_chars
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import re
2+
3+
import frappe
4+
5+
6+
def execute():
7+
wiki_pages = frappe.db.get_all("Wiki Page", fields=["name", "content"])
8+
for page in wiki_pages:
9+
frappe.db.set_value("Wiki Page", page["name"], "content", edit_content(page["content"]))
10+
11+
12+
def edit_content(content):
13+
def replacer(match):
14+
code_content = match.group(0)
15+
# replace inside the code block
16+
code_content = code_content.replace(r"\"", '"')
17+
code_content = code_content.replace(r"\_", "_")
18+
code_content = code_content.replace(r"\t", "")
19+
code_content = code_content.replace(r"\G", "")
20+
code_content = code_content.replace(r"\n", "\n")
21+
return code_content
22+
23+
content = re.sub(r"(```[\s\S]*?```|`[^`]*`)", replacer, content)
24+
25+
content = content.replace(r"\*", "*")
26+
27+
return content

0 commit comments

Comments
 (0)