Skip to content

Commit

Permalink
chore: apply formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AyshaHakeem committed Sep 10, 2024
1 parent 2776d86 commit 4e29cf6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 34 deletions.
8 changes: 4 additions & 4 deletions wiki/public/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ const previewToggleBtn = $("#toggle-btn");
const wikiTitleInput = $(".wiki-title-input");
const editWikiBtn = $(".edit-wiki-btn");
const saveWikiPageBtn = document.querySelector(
'[data-wiki-button="saveWikiPage"]'
'[data-wiki-button="saveWikiPage"]',
);
const draftWikiPageBtn = document.querySelector(
'[data-wiki-button="draftWikiPage"]'
'[data-wiki-button="draftWikiPage"]',
);
let showPreview = false;

Expand Down Expand Up @@ -122,7 +122,7 @@ editorContainer.addEventListener(
e.preventDefault();
e.stopPropagation();
},
500
500,
);

editorContainer.addEventListener("drop", function (e) {
Expand Down Expand Up @@ -159,7 +159,7 @@ editorContainer.addEventListener("drop", function (e) {
}
editor.session.insert(
editor.getCursorPosition(),
`![](${encodeURI(file_doc.file_url)}`
`![](${encodeURI(file_doc.file_url)}`,
);
},
});
Expand Down
50 changes: 25 additions & 25 deletions wiki/public/js/render_wiki.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,26 +126,26 @@ window.RenderWiki = class RenderWiki extends Wiki {
if (
!$(
`.doc-sidebar .sidebar-group[data-title="${urlParams.get(
"newWiki"
)}"] .add-sidebar-page`
"newWiki",
)}"] .add-sidebar-page`,
).length
) {
this.add_wiki_sidebar(urlParams.get("newWiki"));

$(
$(
`.sidebar-items > .list-unstyled .h6:contains(${urlParams.get(
"newWiki"
)}) + .add-sidebar-page`
)[0]
"newWiki",
)}) + .add-sidebar-page`,
)[0],
).trigger("click");
} else
$(
$(
`.sidebar-items > .list-unstyled .h6:contains(${urlParams.get(
"newWiki"
)}) + .add-sidebar-page`
)[1]
"newWiki",
)}) + .add-sidebar-page`,
)[1],
).trigger("click");
}
$(".wiki-footer, .wiki-page-meta").toggleClass("hide");
Expand All @@ -168,7 +168,7 @@ window.RenderWiki = class RenderWiki extends Wiki {
{
scrollTop: offset,
},
100
100,
);
});
});
Expand Down Expand Up @@ -257,7 +257,7 @@ window.RenderWiki = class RenderWiki extends Wiki {
$(".edit-wiki-btn, .sidebar-edit-mode-btn").on("click", function () {
if (frappe.session.user === "Guest")
window.location.assign(
`/login?redirect-to=${window.location.pathname}`
`/login?redirect-to=${window.location.pathname}`,
);
else {
const urlParams = new URLSearchParams(window.location.search);
Expand All @@ -283,7 +283,7 @@ window.RenderWiki = class RenderWiki extends Wiki {
const groupName = $(".sidebar-item.active").data("group-name");
$(".edit-wiki-btn").trigger("click");
$(
`.doc-sidebar .add-sidebar-page[data-group-name="${groupName}"]`
`.doc-sidebar .add-sidebar-page[data-group-name="${groupName}"]`,
).trigger("click");
});

Expand All @@ -308,7 +308,7 @@ window.RenderWiki = class RenderWiki extends Wiki {
if (newWikiPage.data("group-name") !== groupName) {
// when new item is created in a different group as earlier
newSidebarItem.appendTo(
$(this).parent().parent().children(".list-unstyled")
$(this).parent().parent().children(".list-unstyled"),
);
if (urlParams.get("newWiki") !== groupName)
set_search_params("newWiki", groupName);
Expand All @@ -325,11 +325,11 @@ window.RenderWiki = class RenderWiki extends Wiki {
} else {
// fresh new item
active_items = $(
".sidebar-item.active, .sidebar-item.active .active"
".sidebar-item.active, .sidebar-item.active .active",
).removeClass("active");

newSidebarItem.appendTo(
$(this).parent().parent().children(".list-unstyled")
$(this).parent().parent().children(".list-unstyled"),
);
if (!$(".wiki-editor").is(":visible")) toggleEditor();
if (urlParams.get("newWiki") !== groupName)
Expand All @@ -338,7 +338,7 @@ window.RenderWiki = class RenderWiki extends Wiki {

$(this).parent().parent().each(setSortable);
e.stopPropagation();
}
},
);
}

Expand Down Expand Up @@ -367,7 +367,7 @@ window.RenderWiki = class RenderWiki extends Wiki {
title: __("Delete Wiki Page"),
indicator: "red",
message: __(
`Are you sure you want to <b>delete</b> the Wiki Page <b>${title}</b>?`
`Are you sure you want to <b>delete</b> the Wiki Page <b>${title}</b>?`,
),
primary_action: {
label: "Yes",
Expand All @@ -393,7 +393,7 @@ window.RenderWiki = class RenderWiki extends Wiki {
},
},
});
}
},
);
}

Expand All @@ -408,7 +408,7 @@ window.RenderWiki = class RenderWiki extends Wiki {
$(".revision-content").html(),
$(".from-markdown .wiki-content")
.html()
.replaceAll(/<br class="ProseMirror-trailingBreak">/g, "")
.replaceAll(/<br class="ProseMirror-trailingBreak">/g, ""),
);
$(".previous-revision").removeClass("hide");
} else {
Expand Down Expand Up @@ -450,7 +450,7 @@ window.RenderWiki = class RenderWiki extends Wiki {
if (previousRevision.content)
$(".revision-content")[0].innerHTML = HtmlDiff.execute(
previousRevision.content,
currentRevision.content
currentRevision.content,
);
else $(".revision-content")[0].innerHTML = currentRevision.content;
$(".revision-time")[0].innerHTML =
Expand All @@ -471,7 +471,7 @@ window.RenderWiki = class RenderWiki extends Wiki {
$(".previous-revision").removeClass("hide");
$(".revision-content")[0].innerHTML = HtmlDiff.execute(
nextRevision.content,
currentRevision.content
currentRevision.content,
);
$(".revision-time")[0].innerHTML =
`${currentRevision.author} edited ${currentRevision.revision_time}`;
Expand Down Expand Up @@ -503,7 +503,7 @@ window.RenderWiki = class RenderWiki extends Wiki {
$(".doc-sidebar .sidebar-items")
.children(".list-unstyled")
.not(".hidden")
.first()
.first(),
);

$(".web-sidebar ul").each(setSortable);
Expand Down Expand Up @@ -535,7 +535,7 @@ window.RenderWiki = class RenderWiki extends Wiki {
$(this)
.parent()
.append(
$(`<ul class="list-unstyled" style="min-height:20px;"> </ul`)
$(`<ul class="list-unstyled" style="min-height:20px;"> </ul`),
);
}
});
Expand Down Expand Up @@ -566,7 +566,7 @@ window.RenderWiki = class RenderWiki extends Wiki {
// fixes html tags when they are sliced
return new DOMParser().parseFromString(
content.slice(start, end),
"text/html"
"text/html",
).body.innerHTML;
}

Expand Down Expand Up @@ -628,7 +628,7 @@ window.RenderWiki = class RenderWiki extends Wiki {
$dropdown_menu.addClass("show");
dropdownItems = $dropdown_menu.find(".dropdown-item");
});
}, 500)
}, 500),
);

$("#dropdownMenuSearch, .mobile-search-icon").on("click", () => {
Expand Down Expand Up @@ -724,7 +724,7 @@ window.RenderWiki = class RenderWiki extends Wiki {
$(".update-page-settings-button").on("click", function () {
const name = $('[name="wiki-page-name"]').val();
const hideOnSidebar = $('input[name="pageHideOnSidebar"]').prop(
"checked"
"checked",
);
const route =
$(".wiki-space-route-block").text().trim() +
Expand Down
8 changes: 4 additions & 4 deletions wiki/wiki/doctype/wiki_page/patches/convert_to_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def execute():
wiki_pages = frappe.db.get_all("Wiki Page", fields=["name", "content"])
for page in wiki_pages:
markdown_content = frappe.utils.to_markdown(page['content'])
frappe.db.set_value('Wiki Page', page['name'], 'content', markdown_content)
wiki_pages = frappe.db.get_all("Wiki Page", fields=["name", "content"])
for page in wiki_pages:
markdown_content = frappe.utils.to_markdown(page["content"])
frappe.db.set_value("Wiki Page", page["name"], "content", markdown_content)
2 changes: 1 addition & 1 deletion wiki/wiki/doctype/wiki_page/templates/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ <h5 class="modal-title" id="addGroupModalTitle">Title</h5>
<script>
/** // const patchNewCode = `<h1>{{ patch_new_title }}</h1>{{ patch_new_code }}`;
// const patchNewCode = {title: `{{patch_new_title}}`, content: `{{patch_new_code}}`} **/
const patchNewCode = `{{patch_new_title}},{{patch_new_code}}`
const patchNewCode = `{{patch_new_title}},{{patch_new_code}}`
const wikiSearchScope = `{{ wiki_search_scope or "" }}`;
</script>

Expand Down
3 changes: 3 additions & 0 deletions wiki/wiki/doctype/wiki_page/wiki_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,16 +445,19 @@ def _save_file(match):
content = re.sub(r'<img[^>]*src\s*=\s*["\'](?=data:)(.*?)["\']', _save_file, content)
return content, file_ids["name"]


@frappe.whitelist()
def convert_markdown(markdown):
html = frappe.utils.md_to_html(markdown)
return html


@frappe.whitelist()
def convert_html(html):
markdown = frappe.utils.to_markdown(html)
return markdown


@frappe.whitelist()
def update(
name,
Expand Down

0 comments on commit 4e29cf6

Please sign in to comment.