Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize empty-line handling for li and blockquote content #171

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

chrispy-snps
Copy link
Collaborator

Fixes #170.

The convert_li() and convert_blockquote() functions are updated to use "substitution functions" to compute how each line should be modified. Inside the functions, different actions are taken for content lines versus empty lines.

For example (spaces replaced with · in output):

from markdownify import markdownify as md

html = """
<blockquote>
  <ul>
    <li>
      <p>1</p>
      <ul>
        <li>
          <p>1-a</p>
          <p>2-b</p>
        </li>
      <ul>
    </li>
    <li>
      <p>2</p>
    </li>
  </ul>
</blockquote>
"""
print(md(html, wrap=True, wrap_width=1e8))
# >·*·1
# >
# >···+·1-a
# >
# >·····2-b
# >·*·2

Unit tests are updated to reflect the changes. In addition, manual tests were performed by using Pandoc to convert the Markdown back to HTML to verify correctness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

optimize representation of empty lines in <li> and <blockquote> content
2 participants