feat(frontend): add fork awesome linter

This linter will tell users that their fork awesome icon is deprecated and will stop working in the future and that they should replace it with a new bootstrap icon.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2023-01-15 19:32:15 +01:00
parent eacd81cb9c
commit e2c4e2eccf
4 changed files with 44 additions and 12 deletions

View file

@ -222,7 +222,8 @@
"sequence": "The use of 'sequence' as code block language is deprecated and will be removed in a future release.",
"shortcode": "The {{shortcode}} short-code is deprecated and will be removed in a future release. Use a single line URL instead.",
"frontmatter": "The yaml-metadata is invalid.",
"frontmatter-tags": "The comma-separated definition of tags in the yaml-metadata is deprecated. Use a yaml-array instead."
"frontmatter-tags": "The comma-separated definition of tags in the yaml-metadata is deprecated. Use a yaml-array instead.",
"fork-awesome": "Fork Awesome is deprecated and will be removed in future release. Please use the new bootstrap icons instead. See {{link}} for more information."
},
"upload": {
"uploadFile": {

View file

@ -1,10 +1,10 @@
/*
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import type { Linter } from './linter'
import type { Diagnostic } from '@codemirror/lint'
import type { Action, Diagnostic } from '@codemirror/lint'
import type { EditorView } from '@codemirror/view'
import { t } from 'i18next'
@ -25,7 +25,7 @@ export class SingleLineRegexLinter implements Linter {
constructor(
private regex: RegExp,
private message: string,
private replace: (match: string) => string,
private replace?: (match: string) => string,
private actionLabel?: string
) {}
@ -52,11 +52,10 @@ export class SingleLineRegexLinter implements Linter {
}
private createDiagnostic(from: number, found: RegExpExecArray): Diagnostic {
const replacedText = this.replace(found[1])
return {
from: from,
to: from + found[0].length,
actions: [
let actions: Action[] = []
if (this.replace !== undefined) {
const replacedText = this.replace(found[1])
actions = [
{
name: t(this.actionLabel ?? 'editor.linter.defaultAction'),
apply: (view: EditorView, from: number, to: number) => {
@ -65,7 +64,12 @@ export class SingleLineRegexLinter implements Linter {
})
}
}
],
]
}
return {
from: from,
to: from + found[0].length,
actions: actions,
message: this.message,
severity: 'warning'
}

View file

@ -0,0 +1,25 @@
/*
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import type { Linter } from '../../../components/editor-page/editor-pane/linter/linter'
import { SingleLineRegexLinter } from '../../../components/editor-page/editor-pane/linter/single-line-regex-linter'
import { AppExtension } from '../../base/app-extension'
import { t } from 'i18next'
export const forkAwesomeRegex = /<i class=["']fa fa-[\w-]+["'](?: aria-hidden=["']true["'])?\/?>(?:<\/i>)?/
/**
* Adds support for flow charts to the markdown rendering.
*/
export class ForkAwesomeAppExtension extends AppExtension {
buildCodeMirrorLinter(): Linter[] {
return [
new SingleLineRegexLinter(
forkAwesomeRegex,
t('editor.linter.fork-awesome', { link: 'https://docs.hedgedoc.org' }) // ToDo: Add correct link here
)
]
}
}

View file

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
@ -9,6 +9,7 @@ import { AlertAppExtension } from './alert/alert-app-extension'
import { BlockquoteAppExtension } from './blockquote/blockquote-app-extension'
import { CsvTableAppExtension } from './csv/csv-table-app-extension'
import { FlowchartAppExtension } from './flowchart/flowchart-app-extension'
import { ForkAwesomeAppExtension } from './fork-awesome/fork-awesome-app-extension'
import { GistAppExtension } from './gist/gist-app-extension'
import { GraphvizAppExtension } from './graphviz/graphviz-app-extension'
import { HighlightedCodeFenceAppExtension } from './highlighted-code-fence/highlighted-code-fence-app-extension'
@ -44,5 +45,6 @@ export const optionalAppExtensions: AppExtension[] = [
new VimeoAppExtension(),
new YoutubeAppExtension(),
new TaskListCheckboxAppExtension(),
new HighlightedCodeFenceAppExtension()
new HighlightedCodeFenceAppExtension(),
new ForkAwesomeAppExtension()
]