Skip to content

Commit

Permalink
feat(editor): visualize links
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed Oct 7, 2021
1 parent 8f5867d commit 9db93fb
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/use/raw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ export const italic: Callback<any> = () => {
return { open, close }
}

export const link: Callback<any> = () => {
const open = (tag: string) => {
return `<a href="${tag}" target="_blank" class="underline text-xs">`
}

const close = () => {
return ' </a>'
}

return { open, close }
}

export const useRaw: Callback<any> = () => {
const convert = (page: ContextStatePageContent) => {
let final = ''
Expand All @@ -35,8 +47,21 @@ export const useRaw: Callback<any> = () => {

if (page.type !== 'paragraph') return page.raw

for (let i = 0; i < page.raw.length; i++) {
const letter = page.raw.charAt(i)
const over: Array<string> = []

let _raw = page.raw

page.raw.split(/[ ,]+/).forEach((word: string) => {
console.log(word)
if (word.includes('http')) over.push(word)
})

over.forEach((word: string) => {
_raw = _raw.replace(word, `${link().open(word)}${word}${link().close()}`)
})

for (let i = 0; i < _raw.length; i++) {
const letter = _raw.charAt(i)

if (letter === '*' && !_italic) {
_italic = true
Expand Down

0 comments on commit 9db93fb

Please sign in to comment.