Skip to content

Commit b748e8f

Browse files
Add some useful debug prints
Signed-off-by: Evan Flynn <[email protected]>
1 parent 8ae73a0 commit b748e8f

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

markdown/core.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def convert(self, source):
233233
5. The output is written to a string.
234234
235235
"""
236-
236+
logger.debug("Converting markdown file to serialzed XHTML or HTML")
237237
# Fix up the source text
238238
if not source.strip():
239239
return '' # a blank Unicode string
@@ -246,20 +246,23 @@ def convert(self, source):
246246
raise
247247

248248
# Split into lines and run the line preprocessors.
249+
logger.debug("Split document into lines")
249250
self.lines = source.split("\n")
250251
for prep in self.preprocessors:
252+
logger.debug(f"Running preprocessor prep for {prep.__module__.__str__()}")
251253
self.lines = prep.run(self.lines)
252254

253-
# Parse the high-level elements.
255+
logger.debug("Parse the high-level elements of the file")
254256
root = self.parser.parseDocument(self.lines).getroot()
255257

256-
# Run the tree-processors
258+
logger.debug("Run the tree-processors")
257259
for treeprocessor in self.treeprocessors:
260+
logger.debug(f"Running treeprocessor for {treeprocessor.__module__.__str__()}:{treeprocessor.__class__.__name__}")
258261
newRoot = treeprocessor.run(root)
259262
if newRoot is not None:
260263
root = newRoot
261264

262-
# Serialize _properly_. Strip top-level tags.
265+
logger.debug("Serialize _properly_. Strip top-level tags.")
263266
output = self.serializer(root)
264267
if self.stripTopLevelTags:
265268
try:
@@ -269,14 +272,14 @@ def convert(self, source):
269272
output = output[start:end].strip()
270273
except ValueError as e: # pragma: no cover
271274
if output.strip().endswith('<%s />' % self.doc_tag):
272-
# We have an empty document
275+
logger.debug("Document is empty")
273276
output = ''
274277
else:
275278
# We have a serious problem
276279
raise ValueError('Markdown failed to strip top-level '
277280
'tags. Document=%r' % output.strip()) from e
278281

279-
# Run the text post-processors
282+
logger.debug("Run the text post-processors")
280283
for pp in self.postprocessors:
281284
output = pp.run(output)
282285

markdown/treeprocessors.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
1919
License: BSD (see LICENSE.md for details).
2020
"""
21-
21+
import logging
2222
import re
2323
import xml.etree.ElementTree as etree
2424
from . import util
2525
from . import inlinepatterns
2626

27+
logger = logging.getLogger('MARKDOWN')
28+
2729

2830
def build_treeprocessors(md, **kwargs):
2931
""" Build the default `treeprocessors` for Markdown. """
@@ -340,6 +342,7 @@ def run(self, tree, ancestors=None):
340342
Returns: `ElementTree` object with applied inline patterns.
341343
342344
"""
345+
logger.debug("Running inline treeprocessor")
343346
self.stashed_nodes = {}
344347

345348
# Ensure a valid parent list, but copy passed in lists
@@ -413,7 +416,7 @@ def _prettifyETree(self, elem):
413416

414417
def run(self, root):
415418
""" Add line breaks to `ElementTree` root object. """
416-
419+
logger.debug("Running line break treeprocessor")
417420
self._prettifyETree(root)
418421
# Do `<br />`'s separately as they are often in the middle of
419422
# inline content and missed by `_prettifyETree`.
@@ -445,6 +448,7 @@ def unescape(self, text):
445448
return self.RE.sub(self._unescape, text)
446449

447450
def run(self, root):
451+
logger.debug("Running UnescapeTreeprocessor")
448452
""" Loop over all elements and unescape all text. """
449453
for elem in root.iter():
450454
# Unescape text content

0 commit comments

Comments
 (0)