-
-
Notifications
You must be signed in to change notification settings - Fork 590
feat: markdown pasting & custom paste handlers #1490
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
1ced711
feat: an attempt at parsing markdown on paste
nperez0111 f60d856
chore: comment
nperez0111 29162fa
feat: paste as HTML
nperez0111 7f61926
fix deploy
YousefED c060eee
feat: check if pasting looks like markdown
nperez0111 1681c62
refactor: better naming for detecting markdown
nperez0111 1f3ad10
feat: implement a pastHandler API
nperez0111 aee8dcc
docs: add docs for new option
nperez0111 2045027
docs: forgot one option
nperez0111 52ce922
refactor: no need to expose pasteHandler
nperez0111 f20e37d
refactor: pasteText & pasteHTML APIs
nperez0111 5ce1571
docs: add docs on paste handling
nperez0111 913916d
refactor: clean up logic
nperez0111 f3822e5
refactor: split out pasteMarkdown method
nperez0111 c892e7f
docs: update link
nperez0111 af0c5ff
refactor: separate autodetectMarkdown from plaintextAsMarkdown
nperez0111 0670c99
chore: update example text
nperez0111 c055b4c
docs: update readme
nperez0111 83bd820
chore: add period
nperez0111 b232332
refactor: rename autodetectMarkdown -> prioritizeMarkdownOverHTML
nperez0111 7ed58cb
Merge branch 'main' into markdown-paste
nperez0111 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
packages/core/src/api/clipboard/fromClipboard/acceptedMIMETypes.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Headings H1-H6. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. curious how many false positives we get. I didn't review the regexpes obviously. Figured this might be useful: https://chatgpt.com/share/67d12910-3d78-8009-8bc0-ddd23dd7cba9 |
||
const h1 = /(^|\n) {0,3}#{1,6} {1,8}[^\n]{1,64}\r?\n\r?\n\s{0,32}\S/; | ||
|
||
// Bold, italic, underline, strikethrough, highlight. | ||
const bold = /(?:\s|^)(_|__|\*|\*\*|~~|==|\+\+)(?!\s).{1,64}(?<!\s)(?=\1)/; | ||
|
||
// Basic inline link (also captures images). | ||
const link = /\[[^\]]{1,128}\]\(https?:\/\/\S{1,999}\)/; | ||
|
||
// Inline code. | ||
const code = /(?:\s|^)`(?!\s)[^`]{1,48}(?<!\s)`([^\w]|$)/; | ||
|
||
// Unordered list. | ||
const ul = /(?:^|\n)\s{0,5}-\s{1}[^\n]+\n\s{0,15}-\s/; | ||
|
||
// Ordered list. | ||
const ol = /(?:^|\n)\s{0,5}\d+\.\s{1}[^\n]+\n\s{0,15}\d+\.\s/; | ||
|
||
// Horizontal rule. | ||
const hr = /\n{2} {0,3}-{2,48}\n{2}/; | ||
|
||
// Fenced code block. | ||
const fences = | ||
/(?:\n|^)(```|~~~|\$\$)(?!`|~)[^\s]{0,64} {0,64}[^\n]{0,64}\n[\s\S]{0,9999}?\s*\1 {0,64}(?:\n+|$)/; | ||
|
||
// Classical underlined H1 and H2 headings. | ||
const title = /(?:\n|^)(?!\s)\w[^\n]{0,64}\r?\n(-|=)\1{0,64}\n\n\s{0,64}(\w|$)/; | ||
|
||
// Blockquote. | ||
const blockquote = | ||
/(?:^|(\r?\n\r?\n))( {0,3}>[^\n]{1,333}\n){1,999}($|(\r?\n))/; | ||
|
||
// Table Header | ||
const tableHeader = /^\s*\|(.+\|)+\s*$/m; | ||
|
||
// Table Divider | ||
const tableDivider = /^\s*\|(\s*[-:]+[-:]\s*\|)+\s*$/m; | ||
|
||
// Table Row | ||
const tableRow = /^\s*\|(.+\|)+\s*$/m; | ||
|
||
/** | ||
* Returns `true` if the source text might be a markdown document. | ||
* | ||
* @param src Source text to analyze. | ||
*/ | ||
export const is = (src: string): boolean => | ||
h1.test(src) || | ||
bold.test(src) || | ||
link.test(src) || | ||
code.test(src) || | ||
ul.test(src) || | ||
ol.test(src) || | ||
hr.test(src) || | ||
fences.test(src) || | ||
title.test(src) || | ||
blockquote.test(src) || | ||
tableHeader.test(src) || | ||
tableDivider.test(src) || | ||
tableRow.test(src); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.