Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/components/Suggestion/LinkPicker/suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ const isValidMarkdown = (content) => {
}
}

const isValidUrl = (url) => {
try {
return Boolean(new URL(url))
} catch (e) {
return false
}
}

const sortImportantFirst = (list) => {
return [
...list.filter(e => important.indexOf(e.key) > -1),
Expand Down Expand Up @@ -77,9 +85,11 @@ export default () => createSuggestions({
}
getLinkWithPicker(props.providerId, true)
.then(link => {
if (hasMarkdownSyntax(link) && isValidMarkdown(link)) {
const isUrl = isValidUrl(link)
if (!isUrl) {
const isMarkdown = hasMarkdownSyntax(link) && isValidMarkdown(link)
// Insert markdown content (e.g. from `text_templates` app)
const content = markdownit.render(link)
const content = isMarkdown ? markdownit.render(link) : link
editor
.chain()
.focus()
Expand Down