Skip to content

A platform for community discussion. Free, open, simple.

FIX: Ability to trigger emoji after indented code block (#18478)

Keegan George15f192447b85
diff --git a/app/assets/javascripts/discourse/app/lib/utilities.js b/app/assets/javascripts/discourse/app/lib/utilities.js
index 9f5b02fac4d..6af92d705af 100644
--- a/app/assets/javascripts/discourse/app/lib/utilities.js
+++ b/app/assets/javascripts/discourse/app/lib/utilities.js
@@ -460,18 +460,18 @@ export function postRNWebviewMessage(prop, value) {
}
const CODE_BLOCKS_REGEX =
- /^( |\t).*|`[^`]+`|^```[^]*?^```|\[code\][^]*?\[\/code\]/gm;
-// | ^ | ^ | ^ | ^ |
-// | | | |
-// | | | code blocks between [code]
-// | | |
-// | | +--- code blocks between three backticks
-// | |
-// | +----- inline code between backticks
-// |
-// +------- paragraphs starting with 4 spaces or tab
-
-const OPEN_CODE_BLOCKS_REGEX = /`[^`]+|^```[^]*?|\[code\][^]*?/gm;
+ /^( |\t).*|`[^`]+`|^```[^]*?^```|\[code\][^]*?\[\/code\]/gm;
+//| ^ | ^ | ^ | ^ |
+// | | | |
+// | | | code blocks between [code]
+// | | |
+// | | +--- code blocks between three backticks
+// | |
+// | +----- inline code between backticks
+// |
+// +------- paragraphs starting with 2 spaces or tab
+
+const OPEN_CODE_BLOCKS_REGEX = /^( |\t).*|`[^`]+|^```[^]*?|\[code\][^]*?/gm;
export function inCodeBlock(text, pos) {
let end = 0;
diff --git a/app/assets/javascripts/discourse/tests/unit/lib/utilities-test.js b/app/assets/javascripts/discourse/tests/unit/lib/utilities-test.js
index c2b0c40dd86..2aa232f678d 100644
--- a/app/assets/javascripts/discourse/tests/unit/lib/utilities-test.js
+++ b/app/assets/javascripts/discourse/tests/unit/lib/utilities-test.js
@@ -271,18 +271,23 @@ discourseModule("Unit | Utilities", function () {
test("inCodeBlock", function (assert) {
const texts = [
- // closed code blocks
+ // CLOSED CODE BLOCKS:
"000\n\n 111\n\n000",
"000 `111` 000",
"000\n```\n111\n```\n000",
"000\n[code]111[/code]\n000",
- // open code blocks
+ // OPEN CODE BLOCKS:
"000\n\n 111",
"000 `111",
"000\n```\n111",
"000\n[code]111",
- // complex test
+ // COMPLEX TEST:
"000\n\n```\n111\n```\n\n000\n\n`111 111`\n\n000\n\n[code]\n111\n[/code]\n\n 111\n\t111\n\n000`111",
+ // INDENTED OPEN CODE BLOCKS:
+ // - Using tab
+ "000\n\t```111\n\t111\n\t111```\n000",
+ // - Using spaces
+ `000\n \`\`\`111\n 111\n 111\`\`\`\n000`,
];
texts.forEach((text) => {