diff --git a/examples/course.html b/examples/course.html index ece96c4..ffb5d90 100644 --- a/examples/course.html +++ b/examples/course.html @@ -105,5 +105,58 @@
+

+ Survey +

+
+
+ My Survey +
+

+ Question 1 +

+

+ Question 2 +

+

+ Question 3 +

+ + + This is your feedback text after submitting the survey. + +
+
+
+ My Poll +
+

+ Can you see this poll example? +

+ + + This is your feedback text after submitting the poll. + +
\ No newline at end of file diff --git a/examples/course.md b/examples/course.md index 28b5998..e025d3f 100644 --- a/examples/course.md +++ b/examples/course.md @@ -56,3 +56,37 @@ How many legs does a healthy snake have? ::: +#### Survey + +::: {mu-type=survey} + +#### My Survey {private_results=true max_submissions=10} + +Question 1 + +Question 2 + +Question 3 + +* Answer 1 +* Answer 2 +* Answer 3 + +`This is your feedback text after submitting the survey.` + +::: + +::: {mu-type=survey} + +#### My Poll {private_results=true max_submissions=10} + +Can you see this poll example? + +* Yes +* No +* Maybe + +`This is your feedback text after submitting the poll.` + +::: + diff --git a/examples/olx/sequential/5e20663dadd1e483ac628951dd582ea8.xml b/examples/olx/sequential/5e20663dadd1e483ac628951dd582ea8.xml index 7a605d1..687a36e 100644 --- a/examples/olx/sequential/5e20663dadd1e483ac628951dd582ea8.xml +++ b/examples/olx/sequential/5e20663dadd1e483ac628951dd582ea8.xml @@ -3,4 +3,6 @@ + + diff --git a/examples/olx/vertical/21ab14cf7e8b30af0299c634785a5782.xml b/examples/olx/vertical/21ab14cf7e8b30af0299c634785a5782.xml new file mode 100644 index 0000000..1810196 --- /dev/null +++ b/examples/olx/vertical/21ab14cf7e8b30af0299c634785a5782.xml @@ -0,0 +1,69 @@ + + + + + + diff --git a/mu/formats/base/writer.py b/mu/formats/base/writer.py index ac581e8..bf6877a 100644 --- a/mu/formats/base/writer.py +++ b/mu/formats/base/writer.py @@ -31,3 +31,6 @@ def on_video(self, unit: units.Video) -> None: def on_rawhtml(self, unit: units.RawHtml) -> None: pass + + def on_survey(self, unit: units.Survey) -> None: + pass diff --git a/mu/formats/html/reader.py b/mu/formats/html/reader.py index c40bdd6..e87c46c 100644 --- a/mu/formats/html/reader.py +++ b/mu/formats/html/reader.py @@ -120,6 +120,9 @@ def on_section(self, unit_html: BeautifulSoup) -> t.Iterable[units.Unit]: elif unit_type == "ftq": # Free text question yield from process_ftq(unit_html) + elif unit_type == "survey": + # Survey questionaire + yield from process_survey(unit_html) else: logger.warning("Unit type is unsupported by HTML reader: %s", unit_type) @@ -231,6 +234,18 @@ def process_ftq(unit_html: BeautifulSoup) -> t.Iterable[units.Unit]: yield units.FreeTextQuestion(title=title, question=question, answers=answers) +def process_survey(unit_html: BeautifulSoup) -> t.Iterable[units.Unit]: + title, questions, answers = get_questions_answers(unit_html) + feedback = unit_html.find("code").string.strip() if unit_html.find("code") else "" + yield units.Survey( + title=title, + questions=questions, + answers=answers, + feedback=feedback, + attributes=get_data_attributes(unit_html.find(re.compile("^h[1-6]$"))), + ) + + def process_video(unit_html: BeautifulSoup) -> t.Iterable[units.Unit]: """ https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video @@ -288,6 +303,31 @@ def get_question_answers(unit_html: BeautifulSoup) -> t.Tuple[str, str, t.List[s return title, question, answers +def get_questions_answers( + unit_html: BeautifulSoup, +) -> t.Tuple[str, t.List[str], t.List[str]]: + title = "" + if title_html := find_title(unit_html): + title = title_html.string + + answers = [] + + ul_html = unit_html.find("ul") + if ul_html is None: + raise MuError(f"Missing