Lines Matching refs:block

10 different type of block. Extensions may add/replace/remove BlockProcessors
19 """ Base class for block processors.
24 whether the current block should be processed by this processor. If the
60 def test(self, parent, block):
61 """ Test for block type. Must be overridden by subclasses.
64 on each to determine if the given block of text is of that type. This
66 testing is left to the needs of that particular block type. It could
67 be as simple as ``block.startswith(some_string)`` or a complex regular
68 expression. As the block type may be different depending on the parent
69 of the block (i.e. inside a list), the parent etree element is also
74 * ``parent``: A etree element which will be the parent of the block.
75 * ``block``: A block of text from the source which has been split at
83 When the parser determines the appropriate type of a block, the parser
85 should parse the individual lines of the block and append them to
99 * ``parent``: A etree element which is the parent of the current block.
120 def test(self, parent, block):
121 return block.startswith(' '*markdown.TAB_LENGTH) and \
130 block = blocks.pop(0)
131 level, sibling = self.get_level(parent, block)
132 block = self.looseDetab(block, level)
136 # The parent is already a li. Just parse the child block.
137 self.parser.parseBlocks(parent, [block])
140 self.parser.parseBlocks(sibling, [block])
143 # Assume the last child li is the parent of this block.
146 block = '%s\n\n%s' % (sibling[-1].text, block)
148 self.parser.parseChunk(sibling[-1], block)
150 self.create_item(sibling, block)
153 def create_item(self, parent, block):
154 """ Create a new li and parse the block with it as the parent. """
156 self.parser.parseBlocks(li, [block])
158 def get_level(self, parent, block):
161 m = self.INDENT_RE.match(block)
181 # we have a code block. So we stop here.
189 def test(self, parent, block):
190 return block.startswith(' '*markdown.TAB_LENGTH)
194 block = blocks.pop(0)
198 # The previous block was a code block. As blank lines do not start
199 # new code blocks, append this block to the previous, adding back
202 block, theRest = self.detab(block)
203 code.text = markdown.AtomicString('%s\n%s\n' % (code.text, block.rstrip()))
208 block, theRest = self.detab(block)
209 code.text = markdown.AtomicString('%s\n' % block.rstrip())
211 # This block contained unindented line(s) after the first indented
212 # line. Insert these lines as the first block of the master blocks
221 def test(self, parent, block):
222 return bool(self.RE.search(block))
225 block = blocks.pop(0)
226 m = self.RE.search(block)
228 before = block[:m.start()] # Lines before blockquote
232 block = '\n'.join([self.clean(line) for line in
233 block[m.start():].split('\n')])
236 # Previous block was a blockquote so set that as this blocks parent
241 # Recursively parse block with blockquote as parent.
242 self.parser.parseChunk(quote, block)
265 def test(self, parent, block):
266 return bool(self.RE.match(block))
269 # Check fr multiple items in one block.
273 # Previous block was a list item, so set that as parent
280 # parse first block differently as it gets wrapped in a p.
290 # Loop through items in block, recursively parsing each with the
302 def get_items(self, block):
303 """ Break a block into list items. """
305 for line in block.split('\n'):
333 # Detect a header at start of any line in block
336 def test(self, parent, block):
337 return bool(self.RE.search(block))
340 block = blocks.pop(0)
341 m = self.RE.search(block)
343 before = block[:m.start()] # All lines before header
344 after = block[m.end():] # All lines after header
346 # As the header was not the first line of the block and the
348 # recursively parse this lines as a block.
354 # Insert remaining lines as first block for future parsing.
364 # Detect Setext-style header. Must be first 2 lines of block.
367 def test(self, parent, block):
368 return bool(self.RE.match(block))
388 # Detect hr on any line of a block.
393 def test(self, parent, block):
394 return bool(self.SEARCH_RE.search(block))
399 # Check for lines in block before hr.
411 # check for lines in block after hr.
421 # Detect a block that only contains whitespace
425 def test(self, parent, block):
426 return bool(self.RE.match(block))
429 block = blocks.pop(0)
430 m = self.RE.match(block)
433 blocks.insert(0, block[m.end():])
437 # Last block is a codeblock. Append to preserve whitespace.
444 def test(self, parent, block):
448 block = blocks.pop(0)
449 if block.strip():
450 # Not a blank block. Add to parent, otherwise throw it away.
454 parent.text = '%s\n%s' % (parent.text, block)
456 parent.text = block.lstrip()
460 p.text = block.lstrip()