From 63ed015a86249f63ca46bf1798d04e59b474949a Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 7 Apr 2022 17:33:15 -0700 Subject: [PATCH] fix: Loosen italic markdown matching a little see: https://github.com/outline/outline/discussions/3336 --- shared/editor/marks/Italic.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) 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), ]; }