warnings.filterwarnings("ignore", message='Using `tqdm.autonotebook.tqdm` in notebook mode')Markdown
In order to avoid tqdm’s experimental warning
Creating a header in markdown
markdown_header
markdown_header (text:str, template:string.Template=<string.Template object at 0x7fe458b94fd0>)
*Returns a markdown header for a given text.
Parameters
text: strText for the header.
template: string templateThe template that defines the appearance of the header, and in which
textwill be embedded.
Returns
out: str Markdown-compatible text.*
py2gift.util.render_latex(markdown_header('Header 1'))Header 1
Markdown from user settings for a question
An example numerical question…
question_settings = {
'name': 'Q1',
'class': 'Numerical',
'statement': 'Consider the constellation\nsample_images/1D_3_elements.svg',
'solution': {
'value': 42,
'error': '10%'
},
'feedback': 'We need to...'
}
class_name = gift_wrapper.question.user_settings_to_class_init(question_settings)
numerical_question = getattr(gift_wrapper.question, class_name)(**question_settings)…and one of multiple choice
question_settings = {
'name': 'Q2',
'class': 'MultipleChoice',
'statement': 'Choose...',
'answers':{
'perfect': 'yep',
'wrong': ['foo', 'fa']
},
'feedback': 'We need to...'
}
class_name = gift_wrapper.question.user_settings_to_class_init(question_settings)
multiple_choice_question = getattr(gift_wrapper.question, class_name)(**question_settings)Patching gift-wrapper questions
Base (abstract) HtmlQuestion
html_question_to_markdown
html_question_to_markdown ()
py2gift.util.render_latex(html_question_to_markdown(numerical_question))Statement
Consider the constellation
sample_images/1D_3_elements.svg
Feedback
We need to…
Numerical question
numerical_to_markdown
numerical_to_markdown ()
py2gift.util.render_latex(numerical_question.to_markdown())Statement
Consider the constellation
sample_images/1D_3_elements.svg
Feedback
We need to…
Solution
42 (error: .2)
Multiple-choice question
multiple_choice_to_markdown
multiple_choice_to_markdown ()
py2gift.util.render_latex(multiple_choice_question.to_markdown())Statement
Choose…
Feedback
We need to…
Choices
- yep
- foo
- fa
A gift-wrapper processor to reformat paths for markdown
SvgToMarkdown
SvgToMarkdown ()
Processor to reformat svg files for including them in markdown strings.
from_question
from_question (q:gift_wrapper.question.HtmlQuestion, processors:List[gift_wrapper.transformer.Transformer])
*Returns the markdown representation of a question.
Parameters
q: gift_wrapper.question.HtmlQuestionThe question object.
processors: listProcessors to be applied.
Returns
out: str Markdown-compatible text.*
py2gift.util.render_latex(from_question(numerical_question, pre_processors))Statement
Consider the constellation
Feedback
We need to…
Solution
42 (error: .2)
settings_to_markdown
settings_to_markdown (settings:dict)
*Returns a markdown representation of the question given the corresponding settings.
Parameters
settings: dictUser settings (usually read from a YAML file).
Returns
markdown: strMarkdown representation*