fix(converter): honor <ol start> in html → markdown - #270
Merged
Merged
Conversation
html → markdown always numbered ordered lists from 1, while storage → markdown has honored <ol start> since #246, so the two converters disagreed on the same markup. Keep the attributes of an opening <ol> through tag normalization and read `start` when tokenizing lists. Share the numbering rules with the walker (non-negative integers, at most nine digits, otherwise 1) by moving resolveListStart into lib/list-start.js, and apply the same blank-line rule for a list that does not start at 1 and so cannot interrupt a paragraph, at top level and when nested in an item. Fixes #252
- Keep the attributes of a tag only when it is a real `<ol` followed by whitespace or `>`, so `<ol-x>` and `<ol/...>` are normalised like any other tag instead of losing the list. - Parse attributes one by one and take the first `start`, so `start=7` inside another attribute's value is not read. The name is matched case-insensitively, as in HTML. - Decode numeric character references in the value, matching the walker's parser.
|
🎉 This PR is included in version 2.27.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
storage → markdown has honored
<ol start="N">since #246, but html → markdown (lib/html-to-markdown.js, used byconvert --input-format html) always numbered ordered lists from 1, so the two converters disagreed on the same markup.Changes
<ol>now keeps its attributes through tag normalization, andtokenizeListsreadsstartfrom it (double-quoted, single-quoted or unquoted). Attributes are parsed one by one and the firststartwins, sostart=7inside another attribute's value is not read; the name is matched case-insensitively as in HTML (the walker's XML parser is case-sensitive), and numeric character references in the value are decoded. Only a real<olfollowed by whitespace or>keeps its attributes, so<ol-x>and<ol/...>are normalised like any other tag. Keeping the attributes on the tag, instead of collecting them in a separate list, means a list inside a table cell (whose tags are stripped earlier) cannot shift thestartof a later list.lib/list-start.jsand are shared withStorageWalker:resolveListStartmoved there unchanged (non-negative integers, at most nine digits including the run of items, otherwise 1), along with the "marker that cannot interrupt a paragraph" pattern. Empty items are not counted, as in the walker.9.→10.indents nested content correctly.Behavior notes
<ol start>produces different output; everything else is unchanged.starton<ul>is ignored, and other tags still have their attributes stripped.Testing
<ol start> (#252)tests: the repro,0, whitespace and leading zeros, quote styles, invalid values falling back to 1, the nine-digit limit, empty items, marker widening past 9, several lists in one document, a list in a table cell before another list, nested and after-text blank-line rules, and an unpaired<ol start>.htmlToMarkdownandstorageToMarkdownand expect identical output.npm test(40 suites, 1616 tests) andeslintpass.Fixes #252