MuckRock / documentcloud-frontend

DocumentCloud's front end source code - Please report bugs, issues and feature requests to info@documentcloud.org
https://www.documentcloud.org
GNU Affero General Public License v3.0
18 stars 5 forks source link

HTML/Markdown editor #572

Open eyeseast opened 5 months ago

eyeseast commented 5 months ago

Some fields allow (some) HTML. We should have a way to edit that text, without just asking people to write HTML from scratch.

The current site has an HtmlField component. We probably need something similar.

It would be very nice if we could turn the server-sent HTML into Markdown for editing, and then back into HTML to save.

eyeseast commented 5 months ago

Some options:

Thomas Wilburn wrote a converter: https://github.com/Chalkbeat/powertoys/blob/main/paraphrase/htmlToMarkdown.js

Showdown has an undocumented HTML to markdown converter: https://github.com/showdownjs/showdown/blob/master/src/converter.js#L360

CommonMark probably does it, but can't find documentation right now. There are a bunch of libraries on NPM that might work but I don't want to dig through that pile.

Tom MacWright has more options here: https://macwright.com/2024/01/28/dont-use-marked

allanlasser commented 4 months ago

Based on my experience, remark is my preferred library. It's built on the unified interface and uses plugins for processing and transformation, making it very flexible across use cases.