Skip to content

Commit

Permalink
Merge pull request #22 from The-3Labs-Team/21-tiny-cross-link-aggiung…
Browse files Browse the repository at this point in the history
…ere-link-al-testo-selezionato-553

Refactor searchPublicApi.js to handle selected text as title if avail…
  • Loading branch information
Claudio-Emmolo authored Jan 2, 2024
2 parents 37e2d7e + 36f6c41 commit 6f47671
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/searchPublicApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,18 @@ function addArticleLinkOnEditor () {
form.addEventListener('submit', (e) => {
e.preventDefault()
const formDataArticle = new FormData(form)
const title = formDataArticle.get('title')

let title = formDataArticle.get('title')
const url = formDataArticle.get('url')

const selectedText = tinymce.activeEditor.selection.getContent()

if (selectedText.length > 0) {
title = selectedText
}

const content = `<a href="${url}" target="_blank">${title}</a>`

tinymce.activeEditor.insertContent(content)
tinymce.activeEditor.windowManager.close()
})
Expand Down

0 comments on commit 6f47671

Please sign in to comment.