feat: support legend options (#292)

This commit is contained in:
YangFong 2024-04-28 20:55:59 +08:00 committed by GitHub
parent 97f42c9d0d
commit ed951d293b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 68 additions and 2 deletions

View File

@ -88,6 +88,33 @@ export default {
desc: `dark`, desc: `dark`,
}, },
], ],
legendOption: [
{
label: `title 优先`,
value: `title-alt`,
desc: ``,
},
{
label: `alt 优先`,
value: `alt-title`,
desc: ``,
},
{
label: `只显示 title`,
value: `title`,
desc: ``,
},
{
label: `只显示 alt`,
value: `alt`,
desc: ``,
},
{
label: `不显示`,
value: `none`,
desc: ``,
},
],
form: { form: {
rows: 1, rows: 1,
cols: 1, cols: 1,

View File

@ -175,8 +175,22 @@ class WxRenderer {
return `<figcaption ${getStyles("figcaption")}>${s}</figcaption>`; return `<figcaption ${getStyles("figcaption")}>${s}</figcaption>`;
}; };
const transform = (title, alt) => {
const subText = createSubText(title || text); const legend = localStorage.getItem("legend");
switch (legend) {
case "alt":
return alt;
case "title":
return title;
case "alt-title":
return alt || title;
case "title-alt":
return title || alt;
default:
return "";
}
};
const subText = createSubText(transform(title, text));
const figureStyles = getStyles("figure"); const figureStyles = getStyles("figure");
const imgStyles = getStyles("image"); const imgStyles = getStyles("image");
return `<figure ${figureStyles}><img ${imgStyles} src="${href}" title="${title}" alt="${text}"/>${subText}</figure>`; return `<figure ${figureStyles}><img ${imgStyles} src="${href}" title="${title}" alt="${text}"/>${subText}</figure>`;

View File

@ -110,6 +110,14 @@
:charge="codeThemeChanged" :charge="codeThemeChanged"
></style-option-menu> ></style-option-menu>
</el-dropdown-item> </el-dropdown-item>
<el-dropdown-item class="padding-left-3">
<style-option-menu
label="图注格式"
:options="config.legendOption"
:current="selectLegend"
:charge="legendChanged"
></style-option-menu>
</el-dropdown-item>
<el-dropdown-item <el-dropdown-item
divided divided
class="padding-left-3" class="padding-left-3"
@ -201,6 +209,7 @@ export default {
selectSize: ``, selectSize: ``,
selectColor: ``, selectColor: ``,
selectCodeTheme: config.codeThemeOption[2].value, selectCodeTheme: config.codeThemeOption[2].value,
selectLegend: ``,
form: { form: {
dialogVisible: false, dialogVisible: false,
title: ``, title: ``,
@ -254,6 +263,7 @@ export default {
currentSize: (state) => state.currentSize, currentSize: (state) => state.currentSize,
currentColor: (state) => state.currentColor, currentColor: (state) => state.currentColor,
codeTheme: (state) => state.codeTheme, codeTheme: (state) => state.codeTheme,
legend: (state) => state.legend,
nightMode: (state) => state.nightMode, nightMode: (state) => state.nightMode,
currentCiteStatus: (state) => state.citeStatus, currentCiteStatus: (state) => state.citeStatus,
currentIsMacCodeBlock: (state) => state.isMacCodeBlock, currentIsMacCodeBlock: (state) => state.isMacCodeBlock,
@ -332,6 +342,11 @@ export default {
this.selectCodeTheme = theme this.selectCodeTheme = theme
this.$emit(`refresh`) this.$emit(`refresh`)
}, },
legendChanged(legend) {
this.setCurrentLegend(legend)
this.selectLegend = legend
this.$emit(`refresh`)
},
statusChanged() { statusChanged() {
this.citeStatus = !this.citeStatus this.citeStatus = !this.citeStatus
this.setCiteStatus(this.citeStatus) this.setCiteStatus(this.citeStatus)
@ -420,6 +435,7 @@ export default {
this.colorChanged(this.config.colorOption[0].value) this.colorChanged(this.config.colorOption[0].value)
this.sizeChanged(this.config.sizeOption[2].value) this.sizeChanged(this.config.sizeOption[2].value)
this.codeThemeChanged(this.config.codeThemeOption[2].value) this.codeThemeChanged(this.config.codeThemeOption[2].value)
this.legendChanged(this.config.legendOption[3].value)
this.$emit(`cssChanged`) this.$emit(`cssChanged`)
this.selectFont = this.currentFont this.selectFont = this.currentFont
this.selectSize = this.currentSize this.selectSize = this.currentSize
@ -441,6 +457,7 @@ export default {
`setCurrentSize`, `setCurrentSize`,
`setCssEditorValue`, `setCssEditorValue`,
`setCurrentCodeTheme`, `setCurrentCodeTheme`,
`setCurrentLegend`,
`setWxRendererOptions`, `setWxRendererOptions`,
`setIsMacCodeBlock`, `setIsMacCodeBlock`,
`setIsEditOnLeft`, `setIsEditOnLeft`,
@ -451,6 +468,7 @@ export default {
this.selectSize = this.currentSize this.selectSize = this.currentSize
this.selectColor = this.currentColor this.selectColor = this.currentColor
this.selectCodeTheme = this.codeTheme this.selectCodeTheme = this.codeTheme
this.selectLegend = this.legend
this.citeStatus = this.currentCiteStatus this.citeStatus = this.currentCiteStatus
this.isMacCodeBlock = this.currentIsMacCodeBlock this.isMacCodeBlock = this.currentIsMacCodeBlock
this.isEditOnLeft = this.currentIsEditOnLeft this.isEditOnLeft = this.currentIsEditOnLeft

View File

@ -25,6 +25,7 @@ export const useStore = defineStore(`store`, {
citeStatus: false, citeStatus: false,
nightMode: false, nightMode: false,
codeTheme: config.codeThemeOption[2].value, codeTheme: config.codeThemeOption[2].value,
legend: config.legendOption[3].value,
isMacCodeBlock: true, isMacCodeBlock: true,
isEditOnLeft: true, isEditOnLeft: true,
}), }),
@ -58,6 +59,10 @@ export const useStore = defineStore(`store`, {
this.codeTheme = data this.codeTheme = data
localStorage.setItem(`codeTheme`, data) localStorage.setItem(`codeTheme`, data)
}, },
setCurrentLegend(data) {
this.legend = data
localStorage.setItem(`legend`, data)
},
setIsMacCodeBlock(data) { setIsMacCodeBlock(data) {
this.isMacCodeBlock = data this.isMacCodeBlock = data
localStorage.setItem(`isMacCodeBlock`, data) localStorage.setItem(`isMacCodeBlock`, data)
@ -79,6 +84,8 @@ export const useStore = defineStore(`store`, {
localStorage.getItem(`size`) || config.sizeOption[2].value localStorage.getItem(`size`) || config.sizeOption[2].value
this.codeTheme = this.codeTheme =
localStorage.getItem(`codeTheme`) || config.codeThemeOption[2].value localStorage.getItem(`codeTheme`) || config.codeThemeOption[2].value
this.legend =
localStorage.getItem(`legend`) || config.legendOption[3].value
this.citeStatus = localStorage.getItem(`citeStatus`) === `true` this.citeStatus = localStorage.getItem(`citeStatus`) === `true`
this.nightMode = localStorage.getItem(`nightMode`) === `true` this.nightMode = localStorage.getItem(`nightMode`) === `true`
this.isMacCodeBlock = !( this.isMacCodeBlock = !(