mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-06-07 01:51:36 -04:00
added a spoiler container (#947)
changed toolbar to insert the new spoiler container changed tests accordingly References: https://github.com/markdown-it/markdown-it-container Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
9330adf564
commit
7be64bc582
9 changed files with 60 additions and 18 deletions
|
@ -5,12 +5,20 @@
|
|||
*/
|
||||
|
||||
import { Editor, Hint, Hints, Pos } from 'codemirror'
|
||||
import { validAlertLevels } from '../../../markdown-renderer/markdown-it-plugins/alert-container'
|
||||
import { findWordAtCursor, Hinter } from './index'
|
||||
|
||||
const wordRegExp = /^:::((\w|-|_|\+)*)$/
|
||||
const allSupportedConatiner = ['success', 'info', 'warning', 'danger']
|
||||
const spoilerSuggestion: Hint = {
|
||||
text: ':::spoiler Toggle label\nToggled content\n::: \n',
|
||||
displayText: 'spoiler'
|
||||
}
|
||||
const suggestions = validAlertLevels.map((suggestion: string): Hint => ({
|
||||
text: ':::' + suggestion + '\n\n::: \n',
|
||||
displayText: suggestion
|
||||
})).concat(spoilerSuggestion)
|
||||
|
||||
const containerHint = (editor: Editor): Promise< Hints| null > => {
|
||||
const containerHint = (editor: Editor): Promise<Hints | null> => {
|
||||
return new Promise((resolve) => {
|
||||
const searchTerm = findWordAtCursor(editor)
|
||||
const searchResult = wordRegExp.exec(searchTerm.text)
|
||||
|
@ -18,16 +26,12 @@ const containerHint = (editor: Editor): Promise< Hints| 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
|
||||
})),
|
||||
list: suggestions.filter((suggestion) => suggestion.displayText?.startsWith(searchResult[1])),
|
||||
from: Pos(cursor.line, searchTerm.start),
|
||||
to: Pos(cursor.line, searchTerm.end)
|
||||
})
|
||||
|
|
|
@ -64,5 +64,5 @@ export const allHinters: Hinter[] = [
|
|||
ImageHinter,
|
||||
LinkAndExtraTagHinter,
|
||||
PDFHinter,
|
||||
CollapsableBlockHinter
|
||||
CollapsableBlockHinter,
|
||||
]
|
||||
|
|
|
@ -929,7 +929,7 @@ describe('test collapsable block', () => {
|
|||
listSelections: mockListSelections(cursor, true),
|
||||
getLine: (): string => (textFirstLine),
|
||||
replaceRange: (replacement: string | string[]) => {
|
||||
expect(replacement).toEqual(`${textFirstLine}\n<details>\n <summary>Toggle label</summary>\n Toggled content\n</details>`)
|
||||
expect(replacement).toEqual(`${textFirstLine}\n:::spoiler Toggle label\n Toggled content\n:::`)
|
||||
done()
|
||||
}
|
||||
})
|
||||
|
@ -941,7 +941,7 @@ describe('test collapsable block', () => {
|
|||
getCursor: () => cursor.from,
|
||||
listSelections: mockListSelections(firstLine, false),
|
||||
getLine: (): string => (textFirstLine),
|
||||
replaceRange: expectFromToReplacement(firstLine, `${textFirstLine}\n<details>\n <summary>Toggle label</summary>\n Toggled content\n</details>`, done)
|
||||
replaceRange: expectFromToReplacement(firstLine, `${textFirstLine}\n:::spoiler Toggle label\n Toggled content\n:::`, done)
|
||||
})
|
||||
addCollapsableBlock(editor)
|
||||
})
|
||||
|
@ -952,7 +952,7 @@ describe('test collapsable block', () => {
|
|||
listSelections: mockListSelections(multiline, false),
|
||||
getLine: (): string => '2nd line',
|
||||
replaceRange: (replacement: string | string[]) => {
|
||||
expect(replacement).toEqual('2nd line\n<details>\n <summary>Toggle label</summary>\n Toggled content\n</details>')
|
||||
expect(replacement).toEqual('2nd line\n:::spoiler Toggle label\n Toggled content\n:::')
|
||||
done()
|
||||
}
|
||||
})
|
||||
|
@ -965,7 +965,7 @@ describe('test collapsable block', () => {
|
|||
listSelections: mockListSelections(multilineOffset, false),
|
||||
getLine: (): string => '2nd line',
|
||||
replaceRange: (replacement: string | string[]) => {
|
||||
expect(replacement).toEqual('2nd line\n<details>\n <summary>Toggle label</summary>\n Toggled content\n</details>')
|
||||
expect(replacement).toEqual('2nd line\n:::spoiler Toggle label\n Toggled content\n:::')
|
||||
done()
|
||||
}
|
||||
})
|
||||
|
|
|
@ -28,7 +28,7 @@ export const addTaskList = (editor: Editor): void => createList(editor, () => '-
|
|||
export const addImage = (editor: Editor): void => addLink(editor, '!')
|
||||
|
||||
export const addLine = (editor: Editor): void => changeLines(editor, line => `${line}\n----`)
|
||||
export const addCollapsableBlock = (editor: Editor): void => changeLines(editor, line => `${line}\n<details>\n <summary>Toggle label</summary>\n Toggled content\n</details>`)
|
||||
export const addCollapsableBlock = (editor: Editor): void => changeLines(editor, line => `${line}\n:::spoiler Toggle label\n Toggled content\n:::`)
|
||||
export const addComment = (editor: Editor): void => changeLines(editor, line => `${line}\n> []`)
|
||||
export const addTable = (editor: Editor, rows: number, columns: number): void => {
|
||||
const rowArray = createNumberRangeArray(rows)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue