turndown icon indicating copy to clipboard operation
turndown copied to clipboard

Separate Turndown Core

Open domchristie opened this issue 4 years ago • 0 comments

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 to turndown, except it does not convert strings. The turndown simply package imports turndown-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.


  • [ ] DRY up config
  • [ ] DRY up tests
  • [ ] Documentation
  • [ ] Travis set up
  • [ ] GFM

domchristie avatar Aug 29 '19 08:08 domchristie