diff --git a/wiki/public/js/editor.js b/wiki/public/js/editor.js index 79a7e25c..bfba69fa 100644 --- a/wiki/public/js/editor.js +++ b/wiki/public/js/editor.js @@ -27,7 +27,7 @@ editWikiBtn.on("click", () => { $(document).ready(() => { const urlParams = new URLSearchParams(window.location.search); - if (urlParams.get("editWiki") === "1") { + if (urlParams.get("editWiki") || urlParams.get("wikiPagePatch")) { setEditor(); } }); @@ -55,6 +55,7 @@ previewToggleBtn.on("click", function () { }); function setEditor() { + const urlParams = new URLSearchParams(window.location.search); editor.setOptions({ wrap: true, showPrintMargin: true, @@ -65,9 +66,10 @@ function setEditor() { method: "wiki.wiki.doctype.wiki_page.wiki_page.get_markdown_content", args: { wikiPageName, + wikiPagePatch: urlParams.get("wikiPagePatch") || "", }, callback: (r) => { - editor.setValue(r.message || "", 1); + editor.setValue(r.message.content || "", 1); }, }); wikiTitleInput.val($(".wiki-title").text() || ""); diff --git a/wiki/wiki/doctype/wiki_page/wiki_page.py b/wiki/wiki/doctype/wiki_page/wiki_page.py index e4d6156f..35ba474a 100644 --- a/wiki/wiki/doctype/wiki_page/wiki_page.py +++ b/wiki/wiki/doctype/wiki_page/wiki_page.py @@ -599,5 +599,8 @@ def update_page_settings(name, settings): @frappe.whitelist() -def get_markdown_content(wikiPageName): - return frappe.db.get_value("Wiki Page", wikiPageName, "content") +def get_markdown_content(wikiPageName, wikiPagePatch): + if wikiPagePatch: + new_code, new_title = frappe.db.get_value("Wiki Page Patch", wikiPagePatch, ["new_code", "new_title"]) + return {"content": new_code, "title": new_title} + return frappe.db.get_value("Wiki Page", wikiPageName, ["content", "title"], as_dict=True)