Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 5805194

Browse files
committed
fix: add http(s) to link in the tuiEditor
ref issue #122
1 parent 16b1aee commit 5805194

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/components/TuiEditor/index.jsx

+13-5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ class TuiEditor extends React.Component {
3131
// this.editorInst.off(eventName);
3232
this.editorInst.on(eventName, props[key]);
3333
});
34+
35+
// always add `https` to the links if link was added without `http` or `https`
36+
this.editorInst.on('convertorAfterHtmlToMarkdownConverted', (inputMarkdown) => {
37+
const outputMarkdown = inputMarkdown.replace(/\[([^\]]*)\]\((?!https?)([^\)]+)\)/g, "[$1](https://$2)")
38+
return outputMarkdown;
39+
});
3440
}
3541

3642
componentDidMount() {
@@ -44,11 +50,13 @@ class TuiEditor extends React.Component {
4450

4551
componentWillUnmount() {
4652
Object.keys(this.props)
47-
.filter((key) => /^on[A-Z][a-zA-Z]+/.test(key))
48-
.forEach((key) => {
49-
const eventName = key[2].toLowerCase() + key.slice(3);
50-
this.editorInst.off(eventName);
51-
});
53+
.filter((key) => /^on[A-Z][a-zA-Z]+/.test(key))
54+
.forEach((key) => {
55+
const eventName = key[2].toLowerCase() + key.slice(3);
56+
this.editorInst.off(eventName);
57+
});
58+
59+
this.editorInst.off('convertorAfterHtmlToMarkdownConverted');
5260
}
5361

5462
shouldComponentUpdate(nextProps) {

0 commit comments

Comments
 (0)