Skip to content
Snippets Groups Projects
Commit 10332276 authored by Aaron O'Leary's avatar Aaron O'Leary
Browse files

trigger prereqs class with title

Previously, Div creation was triggered by a Blockquote that began with a
header that contained a single class that was in a list of special
classes.

Now, Div creation is *also* triggered by a Blockquote that begins with a
header that has it's text contained in a list of special titles. The
title is used to lookup an appropriate class to give the Div.

In particular, 'prerequesites' is a special title, giving the class
'prereq'.

This input:

    > ## Prerequesites
    >
    > A short paragraph describing what learners need to know before
    > tackling this lesson.

will trigger this output:

    <div id="prerequisites" class="prereq">
    <h2>Prerequisites</h2>
    <p>A short paragraph describing what learners need to know before
    tackling this lesson.</p>
    </div>
parent a2add95d
Branches
Tags
No related merge requests found
......@@ -34,10 +34,17 @@ like this:
import pandocfilters as pf
valid_classes = ['objectives', 'callout', 'challenge']
# These are classes that, if set on the title of a blockquote, will
# trigger the blockquote to be converted to a div.
special_classes = ['objectives', 'callout', 'challenge']
# These are titles of blockquotes that will cause the blockquote to
# be converted into a div. They are 'title': 'class' pairs, where the
# 'title' will create a blockquote with the corresponding 'class'.
special_titles = {'prerequisites': 'prereq'}
def find_attributes(blockquote):
def find_header(blockquote):
"""Find attributes in a blockquote if they are defined on a
header that is the first thing in the block quote.
......@@ -46,7 +53,7 @@ def find_attributes(blockquote):
"""
if blockquote[0]['t'] == 'Header':
level, attr, inline = blockquote[0]['c']
return attr
return level, attr, inline
def remove_attributes(blockquote):
......@@ -71,10 +78,21 @@ def blockquote2div(key, value, format, meta):
"""
if key == 'BlockQuote':
blockquote = value
attr = find_attributes(blockquote)
if not attr:
header = find_header(blockquote)
if not header:
return
elif len(attr[1]) == 1 and attr[1][0] in valid_classes:
else:
level, attr, inlines = header
id, classes, kvs = attr
ltitle = pf.stringify(inlines).lower()
if ltitle in special_titles:
classes.append(special_titles[ltitle])
return pf.Div(attr, blockquote)
elif len(classes) == 1 and classes[0] in special_classes:
remove_attributes(blockquote)
# a blockquote is just a list of blocks, so it can be
# passed directly to Div, which expects Div(attr, blocks)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment