chore: lint and fmt
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
export const decodeBase64ToUTF8 = (content: string): string => {
|
||||
return decodeURIComponent(
|
||||
atob(content)
|
||||
.split('')
|
||||
.map((char) => `%${('00' + char.charCodeAt(0).toString(16)).slice(-2)}`)
|
||||
.join('')
|
||||
.split("")
|
||||
.map((char) => `%${("00" + char.charCodeAt(0).toString(16)).slice(-2)}`)
|
||||
.join("")
|
||||
)
|
||||
}
|
||||
export const encodeUTF8ToBase64 = (content: string): string => {
|
||||
|
||||
@@ -6,7 +6,7 @@ export const displayLanguage = (langCode?: string): string | null => {
|
||||
try {
|
||||
const locale = navigator.language ?? langCode
|
||||
const display = new Intl.DisplayNames([locale], {
|
||||
type: "language",
|
||||
type: "language"
|
||||
})
|
||||
|
||||
return display.of(langCode) ?? null
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
// We can only detect video/audio files from the extension in the URL.
|
||||
// We ignore MP1 and MP2 (not in active use) and default to video for ambiguous
|
||||
|
||||
import MarkdownIt from 'markdown-it'
|
||||
import MarkdownIt from "markdown-it"
|
||||
|
||||
// extensions (MPG, MP4)
|
||||
const validAudioExtensions = ['aac', 'm4a', 'mp3', 'oga', 'ogg', 'wav']
|
||||
const validVideoExtensions = ['mp4', 'm4v', 'ogv', 'webm', 'mpg', 'mpeg']
|
||||
const validAudioExtensions = ["aac", "m4a", "mp3", "oga", "ogg", "wav"]
|
||||
const validVideoExtensions = ["mp4", "m4v", "ogv", "webm", "mpg", "mpeg"]
|
||||
|
||||
/**
|
||||
* @property {Object} messages
|
||||
@@ -19,13 +19,13 @@ const validVideoExtensions = ['mp4', 'm4v', 'ogv', 'webm', 'mpg', 'mpeg']
|
||||
*/
|
||||
let messages: { [key: string]: any } = {
|
||||
en: {
|
||||
'html5 video not supported':
|
||||
'Your browser does not support playing HTML5 video.',
|
||||
'html5 audio not supported':
|
||||
'Your browser does not support playing HTML5 audio.',
|
||||
'html5 media fallback link':
|
||||
"html5 video not supported":
|
||||
"Your browser does not support playing HTML5 video.",
|
||||
"html5 audio not supported":
|
||||
"Your browser does not support playing HTML5 audio.",
|
||||
"html5 media fallback link":
|
||||
'You can <a href="%s" download>download the file</a> instead.',
|
||||
'html5 media description': 'Here is a description of the content: %s'
|
||||
"html5 media description": "Here is a description of the content: %s"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,18 +37,18 @@ let translate = (
|
||||
// Revert back to English default if no message object, or no translation
|
||||
// for this language
|
||||
if (!messages[language] || !messages[language][messageKey]) {
|
||||
language = 'en'
|
||||
language = "en"
|
||||
}
|
||||
|
||||
if (!messages[language]) {
|
||||
return ''
|
||||
return ""
|
||||
}
|
||||
|
||||
let message = messages[language][messageKey] || ''
|
||||
let message = messages[language][messageKey] || ""
|
||||
|
||||
if (messageParams)
|
||||
for (const param of messageParams) {
|
||||
message = message.replace('%s', param)
|
||||
message = message.replace("%s", param)
|
||||
}
|
||||
|
||||
return message
|
||||
@@ -96,7 +96,7 @@ function tokenizeImagesAndMedia(
|
||||
}
|
||||
): boolean {
|
||||
let attrs, code, label, pos, ref, res, title, tokens: never[], start
|
||||
let href = ''
|
||||
let href = ""
|
||||
const oldPos = state.pos
|
||||
const max = state.posMax
|
||||
|
||||
@@ -140,7 +140,7 @@ function tokenizeImagesAndMedia(
|
||||
if (state.md.validateLink(href)) {
|
||||
pos = res.pos
|
||||
} else {
|
||||
href = ''
|
||||
href = ""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ function tokenizeImagesAndMedia(
|
||||
if (!md.utils.isSpace(code) && code !== 0x0a) break
|
||||
}
|
||||
} else {
|
||||
title = ''
|
||||
title = ""
|
||||
}
|
||||
|
||||
if (pos >= max || state.src.charCodeAt(pos) !== 0x29) {
|
||||
@@ -179,7 +179,7 @@ function tokenizeImagesAndMedia(
|
||||
//
|
||||
// Link reference
|
||||
//
|
||||
if (typeof state.env.references === 'undefined') return false
|
||||
if (typeof state.env.references === "undefined") return false
|
||||
|
||||
if (pos < max && state.src.charCodeAt(pos) === 0x5b) {
|
||||
// Bracket: [
|
||||
@@ -219,15 +219,15 @@ function tokenizeImagesAndMedia(
|
||||
state.md.inline.parse(content, state.md, state.env, (tokens = []))
|
||||
|
||||
const mediaType = guessMediaType(href)
|
||||
const tag = mediaType == 'image' ? 'img' : mediaType
|
||||
const tag = mediaType == "image" ? "img" : mediaType
|
||||
|
||||
const token = state.push(mediaType, tag, 0)
|
||||
token.attrs = attrs = [['src', href]]
|
||||
if (mediaType == 'image') attrs.push(['alt', ''])
|
||||
token.attrs = attrs = [["src", href]]
|
||||
if (mediaType == "image") attrs.push(["alt", ""])
|
||||
token.children = tokens
|
||||
token.content = content
|
||||
|
||||
if (title) attrs.push(['title', title])
|
||||
if (title) attrs.push(["title", title])
|
||||
|
||||
state.pos = pos
|
||||
state.posMax = max
|
||||
@@ -247,13 +247,13 @@ function tokenizeImagesAndMedia(
|
||||
*/
|
||||
function guessMediaType(url: string): string {
|
||||
const extensionMatch = url.match(/\.([^/.]+)$/)
|
||||
if (extensionMatch === null) return 'image'
|
||||
if (extensionMatch === null) return "image"
|
||||
const extension = extensionMatch[1]
|
||||
if (validAudioExtensions.indexOf(extension.toLowerCase()) != -1)
|
||||
return 'audio'
|
||||
return "audio"
|
||||
else if (validVideoExtensions.indexOf(extension.toLowerCase()) != -1)
|
||||
return 'video'
|
||||
else return 'image'
|
||||
return "video"
|
||||
else return "image"
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -283,37 +283,37 @@ function renderMedia(
|
||||
const token = tokens[idx]
|
||||
const type = token.type
|
||||
|
||||
if (!token.attrs || (type !== 'video' && type !== 'audio')) {
|
||||
return ''
|
||||
if (!token.attrs || (type !== "video" && type !== "audio")) {
|
||||
return ""
|
||||
}
|
||||
|
||||
let attrs = options.html5Media[`${type}Attrs`].trim()
|
||||
if (attrs) {
|
||||
attrs = ' ' + attrs
|
||||
attrs = " " + attrs
|
||||
}
|
||||
|
||||
// We'll always have a URL for non-image media: they are detected by URL
|
||||
const url = token.attrs[token.attrIndex('src')][1]
|
||||
const url = token.attrs[token.attrIndex("src")][1]
|
||||
|
||||
// Title is set like this: 
|
||||
const title =
|
||||
token.attrIndex('title') != -1
|
||||
token.attrIndex("title") != -1
|
||||
? ` title="${md.utils.escapeHtml(
|
||||
token.attrs[token.attrIndex('title')][1]
|
||||
token.attrs[token.attrIndex("title")][1]
|
||||
)}"`
|
||||
: ''
|
||||
: ""
|
||||
|
||||
const fallbackText =
|
||||
translate(env.language, `html5 ${type} not supported`) +
|
||||
'\n' +
|
||||
translate(env.language, 'html5 media fallback link', [url])
|
||||
"\n" +
|
||||
translate(env.language, "html5 media fallback link", [url])
|
||||
|
||||
const description = token.content
|
||||
? '\n' +
|
||||
translate(env.language, 'html5 media description', [
|
||||
? "\n" +
|
||||
translate(env.language, "html5 media description", [
|
||||
md.utils.escapeHtml(token.content)
|
||||
])
|
||||
: ''
|
||||
: ""
|
||||
|
||||
return (
|
||||
`<${type} src="${url}"${title}${attrs}>\n` +
|
||||
@@ -369,7 +369,7 @@ export const html5Media = (
|
||||
? options.audioAttrs
|
||||
: 'controls class="html5-audio-player"'
|
||||
|
||||
md.inline.ruler.at('image', (tokens: any, silent: any) =>
|
||||
md.inline.ruler.at("image", (tokens: any, silent: any) =>
|
||||
tokenizeImagesAndMedia(tokens, silent, md)
|
||||
)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import MarkdownIt, { PluginSimple } from 'markdown-it'
|
||||
import MarkdownIt, { PluginSimple } from "markdown-it"
|
||||
|
||||
let counter = 0
|
||||
|
||||
@@ -6,14 +6,14 @@ export const markdownItPlugin = (
|
||||
regex: RegExp,
|
||||
replacer: (matches: RegExpExecArray[]) => string
|
||||
): PluginSimple => {
|
||||
const id = 'regexp-' + counter
|
||||
const id = "regexp-" + counter
|
||||
counter++
|
||||
const flags =
|
||||
(regex.global ? 'g' : '') +
|
||||
(regex.multiline ? 'm' : '') +
|
||||
(regex.ignoreCase ? 'i' : '')
|
||||
(regex.global ? "g" : "") +
|
||||
(regex.multiline ? "m" : "") +
|
||||
(regex.ignoreCase ? "i" : "")
|
||||
|
||||
const regexp = RegExp('^' + regex.source, flags)
|
||||
const regexp = RegExp("^" + regex.source, flags)
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const parse = (state: any, silent: boolean): boolean => {
|
||||
@@ -31,7 +31,7 @@ export const markdownItPlugin = (
|
||||
return true
|
||||
}
|
||||
|
||||
const token = state.push(id, '', 0)
|
||||
const token = state.push(id, "", 0)
|
||||
token.meta = { match }
|
||||
|
||||
return true
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import { markdownItPlugin } from "./markdown-it-regexp"
|
||||
|
||||
// Matches :icon-name: where icon-name is letters, digits, hyphens
|
||||
export const markdownItTablerIcons = markdownItPlugin(
|
||||
/:([\w-]+):/,
|
||||
(match) => {
|
||||
const name = match[1]
|
||||
return `<i class="ti ti-${name}"></i>`
|
||||
},
|
||||
)
|
||||
export const markdownItTablerIcons = markdownItPlugin(/:([\w-]+):/, (match) => {
|
||||
const name = match[1]
|
||||
return `<i class="ti ti-${name}"></i>`
|
||||
})
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
export const filenameToNoteTitle = (title: string) =>
|
||||
title.replaceAll('/', ' / ').replaceAll('-', ' ')
|
||||
title.replaceAll("/", " / ").replaceAll("-", " ")
|
||||
|
||||
export const pathToNotePathTitle = (path: string) => {
|
||||
const fileNames = path.split('.')
|
||||
const fileNames = path.split(".")
|
||||
|
||||
fileNames.pop()
|
||||
return fileNames
|
||||
.join('.')
|
||||
.split('/')
|
||||
.filter((path) => !path.includes('README'))
|
||||
.join('/')
|
||||
.replaceAll('-', ' ')
|
||||
.join(".")
|
||||
.split("/")
|
||||
.filter((path) => !path.includes("README"))
|
||||
.join("/")
|
||||
.replaceAll("-", " ")
|
||||
}
|
||||
|
||||
export const pathToNoteTitle = (notePathTitle: string) => {
|
||||
return pathToNotePathTitle(notePathTitle).split('/').pop()?.trim() ?? ''
|
||||
return pathToNotePathTitle(notePathTitle).split("/").pop()?.trim() ?? ""
|
||||
}
|
||||
|
||||
@@ -4,23 +4,23 @@ const notif = new Notyf({
|
||||
types: [
|
||||
{
|
||||
className: "alert alert-success",
|
||||
type: "confirm",
|
||||
type: "confirm"
|
||||
},
|
||||
{
|
||||
className: "alert alert-error",
|
||||
type: "error",
|
||||
},
|
||||
],
|
||||
type: "error"
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
export const confirmMessage = (message: string) =>
|
||||
notif.open({
|
||||
type: "confirm",
|
||||
message,
|
||||
message
|
||||
})
|
||||
|
||||
export const errorMessage = (message: string) =>
|
||||
notif.open({
|
||||
type: "error",
|
||||
message,
|
||||
message
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user