瀏覽代碼

refac: rich text input behaviour

Timothy J. Baek 6 月之前
父節點
當前提交
4c691c0edb
共有 1 個文件被更改,包括 3 次插入2 次删除
  1. 3 2
      src/lib/components/common/RichTextInput.svelte

+ 3 - 2
src/lib/components/common/RichTextInput.svelte

@@ -168,11 +168,12 @@
 	}
 	}
 
 
 	function boldRule(schema) {
 	function boldRule(schema) {
-		return markInputRule(/\*([^*]+)\*/, schema.marks.strong);
+		return markInputRule(/(?<=^|\s)\*([^*]+)\*(?=\s|$)/, schema.marks.strong);
 	}
 	}
 
 
 	function italicRule(schema) {
 	function italicRule(schema) {
-		return markInputRule(/\_([^*]+)\_/, schema.marks.em);
+		// Using lookbehind and lookahead to prevent the space from being consumed
+		return markInputRule(/(?<=^|\s)_([^*_]+)_(?=\s|$)/, schema.marks.em);
 	}
 	}
 
 
 	// Initialize Editor State and View
 	// Initialize Editor State and View