'<strong>$1</strong>')
          .replace(/\*(.*?)\*(?=([^`]*`[^`]*`)*[^`]*$)/g, '<em>$1</em>')
          .replace(/_(.*?)_(?=([^`]*`[^`]*`)*[^`]*$)/g, '<em>$1</em>')
          .replace(/```.*?\n([\s\S]*?)```/g, '<pre><code>$1</code></pre>')
          .replace(/`(.*?)`/g, '<code>$1</code>')
          .replace(/\n/gim, '<br />');
        } else { // inside code block
          chunks[i] = `<pre><code>${chunks[i]}</code></pre>`;
        }
      }

      const restoredText = chunks.join('');

    