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.
Turndown currently converts both string and DOM element inputs to Markdown. String conversion has been supported since the beginning and I think is one of the reasons for the library's popularity.
String inputs are ultimately parsed and converted to a DOM tree for accurate conversion. Turndown uses the JSDOM library to parse strings as HTML and it was chosen because it is popular, well maintained, and accurate. It also mirrors the DOM interface used in browsers and so provides a familiar interface for software developers to query and manipulate DOM nodes (useful for developers to add their own conversion rules and contribute to the project). However, as it is so fully-featured, its use does incur a performance cost. Downloading and requiring the library, as well as parsing strings can seem needlessly time-consuming, particularly because much of the library is not needed for this purpose.
The challenge for this pull request is to maintain the same Turndown API to avoid breakages for the developers using it, whilst creating a way for those wanting improved performance.
This pull request creates an additional package (
turndown-core
) within this repository. From an API perspective it's almost identical toturndown
, except it does not convert strings. Theturndown
simply package importsturndown-core
and will parse string inputs before conversion.In terms of the implementation, Turndown Core is simply stripped of any string conversion code. Turndown imports Turndown Core and overrides the
turndown
method, checking for string inputs and parsing them if necessary.Due to the similarity of the packages, and to make it easier to maintain, the packages both reside in a single repository.