mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-22 01:36:29 -05:00
enhancement(autocomplete): add generic code suggestion entry
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
parent
5ccc9059f0
commit
685488c7a2
1 changed files with 12 additions and 4 deletions
|
@ -10,6 +10,7 @@ import { AppExtension } from '../../_base-classes/app-extension'
|
||||||
import { HighlightedCodeMarkdownExtension } from './highlighted-code-markdown-extension'
|
import { HighlightedCodeMarkdownExtension } from './highlighted-code-markdown-extension'
|
||||||
import type { CompletionContext, CompletionResult, CompletionSource } from '@codemirror/autocomplete'
|
import type { CompletionContext, CompletionResult, CompletionSource } from '@codemirror/autocomplete'
|
||||||
import { languages } from '@codemirror/language-data'
|
import { languages } from '@codemirror/language-data'
|
||||||
|
import { t } from 'i18next'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds code highlighting to the markdown rendering.
|
* Adds code highlighting to the markdown rendering.
|
||||||
|
@ -29,6 +30,16 @@ export class HighlightedCodeFenceAppExtension extends AppExtension {
|
||||||
}
|
}
|
||||||
|
|
||||||
buildAutocompletion(): CompletionSource[] {
|
buildAutocompletion(): CompletionSource[] {
|
||||||
|
const completions = [
|
||||||
|
{
|
||||||
|
detail: t('editor.editorToolbar.code'),
|
||||||
|
label: '```\n\n```'
|
||||||
|
},
|
||||||
|
...languages.map((lang) => ({
|
||||||
|
detail: lang.name,
|
||||||
|
label: '```' + lang.alias[0] + '\n\n```'
|
||||||
|
}))
|
||||||
|
]
|
||||||
return [
|
return [
|
||||||
(context: CompletionContext): CompletionResult | null => {
|
(context: CompletionContext): CompletionResult | null => {
|
||||||
const match = context.matchBefore(codeFenceRegex)
|
const match = context.matchBefore(codeFenceRegex)
|
||||||
|
@ -37,10 +48,7 @@ export class HighlightedCodeFenceAppExtension extends AppExtension {
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
from: match.from,
|
from: match.from,
|
||||||
options: languages.map((lang) => ({
|
options: completions
|
||||||
detail: lang.name,
|
|
||||||
label: '```' + lang.alias[0] + '\n\n```'
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue