2018-07-15 12:46:29 +02:00
|
|
|
<template>
|
|
|
|
<span class="content">
|
2020-03-21 21:55:36 +01:00
|
|
|
<span class="text"><ParsedMessage :network="network" :text="cleanText" /></span>
|
2018-07-15 12:46:29 +02:00
|
|
|
</span>
|
|
|
|
</template>
|
|
|
|
|
2022-06-19 02:25:21 +02:00
|
|
|
<script lang="ts">
|
|
|
|
import {computed, defineComponent, PropType} from "vue";
|
|
|
|
import {ClientNetwork, ClientMessage} from "../../js/types";
|
2018-07-15 12:46:29 +02:00
|
|
|
import ParsedMessage from "../ParsedMessage.vue";
|
|
|
|
|
2022-06-19 02:25:21 +02:00
|
|
|
export default defineComponent({
|
2020-06-29 09:51:17 +02:00
|
|
|
name: "MessageTypeMonospaceBlock",
|
2018-07-15 12:46:29 +02:00
|
|
|
components: {
|
|
|
|
ParsedMessage,
|
|
|
|
},
|
|
|
|
props: {
|
2022-06-19 02:25:21 +02:00
|
|
|
network: {
|
|
|
|
type: Object as PropType<ClientNetwork>,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
message: {
|
|
|
|
type: Object as PropType<ClientMessage>,
|
|
|
|
required: true,
|
|
|
|
},
|
2018-07-15 12:46:29 +02:00
|
|
|
},
|
2022-06-19 02:25:21 +02:00
|
|
|
setup(props) {
|
|
|
|
const cleanText = computed(() => {
|
|
|
|
let lines = props.message.text.split("\n");
|
2018-07-15 12:46:29 +02:00
|
|
|
|
|
|
|
// If all non-empty lines of the MOTD start with a hyphen (which is common
|
|
|
|
// across MOTDs), remove all the leading hyphens.
|
|
|
|
if (lines.every((line) => line === "" || line[0] === "-")) {
|
2022-06-19 02:25:21 +02:00
|
|
|
lines = lines.map((line) => line.substring(2));
|
2018-07-15 12:46:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove empty lines around the MOTD (but not within it)
|
2018-07-16 21:05:55 +02:00
|
|
|
return lines
|
2019-07-17 11:33:59 +02:00
|
|
|
.map((line) => line.replace(/\s*$/, ""))
|
2018-07-16 21:05:55 +02:00
|
|
|
.join("\n")
|
|
|
|
.replace(/^[\r\n]+|[\r\n]+$/g, "");
|
2022-06-19 02:25:21 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
cleanText,
|
|
|
|
};
|
2018-07-15 12:46:29 +02:00
|
|
|
},
|
2022-06-19 02:25:21 +02:00
|
|
|
});
|
2018-07-15 12:46:29 +02:00
|
|
|
</script>
|