Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate Turndown Core #290

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft

Separate Turndown Core #290

wants to merge 6 commits into from

Conversation

domchristie
Copy link
Collaborator

@domchristie domchristie commented Aug 29, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant