mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-24 05:48:59 +08:00
fix(editor): support more divider markdown shortcut (#10139)
This commit is contained in:
@@ -76,10 +76,32 @@ export function substringMatchScore(name: string, query: string) {
|
||||
|
||||
/**
|
||||
* Checks if the prefix is a markdown prefix.
|
||||
* Ex. 1. 2. 3. - * [] [ ] [x] # ## ### #### ##### ###### --- *** > ```
|
||||
* Ex. 1. 2. 3. - * [] [ ] [x] # ## ### #### ##### ###### --- *** ___ > ```
|
||||
*/
|
||||
export function isMarkdownPrefix(prefix: string) {
|
||||
return !!prefix.match(
|
||||
/^(\d+\.|-|\*|\[ ?\]|\[x\]|(#){1,6}|(-){3}|(\*){3}|>|```([a-zA-Z0-9]*))$/
|
||||
return (
|
||||
!!prefix.match(
|
||||
/^(\d+\.|-|\*|\[ ?\]|\[x\]|(#){1,6}|>|```([a-zA-Z0-9]*))$/
|
||||
) || isHorizontalRuleMarkdown(prefix)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the prefix is a valid markdown horizontal rule - https://www.markdownguide.org/basic-syntax/#horizontal-rules
|
||||
* @param prefix - The string to check for horizontal rule syntax
|
||||
* @returns boolean - True if the string represents a valid horizontal rule
|
||||
*
|
||||
* Valid horizontal rules:
|
||||
* - Three or more consecutive hyphens (e.g., "---", "----")
|
||||
* - Three or more consecutive asterisks (e.g., "***", "****")
|
||||
* - Three or more consecutive underscores (e.g., "___", "____")
|
||||
*
|
||||
* Invalid examples:
|
||||
* - Mixed characters (e.g., "--*", "-*-")
|
||||
* - Less than three characters (e.g., "--", "**")
|
||||
*/
|
||||
export function isHorizontalRuleMarkdown(prefix: string) {
|
||||
const horizontalRulePattern = /^(-{3,}|\*{3,}|_{3,})$/;
|
||||
|
||||
return !!prefix.match(horizontalRulePattern);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user