diff --git a/shared/editor/marks/Italic.ts b/shared/editor/marks/Italic.ts index 51ee3d1a7..4a361c7b1 100644 --- a/shared/editor/marks/Italic.ts +++ b/shared/editor/marks/Italic.ts @@ -25,9 +25,29 @@ export default class Italic extends Mark { } inputRules({ type }: { type: MarkType }): InputRule[] { + /** + * Due to use of snake_case strings common in docs the matching conditions + * are a bit more strict than e.g. the ** bold syntax to help prevent + * false positives. + * + * Matches: + * _1_ + * _123_ + * (_one_ + * [_one_ + * + * No match: + * __ + * __123_ + * __123__ + * _123 + * one_123_ + * ONE_123_ + * 1_123_ + */ return [ - markInputRule(/(?:^|[\s])(_([^_]+)_)$/, type), - markInputRule(/(?:^|[^*])(\*([^*]+)\*)$/, type), + markInputRule(/(?<=[^_\na-zA-Z0-9]|^)_([^_\n]+)_$/, type), + markInputRule(/(?<=[^*\na-zA-Z0-9]|^)\*([^*\n]+)\*$/, type), ]; }