[enh] Add markdown in alert and help

This commit is contained in:
ljf 2021-09-13 01:50:07 +02:00
parent f36d1aca7a
commit b9b0dd906f
3 changed files with 43 additions and 10 deletions

View file

@ -35,8 +35,7 @@
</b-link>
</div>
<div
v-if="description" v-html="description"
<vue-showdown :markdown="description" flavor="github" v-if="description"
:class="{ ['alert p-1 px-2 alert-' + descriptionVariant]: descriptionVariant }"
/>
</template>

View file

@ -1,7 +1,8 @@
<template>
<b-alert :variant="type" show>
<icon :iname="icon_" />
{{ label }}
<vue-showdown :markdown="label" flavor="github"
tag="span" class="markdown" />
</b-alert>
</template>
@ -29,3 +30,12 @@ export default {
}
}
</script>
<style lang="scss">
.icon + span.markdown > *:first-child {
display: inline-block;
}
.alert p:last-child {
margin-bottom: 0;
}
</style>

View file

@ -50,7 +50,7 @@ import evaluate from 'simple-evaluate'
// FIXME needs test and rework
import api, { objectToParams } from '@/api'
import { formatI18nField, formatYunoHostArguments, formatFormData } from '@/helpers/yunohostArguments'
import { formatI18nField, formatYunoHostArguments, formatFormData, pFileReader } from '@/helpers/yunohostArguments'
export default {
name: 'AppConfigPanel',
@ -84,16 +84,40 @@ export default {
isVisible (expression) {
if (!expression) return true
const context = {}
const promises = []
for (const args of Object.values(this.forms)) {
for (const shortname in args) {
if (args[shortname] instanceof File) {
if (expression.includes(shortname)) {
promises.push(pFileReader(args[shortname], context, shortname, false))
}
} else {
context[shortname] = args[shortname]
}
}
try {
return evaluate(context, expression)
} catch (error) {
return true
}
// Allow to use match(var,regexp) function
const matchRe = new RegExp('match\\(\\s*(\\w+)\\s*,\\s*"([^"]+)"\\s*\\)', 'g')
let i = 0
return new Promise((resolve, reject) => {
i = 2
resolve(false)
Promise.all(promises).then((value) => {
for (const matched of expression.matchAll(matchRe)) {
i++
const varName = matched[1] + '__re' + i.toString()
context[varName] = new RegExp(matched[2]).test(context[matched[1]])
expression = expression.replace(matched[0], varName)
}
try {
resolve(evaluate(context, expression))
} catch (error) {
resolve(false)
}
})
})
},
onQueriesResponse (data) {
if (!data.panels || data.panels.length === 0) {