Example #1
0
def composer_preprocessor(intermediate):
    """
    Performs the following modifications to the intermediate:
     - Promote questions token to top level of the ast
     - Converts images to a base64 encoded string to appear directly in the HTML source
     - Add text tags around the solution if they are not already present

    :param intermediate: An intermediate parse object
    :return: A modified intermediate
    """
    def fix_solutions(token):
        if not filters.has_name(token) and token.definition[0].startswith('<text>'):
            token.definition = ['<text>'] + token.definition + ['</text>']
        return token

    def escape_html(token):
        for i in range(len(token.definition)):
            if not filters.has_name(token.definition[i]):
                token.definition[i] = token.definition[i].replace('(', '&#40;').replace(')', '&#41;')
        return token
    
    intermediate.ast = filters.promote(intermediate.ast, 'questions')
    intermediate.ast = filters.img64(intermediate.ast)
    intermediate.ast = filters.apply_function(intermediate.ast, fix_solutions, 'solution')
    intermediate.ast = filters.apply_function(intermediate.ast, escape_html, 'prompt')
    return intermediate
Example #2
0
def composer_preprocessor(intermediate):
    """
    Performs the following modifications to the intermediate:
     - Promote questions token to top level of the ast
     - Converts images to a base64 encoded string to appear directly in the HTML source
     - Add text tags around the solution if they are not already present

    :param intermediate: An intermediate parse object
    :return: A modified intermediate
    """
    def fix_solutions(token):
        if not filters.has_name(token) and token.definition[0].startswith(
                '<text>'):
            token.definition = ['<text>'] + token.definition + ['</text>']
        return token

    def escape_html(token):
        for i in range(len(token.definition)):
            if not filters.has_name(token.definition[i]):
                token.definition[i] = token.definition[i].replace(
                    '(', '&#40;').replace(')', '&#41;')
        return token

    intermediate.ast = filters.promote(intermediate.ast, 'questions')
    intermediate.ast = filters.img64(intermediate.ast)
    intermediate.ast = filters.apply_function(intermediate.ast, fix_solutions,
                                              'solution')
    intermediate.ast = filters.apply_function(intermediate.ast, escape_html,
                                              'prompt')
    return intermediate
Example #3
0
def composer_preprocessor(intermediate):
    """
    Performs the following modifications to the intermediate:
     - [filters.wrap_lists](%/Modules/fitlers.html) is called to warp all consecutive listitem tokens in a list token
     - Converts images to a base64 encoded string to appear directly in the HTML source
     - Verbatim blocks have leading whitespace evenly removed to help formatting in the case where verbatim blocks are
     being read in from formatted source files

    :param intermediate: The intermediate to process
    :return: The processed intermediate
    """
    intermediate.ast = filters.wrap_lists(intermediate.ast)
    intermediate.ast = filters.img64(intermediate.ast)
    intermediate.ast = filters.untab_verb(intermediate.ast)
    return intermediate
Example #4
0
def composer_preprocessor(intermediate):
    """
    Performs the following modifications to the intermediate:
     - [filters.wrap_lists](%/Modules/fitlers.html) is called to warp all consecutive listitem tokens in a list token
     - Converts images to a base64 encoded string to appear directly in the HTML source
     - Verbatim blocks have leading whitespace evenly removed to help formatting in the case where verbatim blocks are
     being read in from formatted source files

    :param intermediate: The intermediate to process
    :return: The processed intermediate
    """
    intermediate.ast = filters.wrap_lists(intermediate.ast)
    intermediate.ast = filters.img64(intermediate.ast)
    intermediate.ast = filters.untab_verb(intermediate.ast)
    return intermediate