Skip to content

Commit

Permalink
fix: fix errors, undo escaped code content in previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AyshaHakeem committed Sep 23, 2024
1 parent a7cf1ca commit 9896d4b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 33 deletions.
3 changes: 2 additions & 1 deletion wiki/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ wiki.wiki.doctype.wiki_feedback.patches.delete_wiki_feedback_item
[post_model_sync]
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.convert_wiki_content_to_markdown
wiki.wiki.doctype.wiki_page.patches.update_escaped_code_content
10 changes: 9 additions & 1 deletion wiki/public/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@ function setEditor() {
theme: "ace/theme/tomorrow_night",
});
editor.renderer.lineHeight = 20;
editor.setValue(markdown_content || "", 1);
frappe.call({
method: "wiki.wiki.doctype.wiki_page.wiki_page.get_markdown_content",
args: {
wikiPageName,
},
callback: (r) => {
editor.setValue(r.message || "", 1);
},
});
wikiTitleInput.val($(".wiki-title").text() || "");
}

Expand Down
29 changes: 6 additions & 23 deletions wiki/public/scss/wiki.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,9 @@ body {

// ------------------------------------------

font-family:
InterVariable,
ui-sans-serif,
system-ui,
-apple-system,
BlinkMacSystemFont,
Segoe UI,
Roboto,
Helvetica Neue,
Arial,
Noto Sans,
sans-serif,
"Apple Color Emoji",
"Segoe UI Emoji",
Segoe UI Symbol,
font-family: InterVariable, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, Noto Sans,
sans-serif, "Apple Color Emoji", "Segoe UI Emoji", Segoe UI Symbol,
"Noto Color Emoji";

background-color: var(--background-color);
Expand Down Expand Up @@ -328,10 +316,7 @@ body.dark {
&.active {
background-color: var(--sidebar-active-item-color);
border-radius: 0.625rem;
box-shadow:
0 0 #0000,
0 0 #0000,
0px 1px 2px rgba(0, 0, 0, 0.1);
box-shadow: 0 0 #0000, 0 0 #0000, 0px 1px 2px rgba(0, 0, 0, 0.1);
}

div {
Expand Down Expand Up @@ -777,6 +762,7 @@ body.dark {
margin-bottom: 1rem;
}
.wiki-title-input {
color: var(--text-color);
background-color: var(--editor-background-color);
}
}
Expand Down Expand Up @@ -969,10 +955,7 @@ h6:hover .feather-link {
.active {
color: var(--text-color);
box-shadow: 1px 0 0 var(--primary) inset;
transition:
color 0.2s,
box-shadow 0.2s linear,
transform 0.2s linear;
transition: color 0.2s, box-shadow 0.2s linear, transform 0.2s linear;
}

a {
Expand Down
14 changes: 14 additions & 0 deletions wiki/wiki/doctype/wiki_page/patches/update_escaped_code_content.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import frappe


def execute():
wiki_pages = frappe.db.get_all("Wiki Page", fields=["name", "content"])
for page in wiki_pages:
markdown_content = (
page["content"]
.replace("`", "`")
.replace("${", "${")
.replace(">", ">")
.replace("&lt;", "<")
)
frappe.db.set_value("Wiki Page", page["name"], "content", markdown_content)
6 changes: 3 additions & 3 deletions wiki/wiki/doctype/wiki_page/templates/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<h1 class="wiki-title">{{ title }}</h1>
</div>
<div class="wiki-content">
{{frappe.utils.md_to_html(show_content)}}
{{frappe.utils.md_to_html(content)}}
</div>
<input value={{ name }} class="d-none" name="wiki-page-name"></input>
{% include "wiki/doctype/wiki_page/templates/revisions.html" %}
Expand Down Expand Up @@ -92,7 +92,7 @@ <h5 class="modal-title" id="addGroupModalTitle">Title</h5>
{{ include_script('wiki.bundle.js') }}

<script>
const markdown_content = `{{content}}`;
const wikiPageName = `{{name}}`;
function getSidebarItems() {
let side = {};

Expand Down Expand Up @@ -126,4 +126,4 @@ <h5 class="modal-title" id="addGroupModalTitle">Title</h5>

{%- if script -%}
<script>{{ script }}</script>
{%- endif -%}
{%- endif -%}
11 changes: 6 additions & 5 deletions wiki/wiki/doctype/wiki_page/wiki_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

class WikiPage(WebsiteGenerator):
def before_save(self):
self.content = self.sanitize_html().replace("`", "&#96;").replace("${", "&#36;{")

if old_title := frappe.db.get_value("Wiki Page", self.name, "title"):
if old_title != self.title:
clear_sidebar_cache()
Expand Down Expand Up @@ -130,7 +128,7 @@ def attributes_filter(tag, name, value):
if "youtube.com/embed/" not in iframe["src"]:
iframe.replace_with(str(iframe))

escaped_html = str(soup).replace("`", "&#96;").replace("${", "&#36;{")
escaped_html = str(soup)
return escaped_html

def update_page(self, title, content, edit_message, raised_by=None):
Expand Down Expand Up @@ -241,8 +239,6 @@ def get_context(self, context):
"Wiki Group Item", {"wiki_page": self.name}, "hide_on_sidebar"
)
html = frappe.utils.md_to_html(self.content)
context.show_content = self.content.replace("&#96;", "`").replace("&#36;{", "${")
#
context.content = self.content
context.page_toc_html = (
self.calculate_toc_html(html) if wiki_settings.enable_table_of_contents else None
Expand Down Expand Up @@ -606,3 +602,8 @@ def update_page_settings(name, settings):
)

frappe.db.set_value("Wiki Page", name, "route", settings.route)


@frappe.whitelist()
def get_markdown_content(wikiPageName):
return frappe.db.get_value("Wiki Page", wikiPageName, "content")

0 comments on commit 9896d4b

Please sign in to comment.