Skip to content

Commit c81e20b

Browse files
author
Andrew L
committed
Update readme
1 parent 9bd8558 commit c81e20b

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

Diff for: README.md

+19
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,25 @@ Some `<table>`s are not meant to be pasted as markdown; for example, a file cont
4444
</table>
4545
```
4646

47+
### Granular control for pasting as plain text
48+
49+
If you're wanting more granular support of pasting certain items as plain text by default, you can pass in the controls config at the `subscribe` level.
50+
51+
Our config support looks as follows:
52+
53+
```js
54+
import {subscribe} from '@github/paste-markdown'
55+
56+
// Subscribe the behavior to the textarea with pasting URL links as plain text by default.
57+
subscribe(document.querySelector('textarea[data-paste-markdown]'), {defaultPlainTextPaste: {urlLinks: true}})
58+
```
59+
60+
In this scenario above, pasting a URL over selected text will paste as plain text by default, but pasting a table will still paste as markdown by default.
61+
62+
Only the `urlLinks` param is currently supported.
63+
64+
If there is no config passed in, or attributes missing, this will always default to `false`, being the existing behavior.
65+
4766
## Development
4867

4968
```

Diff for: src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface Subscription {
1414
}
1515

1616
function subscribe(el: HTMLElement, optionConfig?: OptionConfig): Subscription {
17-
installSkipFormatting(el, [installTable, installImageLink, installText, installHTML], [installLink], optionConfig)
17+
installSkipFormatting(el, [installTable, installImageLink, installLink, installText, installHTML], optionConfig)
1818
return {
1919
unsubscribe: () => {
2020
uninstallSkipFormatting(el)

Diff for: src/option-config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ interface PlainTextParams {
88
// Not currently implemented behavior
99
/*imageLinks?: boolean
1010
html?: boolean
11-
table?: boolean
11+
tables?: boolean
1212
text?: boolean*/
1313
}

Diff for: src/paste-keyboard-shortcut-helper.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,12 @@ export function shouldSkipFormatting(el: HTMLElement): boolean {
2525

2626
export function installAround(
2727
el: HTMLElement,
28-
installCallbacks: Array<(el: HTMLElement) => void>,
29-
installCallbacksWithOptions: Array<(el: HTMLElement, optionConfig?: OptionConfig) => void>,
28+
installCallbacks: Array<(el: HTMLElement, optionConfig?: OptionConfig) => void>,
3029
optionConfig?: OptionConfig
3130
): void {
3231
el.addEventListener('keydown', setSkipFormattingFlag)
3332

3433
for (const installCallback of installCallbacks) {
35-
installCallback(el)
36-
}
37-
38-
for (const installCallback of installCallbacksWithOptions) {
3934
installCallback(el, optionConfig)
4035
}
4136

0 commit comments

Comments
 (0)