mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-06-08 02:15:02 -04:00
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: 2020 The HedgeDoc developers (see AUTHORS file)
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import { Editor, Hint, Hints, Pos } from 'codemirror'
|
|
import { findWordAtCursor, Hinter } from './index'
|
|
|
|
const wordRegExp = /^:::((\w|-|_|\+)*)$/
|
|
const allSupportedConatiner = ['success', 'info', 'warning', 'danger']
|
|
|
|
const containerHint = (editor: Editor): Promise< Hints| null > => {
|
|
return new Promise((resolve) => {
|
|
const searchTerm = findWordAtCursor(editor)
|
|
const searchResult = wordRegExp.exec(searchTerm.text)
|
|
if (searchResult === null) {
|
|
resolve(null)
|
|
return
|
|
}
|
|
const suggestions = allSupportedConatiner
|
|
const cursor = editor.getCursor()
|
|
if (!suggestions) {
|
|
resolve(null)
|
|
} else {
|
|
resolve({
|
|
list: suggestions.map((suggestion: string): Hint => ({
|
|
text: ':::' + suggestion + '\n\n:::\n',
|
|
displayText: suggestion
|
|
})),
|
|
from: Pos(cursor.line, searchTerm.start),
|
|
to: Pos(cursor.line, searchTerm.end)
|
|
})
|
|
}
|
|
})
|
|
}
|
|
|
|
export const ContainerHinter: Hinter = {
|
|
wordRegExp,
|
|
hint: containerHint
|
|
}
|