Markdown

Conversion to markdown capabilities.

In order to avoid tqdm’s experimental warning

warnings.filterwarnings("ignore", message='Using `tqdm.autonotebook.tqdm` in notebook mode')

Creating a header in markdown


source

markdown_header

 markdown_header (text:str, template:string.Template=<string.Template
                  object at 0x7fbf53bbd4b0>)

Returns a markdown header for a given text.

Parameters

  • text : str

    Text for the header.

  • template : string template

    The template that defines the appearance of the header, and in which text will 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


source

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


source

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


source

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


source

SvgToMarkdown

 SvgToMarkdown ()

Processor to reformat svg files for including them in markdown strings.


source

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.HtmlQuestion

    The question object.

  • processors : list

    Processors 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)


source

settings_to_markdown

 settings_to_markdown (settings:dict)

Returns a markdown representation of the question given the corresponding settings.

Parameters

  • settings : dict

    User settings (usually read from a YAML file).

Returns

  • markdown: str

    Markdown representation