2018-11-16 09:31:25 +00:00
|
|
|
<template>
|
2023-04-08 00:01:42 +00:00
|
|
|
<div v-if="block" v-html="compiledFormula"></div>
|
|
|
|
<span v-else v-html="compiledFormula"></span>
|
2018-11-16 09:31:25 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2023-04-08 00:01:42 +00:00
|
|
|
import { defineComponent } from "vue";
|
|
|
|
import katex from "katex";
|
2020-10-17 11:12:00 +00:00
|
|
|
|
|
|
|
export default defineComponent({
|
2018-11-16 09:31:25 +00:00
|
|
|
props: {
|
|
|
|
formula: {
|
|
|
|
type: String,
|
2023-04-08 00:01:42 +00:00
|
|
|
required: true,
|
2019-01-25 14:08:06 +00:00
|
|
|
},
|
|
|
|
block: {
|
|
|
|
type: Boolean,
|
2023-04-08 00:01:42 +00:00
|
|
|
required: true,
|
|
|
|
},
|
2018-11-16 09:31:25 +00:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
compiledFormula(): any {
|
fix: centering block math (#9946)
Similar to `inlineCode` and `blockCode`, MFM provides two types of formula syntax, `mathInline` and `mathBlock` (I'm curious why these aren't called `inlineMath`/`blockMath`, but oh well)
Other platforms, like GitHub, **Math**todon, my blog, etc., also support these two types of formula representation, and math blocks are centered on (maybe) all such platforms.
![](https://cdn.discordapp.com/attachments/823878222897741868/1101837026304720997/2023-04-29_201943.png)
But Calckey (Misskey v12) don't center math blocks. I'd say this is a bug, and this makes `blockMath` useless (it's just `inlineMath` in a new line).
![](https://cdn.discordapp.com/attachments/823878222897741868/1101837026027917342/2023-04-29_202008.png)
So I fixed this.
![](https://cdn.discordapp.com/attachments/823878222897741868/1101837183574355978/2023-04-29_202854.png)
Co-authored-by: naskya <m@naskya.net>
Reviewed-on: https://codeberg.org/calckey/calckey/pulls/9946
Co-authored-by: naskya <naskya@noreply.codeberg.org>
Co-committed-by: naskya <naskya@noreply.codeberg.org>
2023-04-29 14:01:24 +00:00
|
|
|
const katexString = katex.renderToString(this.formula, {
|
2023-04-08 00:01:42 +00:00
|
|
|
throwOnError: false,
|
2018-12-27 12:07:44 +00:00
|
|
|
} as any);
|
fix: centering block math (#9946)
Similar to `inlineCode` and `blockCode`, MFM provides two types of formula syntax, `mathInline` and `mathBlock` (I'm curious why these aren't called `inlineMath`/`blockMath`, but oh well)
Other platforms, like GitHub, **Math**todon, my blog, etc., also support these two types of formula representation, and math blocks are centered on (maybe) all such platforms.
![](https://cdn.discordapp.com/attachments/823878222897741868/1101837026304720997/2023-04-29_201943.png)
But Calckey (Misskey v12) don't center math blocks. I'd say this is a bug, and this makes `blockMath` useless (it's just `inlineMath` in a new line).
![](https://cdn.discordapp.com/attachments/823878222897741868/1101837026027917342/2023-04-29_202008.png)
So I fixed this.
![](https://cdn.discordapp.com/attachments/823878222897741868/1101837183574355978/2023-04-29_202854.png)
Co-authored-by: naskya <m@naskya.net>
Reviewed-on: https://codeberg.org/calckey/calckey/pulls/9946
Co-authored-by: naskya <naskya@noreply.codeberg.org>
Co-committed-by: naskya <naskya@noreply.codeberg.org>
2023-04-29 14:01:24 +00:00
|
|
|
return this.block
|
|
|
|
? `<div style="text-align:center">${katexString}</div>`
|
|
|
|
: katexString;
|
2023-04-08 00:01:42 +00:00
|
|
|
},
|
|
|
|
},
|
2018-11-16 09:31:25 +00:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
2021-11-11 17:02:25 +00:00
|
|
|
@import "../../node_modules/katex/dist/katex.min.css";
|
2018-11-16 09:31:25 +00:00
|
|
|
</style>
|