Skip to content

Commit d5345d6

Browse files
authored
Merge pull request #361 from torrinlisi/master
Prepend https:// to links, optional but default to true
2 parents b5310db + 6193b2e commit d5345d6

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ The editor component. Simply place this component in your view hierarchy to rece
106106
* `pasteAsPlainText`
107107
A boolean value (false as default) that determines if the clipboard paste will keep its format or it will be done as plain text
108108

109+
* `defaultHttps`
110+
A boolean value (true as default) that prepends https:// to the start of links
111+
109112
* `onPaste`
110113
Callback clipboard paste value
111114

src/RichEditor.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export default class RichTextEditor extends Component {
5757
initialFocus,
5858
disabled,
5959
styleWithCSS,
60+
defaultHttps,
6061
} = props;
6162
that.state = {
6263
html: {
@@ -83,6 +84,7 @@ export default class RichTextEditor extends Component {
8384
firstFocusEnd,
8485
useContainer,
8586
styleWithCSS,
87+
defaultHttps,
8688
}),
8789
},
8890
keyboardHeight: 0,

src/editor.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function createHTML(options = {}) {
4141
firstFocusEnd = true,
4242
useContainer = true,
4343
styleWithCSS = false,
44+
defaultHttps = true,
4445
} = options;
4546
//ERROR: HTML height not 100%;
4647
return `
@@ -354,8 +355,13 @@ function createHTML(options = {}) {
354355
var url = data.url || window.prompt('Enter the link URL');
355356
356357
if (url) {
358+
let href = url
359+
if (${defaultHttps} && !href.startsWith("http")) {
360+
href = "https://" + href
361+
}
362+
357363
var el = document.createElement("a");
358-
el.setAttribute("href", url);
364+
el.setAttribute("href", href);
359365
360366
var title = data.title || sel.toString() || url;
361367
el.text = title;

0 commit comments

Comments
 (0)