diff --git a/README.md b/README.md index 9dcef10c6b71b2f4b4fd25eaf6f0c0815b73f90f..88cdffbfebce6855d0095728c9b5eb653322e68e 100644 --- a/README.md +++ b/README.md @@ -346,7 +346,7 @@ file, but again, we're trying to avoid those. --- Paragraph(s) of introductory material. - > ## Prerequisites {.prereq} + > ## Prerequisites > > What learners need to know before tackling this lesson. diff --git a/pages/01-one.md b/pages/01-one.md index 9857e506196cf33aa47efc55270ebbe129dc1e0e..ca4dc268d6b1539b9c418bc9c33993ebebd9c70e 100644 --- a/pages/01-one.md +++ b/pages/01-one.md @@ -4,7 +4,7 @@ title: Lesson Title subtitle: Topic Title One minutes: 10 --- -> ## Learning Objectives {.objectives} +> ## Learning Objectives > > * Learning objective 1 > * Learning objective 2 diff --git a/pages/02-two.md b/pages/02-two.md index b3fdb641a980390f5adf514f8f38b8baaceafeb0..0412d1bb186e0dc2d7bba0c31f4d1b0c242f6441 100644 --- a/pages/02-two.md +++ b/pages/02-two.md @@ -4,7 +4,7 @@ title: Lesson Title subtitle: Topic Title Two minutes: 10 --- -> ## Learning Objectives {.objectives} +> ## Learning Objectives > > * Learning objective 1 > * Learning objective 2 diff --git a/tools/blockquote2div.py b/tools/blockquote2div.py index bd3b52ba8eac77bdf9dcdaa69d44fab0c0c6431b..6797c86472c92a6526d6f572d0d424f9b2a24638 100755 --- a/tools/blockquote2div.py +++ b/tools/blockquote2div.py @@ -8,10 +8,11 @@ Usage: A blockquote will be converted if -1. it begins with a header -2. that header has attributes -3. those attributes contain a single class -4. that class is one of ['objectives', 'callout', 'challenge'] +1. it begins with a header +2. that either + 1. matches "Prerequisites", "Objectives", "Callout" or "Challenge" OR + 2. has attributes containing a single class matching + one of ['prereq', 'objectives', 'callout', 'challenge'] For example, this is a valid blockquote: @@ -25,6 +26,18 @@ and it will be converted into this markdown: Let's do something. </div> +This is also a valid blockquote: + + > ## Prerequisites + > Breakfast! + +and it will be converted into this markdown: + + <div class='prereq'> + ## Prerequisites + Breakfast! + </div> + For debugging purposes you may find it useful to test the filter like this: @@ -34,10 +47,21 @@ 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 = ['callout', 'challenge', 'prereq', 'objectives'] +# 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', + 'learning objectives': 'objectives', + 'objectives': 'objectives', + 'challenge': 'challenge', + 'callout': 'callout'} -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 +70,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 +95,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)