Auto-applied inline tools #2078
Unanswered
fynnfeldpausch
asked this question in
Q&A
Replies: 1 comment
-
I gave up trying to cause this in real-time, but instead applied it after blur or save() ... it's too hard to manage the cursor when injecting a bunch of html, like <a>, etc. Here's my code. In my case, I want to convert #hashtags and @mentions to bsky.social links. Hope it helps. document.querySelectorAll(".ce-paragraph").forEach((el) => {
const textOnly = Array.from(el.childNodes)
.filter((node) => node.nodeType === Node.TEXT_NODE)
.map((node) => node.textContent)
.join(" ")
const urls = textOnly.match(
/https?\:\/\/[\w\-._~!$&()*+,;=:@\/?]+/g
)
const hashtags = textOnly.match(/#(\w+)/g)
const mentions = textOnly.match(/@([\w.]+)/g)
let html = el.innerHTML
log({
processHashTags: el.textContent,
textOnly,
el,
html,
urls,
hashtags,
mentions,
})
urls?.forEach((url) => {
html = html.replace(
url,
`<a target="_blank" href="${url}">${url}</a>`
)
})
hashtags?.forEach((hashtag) => {
const href = `https://bsky.app/hashtag/${hashtag.slice(1)}`
html = html.replace(
hashtag,
`<a class="hashtag" target="_blank" href="${href}">${hashtag}</a>`
)
})
mentions?.forEach((mention) => {
const href = `https://bsky.app/profile/${mention.slice(1)}`
html = html.replace(
mention,
`<a class="hashtag" target="_blank" href="${href}">${mention}</a>`
)
})
if (html !== el.innerHTML) {
log({processHashTags: el.innerHTML, html})
el.innerHTML = html
}
}) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Is there a way to auto-convert user input at the time of writing without using the inline toolbar but rather by listening to the user input. Let me give you a few examples to make things clearer:
I do not want to add an inline tool to provide a button to trigger those use cases. I want to automatically apply / trigger them while the user is creating input.
Any help is appreciated.
Beta Was this translation helpful? Give feedback.
All reactions