Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

* 👌 Speed up block parsing (~1.2x render) by precomputing line markers per line instead of per character, in [#449](https://github.com/executablebooks/markdown-it-py/pull/449)
* ✨ Add `--enable-tables` to the CLI for file, standard input and interactive parsing in [#422](https://github.com/executablebooks/markdown-it-py/pull/422)
* 🐛 Fix CLI interactive mode joining input lines with an extra newline, which split every line into its own paragraph and broke hard line breaks, in [#172](https://github.com/executablebooks/markdown-it-py/issues/172)
* 🐛 Fix trimming and splitting with the Python whitespace set instead of the CommonMark one, which dropped U+001C–U+001F and U+0085 from paragraphs, headings, table cells and fence info strings and let distinct reference labels resolve each other, in [#418](https://github.com/executablebooks/markdown-it-py/pull/418), thanks to [@Nexory](https://github.com/Nexory)
Expand Down
58 changes: 29 additions & 29 deletions markdown_it/rules_block/state_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,37 +66,37 @@ def __init__(

# Create caches
# Generate markers.
indent_found = False

start = pos = indent = offset = 0
# NOTE: this loop runs once per line, not once per character:
# `str.find` locates each line break at C speed and only leading
# whitespace is scanned (usually zero iterations), instead of
# dispatching every character through `isStrSpace`. The recorded
# markers are identical to the previous per-character scan.
start = 0
length = len(self.src)

for pos, character in enumerate(self.src):
if not indent_found:
if isStrSpace(character):
indent += 1

if character == "\t":
offset += 4 - offset % 4
else:
offset += 1
continue
find = self.src.find

while start < length:
end = find("\n", start)
if end < 0:
end = length
indent = offset = 0
pos = start
while pos < end:
character = self.src[pos]
if not isStrSpace(character):
break
indent += 1
if character == "\t":
offset += 4 - offset % 4
else:
indent_found = True

if character == "\n" or pos == length - 1:
if character != "\n":
pos += 1
self.bMarks.append(start)
self.eMarks.append(pos)
self.tShift.append(indent)
self.sCount.append(offset)
self.bsCount.append(0)

indent_found = False
indent = 0
offset = 0
start = pos + 1
offset += 1
pos += 1
self.bMarks.append(start)
self.eMarks.append(end)
self.tShift.append(indent)
self.sCount.append(offset)
self.bsCount.append(0)
start = end + 1 if end < length else length

# Push fake entry to simplify cache bounds checks
self.bMarks.append(length)
Expand Down