Interface: Fixes URL message parsing
@@ -209,8 +209,35 @@ export class ChatInput extends Component {
return;
}
let message = [];
- editorMessage.split(' ').map((each) => {
- if (this.isUrl(each)) {
+ let isInCodeBlock = false;
+ let endOfCodeBlock = false;
+ editorMessage.split(/\r?\n/).forEach((line) => {
+ // A line of backticks enters and exits a codeblock
+ if (line.startsWith('```')) {
+ // But we need to check if we've ended a codeblock
+ endOfCodeBlock = isInCodeBlock;
+ isInCodeBlock = (!isInCodeBlock);
+ } else {
+ endOfCodeBlock = false;
+ }
+ if (isInCodeBlock) {
+ message.push(`\n${line}`);
+ } else if (endOfCodeBlock) {
+ message.push(`\n${line}\n`);
+ } else {
+ line.split(/\s/).forEach((str) => {
+ if (
+ (str.startsWith('`') && str !== '`')
+ || (str === '`' && !isInCodeBlock)
+ ) {
+ isInCodeBlock = true;
+ } else if (
+ (str.endsWith('`') && str !== '`')
+ || (str === '`' && isInCodeBlock)
+ ) {
+ isInCodeBlock = false;
+ }
+ if (this.isUrl(str) && !isInCodeBlock) {
if (message.length > 0) {
message = message.join(' ');
message = this.getLetterType(message);
@@ -222,7 +249,7 @@ export class ChatInput extends Component {
);
message = [];
}
- const URL = this.getLetterType(each);
+ const URL = this.getLetterType(str);
props.api.chat.message(
props.station,
`~${window.ship}`,
@@ -230,10 +257,14 @@ export class ChatInput extends Component {
URL
);
} else {
- return message.push(each);
+ message.push(str);
}
});
+ }
+
+ });
+
if (message.length > 0) {
message = message.join(' ');
message = this.getLetterType(message);
