Skip to content

Commit

Permalink
Merge pull request #288 from AyshaHakeem/wiki-fix
Browse files Browse the repository at this point in the history
fix: patch to edit escaped characters in content field
  • Loading branch information
AyshaHakeem authored Oct 16, 2024
2 parents 7983436 + 8aeaa17 commit a7177b4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion wiki/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
wiki.wiki.doctype.wiki_page.patches.update_escaped_code_content
wiki.wiki.doctype.wiki_page.patches.update_escaped_chars
27 changes: 27 additions & 0 deletions wiki/wiki/doctype/wiki_page/patches/update_escaped_chars.py
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

0 comments on commit a7177b4

Please sign in to comment.