3939RE_ATTR = re .compile (fr'(?P<attr_name>{ IDENTIFIER } ){ ATTR } ' , flags = re .I | re .X )
4040
4141ATTRIBUTES = {'id' : RE_ID , 'class' : RE_CLASS , 'attr' : RE_ATTRS }
42+ VALID_MODES = {'auto' , 'inline' , 'block' , 'raw' , 'html' }
4243
4344
4445def parse_selectors (selector ):
@@ -125,13 +126,17 @@ class HTML(Block):
125126 NAME = 'html'
126127 ARGUMENT = True
127128 OPTIONS = {
128- 'markdown' : ['auto' , type_string_in ([ 'auto' , 'inline' , 'block' , 'raw' , 'html' ] )]
129+ 'markdown' : ['auto' , type_string_in (VALID_MODES )]
129130 }
130131
131132 def __init__ (self , length , tracker , md , config ):
132133 """Initialize."""
133134
134135 self .markdown = None
136+ self .custom = {}
137+ for entry in config .get ('custom' ):
138+ mode = entry .get ('mode' , 'auto' )
139+ self .custom [entry ['tag' ]] = mode if mode in VALID_MODES else 'auto'
135140 super ().__init__ (length , tracker , md , config )
136141
137142 def on_validate (self , parent ):
@@ -148,6 +153,10 @@ def on_markdown(self):
148153 """Check if this is atomic."""
149154
150155 mode = self .options ['markdown' ]
156+ if mode == 'auto' :
157+ tag = self .tag .lower ()
158+ mode = self .custom .get (tag , mode )
159+
151160 if mode == 'html' :
152161 mode = 'raw'
153162 return mode
@@ -167,6 +176,10 @@ def on_end(self, block):
167176 """On end event."""
168177
169178 mode = self .options ['markdown' ]
179+ if mode == 'auto' :
180+ tag = self .tag .lower ()
181+ mode = self .custom .get (tag , mode )
182+
170183 if (mode == 'auto' and self .is_html (block )) or mode == 'html' :
171184 block .text = self .md .htmlStash .store (block .text )
172185 elif (mode == 'auto' and self .is_raw (block )) or mode == 'raw' :
@@ -176,6 +189,18 @@ def on_end(self, block):
176189class HTMLExtension (BlocksExtension ):
177190 """HTML Blocks Extension."""
178191
192+ def __init__ (self , * args , ** kwargs ):
193+ """Initialize."""
194+
195+ self .config = {
196+ "custom" : [
197+ [],
198+ "Specify handling for custom blocks."
199+ ]
200+ }
201+
202+ super ().__init__ (* args , ** kwargs )
203+
179204 def extendMarkdownBlocks (self , md , block_mgr ):
180205 """Extend Markdown blocks."""
181206
0 commit comments