From 15f192447b858ef530291683535e43a9cca2468c Mon Sep 17 00:00:00 2001 From: Keegan George Date: Wed, 5 Oct 2022 10:33:08 -0700 Subject: [PATCH] FIX: Ability to trigger emoji after indented code block (#18478) --- .../discourse/app/lib/utilities.js | 22 +++++++++---------- .../tests/unit/lib/utilities-test.js | 11 +++++++--- 2 files changed, 19 insertions(+), 14 deletions(-) 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 + /^( |\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 = /`[^`]+|^```[^]*?|\[code\][^]*?/gm; +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) => {