Skip to content

Convert certain HTML pastes to Markdown #52

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vgwidt
Copy link
Owner

@vgwidt vgwidt commented Aug 9, 2023

This PR would allow certain HTML pastes to be converted to Markdown automatically in input forms where markdown is supported. This would be especially helpful for tables.

The first commit is a very simple, clumsy sample using html2md. When pasting, the handle_paste function gets the text/html value. It checks for a tag indicating it came from Excel, grabs the content from <table> to </table> and runs it through the html2md parse_html function to get the markdown equivalent.

I haven't looked too much into how robust html2md is for generating markdown (seems to cover original basics), but we might need to extend it or use html5ever to do it ourselves. This will take some looking into.

This requires rustflags=["--cfg=web_sys_unstable_apis"] due to the use of ClipboardEvent, but this results in dependencies being recompiled on each run. This would need to be fixed somehow before merging.

  • Scanning the entire clipboard is not efficient, check the tags where the attributes should be to determine origin
  • Fix data also being pasted as plain text (by means of oninput)
  • Refactor code for use in all markdown editors
  • Add other potential sources (i.e. LibreOffice)
  • Make tables pretty with CSS
  • Consider other types other than tables

@vgwidt
Copy link
Owner Author

vgwidt commented Aug 9, 2023

It is worth mentioning that html is displayed (after sanitizing), so html tables do work without converting them to markdown.

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