sync: Import labels of Label flags as Markdown

This commit is contained in:
nemunaire 2022-12-07 14:43:44 +01:00
parent 7edbd0f9de
commit baa410e654
2 changed files with 22 additions and 1 deletions

View file

@ -102,6 +102,23 @@ func buildLabelFlag(exercice *fic.Exercice, flag ExerciceFlag, flagline int, exc
return
}
// Call checks hooks
for _, h := range hooks.mdTextHooks {
for _, err := range h(flag.Label, exceptions.Filter2ndCol(strconv.Itoa(flagline))) {
errs = append(errs, NewFlagError(exercice, &flag, flagline, err))
}
}
if mdlabel, err := ProcessMarkdown(GlobalImporter, flag.Label, exercice.Path); err != nil {
errs = append(errs, NewFlagError(exercice, &flag, flagline, fmt.Errorf("unable to parse property label as Markdown: %w", err)))
} else {
if strings.Count(flag.Label, "\n\n") == 0 {
flag.Label = mdlabel[3 : len(mdlabel)-4]
} else {
flag.Label = mdlabel
}
}
if flag.Raw != nil {
errs = append(errs, NewFlagError(exercice, &flag, flagline, fmt.Errorf("raw cannot be defined.")))
}
@ -110,6 +127,10 @@ func buildLabelFlag(exercice *fic.Exercice, flag ExerciceFlag, flagline int, exc
errs = append(errs, NewFlagError(exercice, &flag, flagline, fmt.Errorf("choices cannot be defined.")))
}
if len(flag.Label) > 255 {
errs = append(errs, NewFlagError(exercice, &flag, flagline, fmt.Errorf("label is too long (max 255 chars per label).")))
}
f = &fic.FlagLabel{
Order: int8(flagline),
Label: flag.Label,

View file

@ -200,7 +200,7 @@
{#each flags as flag ((flag.type?flag.type:"i") + flag.id)}
{#if !flag.type && !flag.id}
<div class="form-group mb-3">
<label class="{flag.variant?('text-'+flag.variant):''}">{flag.label}</label>
<label class="{flag.variant?('text-'+flag.variant):''}">{@html flag.label}</label>
</div>
{:else if flag.type == "mcq"}
<FlagMCQ