fix: pdf rendering in lessons
This commit is contained in:
@@ -306,6 +306,7 @@ lms_markdown_macro_renderers = {
|
|||||||
"Assignment": "lms.plugins.assignment_renderer",
|
"Assignment": "lms.plugins.assignment_renderer",
|
||||||
"Embed": "lms.plugins.embed_renderer",
|
"Embed": "lms.plugins.embed_renderer",
|
||||||
"Audio": "lms.plugins.audio_renderer",
|
"Audio": "lms.plugins.audio_renderer",
|
||||||
|
"PDF": "lms.plugins.pdf_renderer",
|
||||||
}
|
}
|
||||||
|
|
||||||
# page_renderer to manage profile pages
|
# page_renderer to manage profile pages
|
||||||
|
|||||||
@@ -185,6 +185,10 @@ def audio_renderer(src):
|
|||||||
return f"<audio width='100%' controls controlsList='nodownload'><source src={quote(src)} type='audio/mp3'></audio>"
|
return f"<audio width='100%' controls controlsList='nodownload'><source src={quote(src)} type='audio/mp3'></audio>"
|
||||||
|
|
||||||
|
|
||||||
|
def pdf_renderer(src):
|
||||||
|
return f"<iframe src='{quote(src)}#toolbar=0' width='100%' height='700px'></iframe>"
|
||||||
|
|
||||||
|
|
||||||
def assignment_renderer(detail):
|
def assignment_renderer(detail):
|
||||||
supported_types = {
|
supported_types = {
|
||||||
"Document": ".doc,.docx,.xml,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
"Document": ".doc,.docx,.xml,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||||
|
|||||||
@@ -54,11 +54,6 @@ const get_tools = () => {
|
|||||||
"https://docs.google.com/presentation/d/e/<%= remote_id %>/embed",
|
"https://docs.google.com/presentation/d/e/<%= remote_id %>/embed",
|
||||||
html: "<iframe width='100%' height='300' frameborder='0' allowfullscreen='true'></iframe>",
|
html: "<iframe width='100%' height='300' frameborder='0' allowfullscreen='true'></iframe>",
|
||||||
},
|
},
|
||||||
pdf: {
|
|
||||||
regex: /(https?:\/\/.*\.pdf)/,
|
|
||||||
embedUrl: "<%= remote_id %>",
|
|
||||||
html: "<iframe width='100%' height='600px' frameborder='0'></iframe>",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -131,6 +126,15 @@ const parse_string_to_lesson = (type) => {
|
|||||||
file_type: "audio",
|
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")) {
|
} else if (block.includes("{{ Embed")) {
|
||||||
let embed = block.match(/\(["']([^"']+?)["']\)/)[1];
|
let embed = block.match(/\(["']([^"']+?)["']\)/)[1];
|
||||||
blocks.push({
|
blocks.push({
|
||||||
@@ -195,23 +199,21 @@ const parse_content_to_string = (data, type) => {
|
|||||||
lesson_content += `{{ Quiz("${block.data.quiz}") }}\n`;
|
lesson_content += `{{ Quiz("${block.data.quiz}") }}\n`;
|
||||||
} else if (block.type == "upload") {
|
} else if (block.type == "upload") {
|
||||||
let url = block.data.file_url;
|
let url = block.data.file_url;
|
||||||
lesson_content +=
|
if (block.data.file_type == "video") {
|
||||||
block.data.file_type == "video"
|
lesson_content += `{{ Video("${url}") }}\n`;
|
||||||
? `{{ Video("${url}") }}\n`
|
} else if (block.data.file_type == "audio") {
|
||||||
: block.data.file_type == "audio"
|
lesson_content += `{{ Audio("${url}") }}\n`;
|
||||||
? `{{ Audio("${url}") }}\n`
|
} else if (block.data.file_type == "pdf") {
|
||||||
: ``;
|
lesson_content += `{{ PDF("${url}") }}\n`;
|
||||||
|
} else {
|
||||||
|
lesson_content += ``;
|
||||||
|
}
|
||||||
} else if (block.type == "header") {
|
} else if (block.type == "header") {
|
||||||
lesson_content +=
|
lesson_content +=
|
||||||
"#".repeat(block.data.level) + ` ${block.data.text}\n`;
|
"#".repeat(block.data.level) + ` ${block.data.text}\n`;
|
||||||
} else if (block.type == "paragraph") {
|
} else if (block.type == "paragraph") {
|
||||||
lesson_content += `${block.data.text}\n`;
|
lesson_content += `${block.data.text}\n`;
|
||||||
} else if (block.type == "embed") {
|
} 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("${
|
lesson_content += `{{ Embed("${
|
||||||
block.data.service
|
block.data.service
|
||||||
}|||${block.data.embed.replace(/&/g, "&")}") }}\n`;
|
}|||${block.data.embed.replace(/&/g, "&")}") }}\n`;
|
||||||
@@ -287,6 +289,10 @@ const get_file_type = (url) => {
|
|||||||
return "audio";
|
return "audio";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (url.split(".").pop() == "pdf") {
|
||||||
|
return "pdf";
|
||||||
|
}
|
||||||
|
|
||||||
return "image";
|
return "image";
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -468,7 +474,7 @@ class Upload {
|
|||||||
folder: "Home/Attachments",
|
folder: "Home/Attachments",
|
||||||
make_attachments_public: true,
|
make_attachments_public: true,
|
||||||
restrictions: {
|
restrictions: {
|
||||||
allowed_file_types: ["image/*", "video/*", "audio/*"],
|
allowed_file_types: ["image/*", "video/*", "audio/*", ".pdf"],
|
||||||
},
|
},
|
||||||
on_success: (file_doc) => {
|
on_success: (file_doc) => {
|
||||||
self.file_url = file_doc.file_url;
|
self.file_url = file_doc.file_url;
|
||||||
@@ -487,6 +493,10 @@ class Upload {
|
|||||||
return `<audio controls width='100%' controls controlsList='nodownload'>
|
return `<audio controls width='100%' controls controlsList='nodownload'>
|
||||||
<source src=${encodeURI(url)} type='audio/mp3'>
|
<source src=${encodeURI(url)} type='audio/mp3'>
|
||||||
</audio>`;
|
</audio>`;
|
||||||
|
} else if (this.file_type == "pdf") {
|
||||||
|
return `<iframe src="${encodeURI(
|
||||||
|
url
|
||||||
|
)}#toolbar=0" width='100%' height='700px'></iframe>`;
|
||||||
} else {
|
} else {
|
||||||
return `<img src=${encodeURI(url)} width='100%'>`;
|
return `<img src=${encodeURI(url)} width='100%'>`;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user