diff --git a/lms/hooks.py b/lms/hooks.py
index a8913578..0c82242b 100644
--- a/lms/hooks.py
+++ b/lms/hooks.py
@@ -306,6 +306,7 @@ lms_markdown_macro_renderers = {
"Assignment": "lms.plugins.assignment_renderer",
"Embed": "lms.plugins.embed_renderer",
"Audio": "lms.plugins.audio_renderer",
+ "PDF": "lms.plugins.pdf_renderer",
}
# page_renderer to manage profile pages
diff --git a/lms/plugins.py b/lms/plugins.py
index 590820f3..b0f40cd2 100644
--- a/lms/plugins.py
+++ b/lms/plugins.py
@@ -185,6 +185,10 @@ def audio_renderer(src):
return f""
+def pdf_renderer(src):
+ return f""
+
+
def assignment_renderer(detail):
supported_types = {
"Document": ".doc,.docx,.xml,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document",
diff --git a/lms/www/batch/edit.js b/lms/www/batch/edit.js
index 8922626b..65318ccc 100644
--- a/lms/www/batch/edit.js
+++ b/lms/www/batch/edit.js
@@ -54,11 +54,6 @@ const get_tools = () => {
"https://docs.google.com/presentation/d/e/<%= remote_id %>/embed",
html: "",
},
- pdf: {
- regex: /(https?:\/\/.*\.pdf)/,
- embedUrl: "<%= remote_id %>",
- html: "",
- },
},
},
},
@@ -131,6 +126,15 @@ const parse_string_to_lesson = (type) => {
file_type: "audio",
},
});
+ } else if (block.includes("{{ PDF")) {
+ let pdf = block.match(/\(["']([^"']+?)["']\)/)[1];
+ blocks.push({
+ type: "upload",
+ data: {
+ file_url: pdf,
+ file_type: "pdf",
+ },
+ });
} else if (block.includes("{{ Embed")) {
let embed = block.match(/\(["']([^"']+?)["']\)/)[1];
blocks.push({
@@ -195,23 +199,21 @@ const parse_content_to_string = (data, type) => {
lesson_content += `{{ Quiz("${block.data.quiz}") }}\n`;
} else if (block.type == "upload") {
let url = block.data.file_url;
- lesson_content +=
- block.data.file_type == "video"
- ? `{{ Video("${url}") }}\n`
- : block.data.file_type == "audio"
- ? `{{ Audio("${url}") }}\n`
- : ``;
+ if (block.data.file_type == "video") {
+ lesson_content += `{{ Video("${url}") }}\n`;
+ } else if (block.data.file_type == "audio") {
+ lesson_content += `{{ Audio("${url}") }}\n`;
+ } else if (block.data.file_type == "pdf") {
+ lesson_content += `{{ PDF("${url}") }}\n`;
+ } else {
+ lesson_content += ``;
+ }
} else if (block.type == "header") {
lesson_content +=
"#".repeat(block.data.level) + ` ${block.data.text}\n`;
} else if (block.type == "paragraph") {
lesson_content += `${block.data.text}\n`;
} else if (block.type == "embed") {
- if (block.data.service == "pdf") {
- if (!block.data.embed.startsWith(window.location.origin)) {
- frappe.throw(__("Invalid PDF URL"));
- }
- }
lesson_content += `{{ Embed("${
block.data.service
}|||${block.data.embed.replace(/&/g, "&")}") }}\n`;
@@ -287,6 +289,10 @@ const get_file_type = (url) => {
return "audio";
}
+ if (url.split(".").pop() == "pdf") {
+ return "pdf";
+ }
+
return "image";
};
@@ -468,7 +474,7 @@ class Upload {
folder: "Home/Attachments",
make_attachments_public: true,
restrictions: {
- allowed_file_types: ["image/*", "video/*", "audio/*"],
+ allowed_file_types: ["image/*", "video/*", "audio/*", ".pdf"],
},
on_success: (file_doc) => {
self.file_url = file_doc.file_url;
@@ -487,6 +493,10 @@ class Upload {
return ``;
+ } else if (this.file_type == "pdf") {
+ return ``;
} else {
return `
`;
}