feat: editor script setup
This commit is contained in:
@ -8,33 +8,34 @@ export function setupMarkdownRenderer(checkboxId: string) {
|
||||
let checkboxNum = -1
|
||||
marked.use({
|
||||
renderer: {
|
||||
image: (src, title, text) => {
|
||||
image(src: string, title: string, text: string) {
|
||||
|
||||
title = title ? ` title="${title}` : ''
|
||||
|
||||
// If the url starts with the api url, the image is likely an attachment and
|
||||
// we'll need to download and parse it properly.
|
||||
if (src.substr(0, window.API_URL.length + 7) === `${window.API_URL}/tasks/`) {
|
||||
if (src.slice(0, window.API_URL.length + 7) === `${window.API_URL}/tasks/`) {
|
||||
return `<img data-src="${src}" alt="${text}" ${title} class="attachment-image"/>`
|
||||
}
|
||||
|
||||
return `<img src="${src}" alt="${text}" ${title}/>`
|
||||
},
|
||||
checkbox: (checked) => {
|
||||
checkbox(checked: boolean) {
|
||||
let checkedString = ''
|
||||
if (checked) {
|
||||
checked = ' checked="checked"'
|
||||
checkedString = 'checked'
|
||||
}
|
||||
|
||||
checkboxNum++
|
||||
return `<input type="checkbox" data-checkbox-num="${checkboxNum}" ${checked} class="text-checkbox-${checkboxId}"/>`
|
||||
return `<input type="checkbox" data-checkbox-num="${checkboxNum}" ${checkedString} class="text-checkbox-${checkboxId}"/>`
|
||||
},
|
||||
link: (href, title, text) => {
|
||||
link(href: string, title: string, text: string) {
|
||||
const isLocal = href.startsWith(`${location.protocol}//${location.hostname}`)
|
||||
const html = linkRenderer.call(renderer, href, title, text)
|
||||
return isLocal ? html : html.replace(/^<a /, '<a target="_blank" rel="noreferrer noopener nofollow" ')
|
||||
},
|
||||
},
|
||||
highlight: function (code, language) {
|
||||
highlight(code, language) {
|
||||
const validLanguage = hljs.getLanguage(language) ? language : 'plaintext'
|
||||
return hljs.highlight(code, {language: validLanguage}).value
|
||||
},
|
||||
|
@ -1,5 +1,5 @@
|
||||
const DEFAULT_ID_LENGTH = 9
|
||||
|
||||
export function createRandomID(idLength = DEFAULT_ID_LENGTH) {
|
||||
return Math.random().toString(36).substr(2, idLength)
|
||||
return Math.random().toString(36).slice(2, idLength)
|
||||
}
|
@ -285,7 +285,7 @@ const getDateFromWeekday = (text: string): dateFoundResult => {
|
||||
// matched string comes with a space at the end (last part of the regex).
|
||||
let foundText = results[0]
|
||||
if (foundText.endsWith(' ')) {
|
||||
foundText = foundText.substr(0, foundText.length - 1)
|
||||
foundText = foundText.slice(0, foundText.length - 1)
|
||||
}
|
||||
|
||||
return {
|
||||
|
Reference in New Issue
Block a user