matthewwithanm / matthewwithanm/python-markdownify

Behavior with strip_pre=mdfy.STRIP_ONE seems incorrect with trailing newlines within the pre

Open
#255 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.2k
Forks
203
PR merge metrics
No merged PRs in 30d

Description

In [1]: import markdownify as mdfy

In [2]: converter = mdfy.MarkdownConverter(strip_pre=mdfy.STRIP_ONE)

In [3]: print(converter.convert('<pre>\n\nabc\n\n</pre>'))
```

abc
```

Only one trailing newline should be stripped, not both. right?

In [4]: print(converter.convert('<pre>\n\nabc\n\n\n</pre>'))
```

abc

```

In the above, 2 of the 3 newlines are trimmed instead of just 1.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two examples from the issue with MarkdownConverter(strip_pre=mdfy.STRIP_ONE). Inspect the pre-conversion behavior and verify that the resulting Markdown preserves all but one trailing newline in each case; done means both examples match the expected output.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
content
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.