diff --git a/wiki/patches.txt b/wiki/patches.txt index 9f6efe34..fb6b6da1 100644 --- a/wiki/patches.txt +++ b/wiki/patches.txt @@ -8,4 +8,5 @@ wiki.wiki.doctype.wiki_feedback.patches.delete_wiki_feedback_item wiki.wiki.doctype.wiki_space.patches.wiki_sidebar_migration wiki.wiki.doctype.wiki_settings.patches.wiki_navbar_item_migration wiki.wiki.doctype.wiki_page.patches.convert_wiki_content_to_markdown -wiki.wiki.doctype.wiki_page.patches.update_escaped_code_content \ No newline at end of file +wiki.wiki.doctype.wiki_page.patches.update_escaped_code_content +wiki.wiki.doctype.wiki_page.patches.update_escaped_chars \ No newline at end of file diff --git a/wiki/wiki/doctype/wiki_page/patches/update_escaped_chars.py b/wiki/wiki/doctype/wiki_page/patches/update_escaped_chars.py new file mode 100644 index 00000000..6f000740 --- /dev/null +++ b/wiki/wiki/doctype/wiki_page/patches/update_escaped_chars.py @@ -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