This fixes problems with the markdownify logic for indentation inside
list items.
This PR uses a branch building on that for #120, #150 and #151, so
those three PRs should be merged first before merging this one.
There is limited logic in markdownify for handling indentation in the
case of nested lists. There are two major problems with this logic:
* As it's in `convert_list`, causing a list to be indented when inside
another list, it does not add indentation for any other elements
such as paragraphs that may be found inside list items (or `<pre>`,
`<blockquote>`, etc.), so such elements are wrongly not indented and
terminate the list in the output.
* It uses fixed indentation of one tab. Following CommonMark, a tab
in Markdown is considered equivalent to four spaces, which is not
sufficient indentation in ordered list items with a number of three
or more digits.
Fix both of these issues by making `convert_li` handle indentation for
the contents of `<li>`, based on the length of the list item marker,
rather than doing it in `convert_list` at all.
This improves the markdownify logic for cleaning up input whitespace
that has no semantic significance in HTML.
This PR uses a branch based on that for #150 (which in turn is based
on that for #120) to avoid conflicts with those fixes. The suggested
order of merging is just first to merge #120, then the rest of #150,
then the rest of this PR.
Whitespace in HTML input isn't generally significant before or after
block-level elements, or at the start of end of such an element other
than `<pre>`. There is some limited logic in markdownify for removing
it, (a) for whitespace-only nodes in conjunction with a limited list
of elements (and with questionable logic that ony removes whitespace
adjacent to such an element when also inside such an element) and (b)
only for trailing whitespace, in certain places in relation to lists.
Replace both those places with more thorough logic using a common list
of block-level elements (which could be expanded more).
In general, this reduces the number of unnecessary blank lines in
output from markdownify (sometimes lines with just a newline,
sometimes lines containing a space as well as that newline). There
are open issues about cases where propagating such input whitespace to
the output actually results in badly formed Markdown output (wrongly
indented output), but #120 (which this builds on) fixes those issues,
sometimes leaving unnecessary lines with just a space on them in the
output, which are dealt with fully by the present PR.
There are a few testcases that are affected because they were relying
on such whitespace for good output from bad HTML input that used `<p>`
or `<blockquote>` inside header tags. To keep reasonable output in
those cases of bad input now input whitespace adjacent to those two
tags is ignored, make the `<p>` and `<blockquote>` output explicitly
include leading and trailing spaces if `convert_as_inline`; such
explicit spaces seem the best that can be done for such bad input.
Given those fixes, all the remaining changes needed to the
expectations of existing tests seem like improvements (removing
useless spaces or newlines from the output).