Colubrina/frontend/src/main.js

102 lines
2.8 KiB
JavaScript
Raw Normal View History

2022-06-05 22:58:18 +10:00
import Vue from "vue"
import App from "./App.vue"
import router from "./router"
import store from "./store"
import vuetify from "./plugins/vuetify"
import axios from "axios"
import VueAxios from "vue-axios"
import Toast from "vue-toastification"
import "./assets/styles.css"
import "vue-toastification/dist/index.css"
import "./registerServiceWorker"
import "@mdi/font/css/materialdesignicons.css"
import "./plugins/dayjs"
import SocketIO from "socket.io-client"
import twemoji from "twemoji"
import VueNativeNotification from "vue-native-notification"
2022-07-31 19:53:52 +10:00
import "highlight.js/styles/github.css"
2022-06-05 22:58:18 +10:00
const md = require("markdown-it")({
html: false, // Enable HTML tags in source
xhtmlOut: false, // Use '/' to close single tags (<br />).
2022-07-30 15:14:26 +10:00
breaks: true, // Convert '\n' in paragraphs into <br>
2022-06-05 22:58:18 +10:00
langPrefix: "language-", // CSS language prefix for fenced blocks. Can be
linkify: true, // Autoconvert URL-like text to links
typographer: false,
quotes: "“”‘’",
highlight: function (/*str, lang*/) {
return ""
}
}).disable(["image", "autolink"])
const emoji = require("markdown-it-emoji")
const defaultRender =
md.renderer.rules.link_open ||
function (tokens, idx, options, env, self) {
return self.renderToken(tokens, idx, options)
}
md.use(emoji)
2022-07-31 19:53:52 +10:00
const hljs = require("highlight.js/lib/core")
md.use(require("markdown-it-highlightjs"), { hljs })
2022-06-05 22:58:18 +10:00
md.renderer.rules.emoji = function (token, idx) {
return twemoji.parse(token[idx].content, {
folder: "svg",
ext: ".svg"
})
}
md.renderer.rules.link_open = function (tokens, idx, options, env, self) {
// If you are sure other plugins can't add `target` - drop check below
const aIndex = tokens[idx].attrIndex("target")
if (aIndex < 0) {
tokens[idx].attrPush(["target", "_blank"]) // add new attribute
} else {
tokens[idx].attrs[aIndex][1] = "_blank" // replace value of existing attr
}
// pass token to default renderer.
return defaultRender(tokens, idx, options, env, self)
}
Vue.use(VueNativeNotification, {
requestOnNotify: false
})
Vue.use({
install(Vue) {
2022-08-01 00:15:40 +10:00
Vue.prototype.$socket = SocketIO(
localStorage.getItem("instance") || process.env.VUE_APP_SOCKET_URL,
{
transports: ["websocket", "polling"],
headers: {
Authorization: localStorage.getItem("session")
}
2022-06-05 22:58:18 +10:00
}
2022-08-01 00:15:40 +10:00
)
2022-06-05 22:58:18 +10:00
}
})
Vue.use(require("vue-shortkey"))
Vue.config.productionTip = false
Vue.use(VueAxios, axios)
Vue.use(Toast)
Vue.directive("markdown", {
inserted(el) {
2022-08-02 21:15:16 +10:00
el.innerHTML = md
.render(el.innerHTML)
.replaceAll("&amp;", "&")
.replaceAll("<p>", "<span>")
.replaceAll("</p>", "</span>")
2022-06-05 22:58:18 +10:00
}
})
2022-07-30 17:45:29 +10:00
if (process.env.NODE_ENV === "development") {
console.log("Colubrina is running in development mode.")
Vue.config.performance = true
}
2022-06-05 22:58:18 +10:00
new Vue({
router,
store,
vuetify,
render: (h) => h(App)
}).$mount("#app")