88
99A blockquote will be converted if
1010
11- 1. it begins with a header
12- 2. that header has attributes
13- 3. those attributes contain a single class
14- 4. that class is one of ['objectives', 'callout', 'challenge']
11+ 1. it begins with a header
12+ 2. that either
13+ 1. matches "Prerequisites", "Objectives", "Callout" or "Challenge" OR
14+ 2. has attributes containing a single class matching
15+ one of ['prereq', 'objectives', 'callout', 'challenge']
1516
1617For example, this is a valid blockquote:
1718
2526 Let's do something.
2627 </div>
2728
29+ This is also a valid blockquote:
30+
31+ > ## Prerequisites
32+ > Breakfast!
33+
34+ and it will be converted into this markdown:
35+
36+ <div class='prereq'>
37+ ## Prerequisites
38+ Breakfast!
39+ </div>
40+
2841
2942For debugging purposes you may find it useful to test the filter
3043like this:
3447import pandocfilters as pf
3548
3649
37- valid_classes = ['objectives' , 'callout' , 'challenge' ]
50+ # These are classes that, if set on the title of a blockquote, will
51+ # trigger the blockquote to be converted to a div.
52+ SPECIAL_CLASSES = ['callout' , 'challenge' , 'prereq' , 'objectives' ]
3853
54+ # These are titles of blockquotes that will cause the blockquote to
55+ # be converted into a div. They are 'title': 'class' pairs, where the
56+ # 'title' will create a blockquote with the corresponding 'class'.
57+ SPECIAL_TITLES = {'prerequisites' : 'prereq' ,
58+ 'learning objectives' : 'objectives' ,
59+ 'objectives' : 'objectives' ,
60+ 'challenge' : 'challenge' ,
61+ 'callout' : 'callout' }
3962
40- def find_attributes (blockquote ):
63+
64+ def find_header (blockquote ):
4165 """Find attributes in a blockquote if they are defined on a
4266 header that is the first thing in the block quote.
4367
@@ -46,7 +70,7 @@ def find_attributes(blockquote):
4670 """
4771 if blockquote [0 ]['t' ] == 'Header' :
4872 level , attr , inline = blockquote [0 ]['c' ]
49- return attr
73+ return level , attr , inline
5074
5175
5276def remove_attributes (blockquote ):
@@ -71,10 +95,21 @@ def blockquote2div(key, value, format, meta):
7195 """
7296 if key == 'BlockQuote' :
7397 blockquote = value
74- attr = find_attributes (blockquote )
75- if not attr :
98+
99+ header = find_header (blockquote )
100+ if not header :
76101 return
77- elif len (attr [1 ]) == 1 and attr [1 ][0 ] in valid_classes :
102+ else :
103+ level , attr , inlines = header
104+
105+ id , classes , kvs = attr
106+
107+ ltitle = pf .stringify (inlines ).lower ()
108+ if ltitle in SPECIAL_TITLES :
109+ classes .append (SPECIAL_TITLES [ltitle ])
110+ return pf .Div (attr , blockquote )
111+
112+ elif len (classes ) == 1 and classes [0 ] in SPECIAL_CLASSES :
78113 remove_attributes (blockquote )
79114 # a blockquote is just a list of blocks, so it can be
80115 # passed directly to Div, which expects Div(attr, blocks)
0 commit comments