From 81fb664ad95cb276a73b1ec644ea80f751c0cd77 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Wed, 20 Apr 2022 17:45:40 +0530 Subject: [PATCH] feat: image markdown extension --- lms/hooks.py | 3 ++- lms/lms/md.py | 3 ++- lms/lms/web_form/lesson/lesson.json | 6 +++--- lms/plugins.py | 3 +++ 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lms/hooks.py b/lms/hooks.py index 81783b67..1a4c774a 100644 --- a/lms/hooks.py +++ b/lms/hooks.py @@ -232,7 +232,8 @@ lms_markdown_macro_renderers = { "Quiz": "lms.plugins.quiz_renderer", "YouTubeVideo": "lms.plugins.youtube_video_renderer", "Video": "lms.plugins.video_renderer", - "Assignment": "lms.plugins.assignment_renderer" + "Assignment": "lms.plugins.assignment_renderer", + "Image": "lms.plugin.image_renderer" } # page_renderer to manage profile pages diff --git a/lms/lms/md.py b/lms/lms/md.py index b02ed68f..99bea3d3 100644 --- a/lms/lms/md.py +++ b/lms/lms/md.py @@ -25,6 +25,7 @@ import html as HTML def markdown_to_html(text): """Renders markdown text into html. """ + print(text) return markdown.markdown(text, extensions=['fenced_code', MacroExtension()]) def find_macros(text): @@ -105,7 +106,7 @@ def sanitize_html(html, macro): any broken tags. This makes sures that all those things are fixed before passing to the etree parser. """ - soup = BeautifulSoup(html, features="lxml") + soup = BeautifulSoup(html, features="html5lib") nodes = soup.body.children classname = "" if macro == "YouTubeVideo": diff --git a/lms/lms/web_form/lesson/lesson.json b/lms/lms/web_form/lesson/lesson.json index 2c519587..210a830a 100644 --- a/lms/lms/web_form/lesson/lesson.json +++ b/lms/lms/web_form/lesson/lesson.json @@ -16,12 +16,12 @@ "docstatus": 0, "doctype": "Web Form", "idx": 0, - "introduction_text": "



Create lessons for your course. You can add some additional content to the lesson using a special syntax. The table below mentions all types of dynamic content that you can add to the lessons and the syntax for the same.


Content TypeSyntax
Video{{ Video(\"url_of_source\") }}
YouTube Video{{ YouTubeVideo(\"unique_embed_id\") }}
Exercise{{ Exercise(\"exercise_name\") }}
Quiz{{ Quiz(\"lms_quiz_name\") }}
Assignment{{ Assignment(\"id-filetype\") }}
", + "introduction_text": "



Create lessons for your course. For adding content, use markdown syntax. You can add some additional content to the lesson using a special syntax. The table below mentions all types of dynamic content that you can add to the lessons and the syntax for the same.


Content TypeSyntax
Video{{ Video(\"url_of_source\") }}
YouTube Video{{ YouTubeVideo(\"unique_embed_id\") }}
Exercise{{ Exercise(\"exercise_name\") }}
Quiz{{ Quiz(\"lms_quiz_name\") }}
Assignment{{ Assignment(\"id-filetype\") }}
", "is_multi_step_form": 0, "is_standard": 1, "login_required": 1, "max_attachment_size": 0, - "modified": "2022-03-14 18:49:33.526455", + "modified": "2022-04-20 15:45:55.567759", "modified_by": "Administrator", "module": "LMS", "name": "lesson", @@ -80,7 +80,7 @@ "fieldname": "body", "fieldtype": "Text", "hidden": 0, - "label": "Body", + "label": "Content", "max_length": 0, "max_value": 0, "read_only": 0, diff --git a/lms/plugins.py b/lms/plugins.py index cd03d2a6..479d45e7 100644 --- a/lms/plugins.py +++ b/lms/plugins.py @@ -142,3 +142,6 @@ def show_custom_signup(): or frappe.db.get_single_value("LMS Settings", "privacy_policy")): return "lms/templates/signup-form.html" return "frappe/templates/signup.html" + +def image_renderer(src); + return f""