From 4cd2078e7a4f48f191b3568886b3074365dd10a9 Mon Sep 17 00:00:00 2001 From: facelessuser Date: Mon, 23 Jan 2017 23:23:22 -0700 Subject: [PATCH] Fix HTML parse with empty lines If both open and close was not found in first block, additional blocks were evaluated without context of previous blocks. The algorithm needs to evaluate a buffer with the left bracket present. So feed in all items and get the right bracket, then adjust the data_index to be relative to the last block. --- markdown/preprocessors.py | 8 +++++++- tests/misc/html.html | 11 +++++++++++ tests/misc/html.txt | 11 +++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/markdown/preprocessors.py b/markdown/preprocessors.py index 7ea4fcf9f..94f983005 100644 --- a/markdown/preprocessors.py +++ b/markdown/preprocessors.py @@ -258,7 +258,13 @@ def run(self, lines): else: items.append(block) - right_tag, data_index = self._get_right_tag(left_tag, 0, block) + # Need to evaluate all items so we can calculate relative to the left index. + right_tag, data_index = self._get_right_tag(left_tag, left_index, ''.join(items)) + # Adjust data_index: relative to items -> relative to last block + prev_block_length = 0 + for item in items[:-1]: + prev_block_length += len(item) + data_index -= prev_block_length if self._equal_tags(left_tag, right_tag): # if find closing tag diff --git a/tests/misc/html.html b/tests/misc/html.html index 1eb6a9729..5380bbdc2 100644 --- a/tests/misc/html.html +++ b/tests/misc/html.html @@ -8,6 +8,17 @@

Block level html

Html with various attributes. +
+
+ Div with a blank line + + in the middle. +
+
+ This gets treated as HTML. +
+
+

And of course .

this . [this )