```coffeescript
###
# Highlight is a named function that will highlight ``` messages
# @param {Object} message - The message object
###

class Highlight

	# If message starts with ```, replace it for text formatting
	constructor: (message) ->

		if _.trim message.html
			# Separate text in code blocks and non code blocks
			msgParts = message.html.split(/(```.*\n[\s\S]*?\n```)/)

			for part, index in msgParts
				# Verify if this part is code
				codeMatch = part.match(/```(.*)\n([\s\S]*?)\n```/)
				if codeMatch?
					# Process highlight if this part is code
					lang = codeMatch[1]
					code = _.unescapeHTML codeMatch[2]
					if lang not in hljs.listLanguages()
						result = hljs.highlightAuto code
					else
						result = hljs.highlight lang, code
					msgParts[index] = "<pre><code class='hljs " + result.language + "'><span class='copyonly'>```<br></span>" + result.value + "<span class='copyonly'><br>```</span></code></pre>"
				else
					# Escape html and fix line breaks for non code blocks
					msgParts[index] = part

			# Re-mount message
			message.html = msgParts.join('')

		return message

RocketChat.callbacks.add 'renderMessage', Highlight, RocketChat.callbacks.priority.HIGH
```

Make the pre-formatted code regular expression a lot more permissive
user
```coffeescript
###
# Highlight is a named function that will highlight ``` messages
# @param {Object} message - The message object
###

class Highlight

	constructor: (message) ->

		if _.trim message.html

			# Count occurencies of ```
			count = (message.html.match(/```/g) || []).length

			if count

				# Check if we need to add a final ```
				if (count % 2 > 0)
					console.log "Even"
					message.html = message.html + "\n```"
					message.msg = message.msg + "\n```"

				# Separate text in code blocks and non code blocks
				msgParts = message.html.split(/(```\w*[\n\ ]?[\s\S]*?```+?)/)

				for part, index in msgParts
					# Verify if this part is code
					codeMatch = part.match(/```(\w*)[\n\ ]?([\s\S]*?)```+?/)
					if codeMatch?
						# Process highlight if this part is code
						lang = codeMatch[1]
						code = _.unescapeHTML codeMatch[2]
						if lang not in hljs.listLanguages()
							result = hljs.highlightAuto code
						else
							result = hljs.highlight lang, code
						msgParts[index] = "<pre><code class='hljs " + result.language + "'><span class='copyonly'>```<br></span>" + result.value + "<span class='copyonly'><br>```</span></code></pre>"
					else
						msgParts[index] = part

				# Re-mount message
				message.html = msgParts.join('')

		return message

RocketChat.callbacks.add 'renderMessage', Highlight, RocketChat.callbacks.priority.HIGH
```
assistant