import { isWordCharacter } from '@admin/utils/editor/is-word-character' export function matchMarkdownMarkSyntax(markdown: string, index: number): number | null { const character = markdown[index] const nextCharacter = markdown[index + 1] const previousCharacter = markdown[index - 1] if (character === '`') { const match = /^`+/.exec(markdown.slice(index)) return match ? index + match[0].length : null } if (character === '*' || character === '~') { const match = new RegExp(`^\\${character}+`).exec(markdown.slice(index)) return match ? index + Math.min(match[0].length, 2) : null } if ( character === '_' && !(isWordCharacter(previousCharacter) && isWordCharacter(nextCharacter)) ) { const match = /^_+/.exec(markdown.slice(index)) return match ? index + Math.min(match[0].length, 2) : null } return null }