forked from MapComplete/MapComplete
chore: improve script to extract questionhints
This commit is contained in:
parent
35d12a653d
commit
12ac229d1b
2 changed files with 25 additions and 14 deletions
|
@ -613,20 +613,21 @@ class MiscTagRenderingChecks extends DesugaringStep<TagRenderingConfigJson> {
|
|||
new TypedTranslation(json["question"]),
|
||||
context + ".question"
|
||||
)
|
||||
const html = question.ConstructElement()
|
||||
for (const lng of question.SupportedLanguages()) {
|
||||
const html = document.createElement("p")
|
||||
html.innerHTML = question.textFor(lng)
|
||||
const divs = Array.from(html.getElementsByTagName("div"))
|
||||
const spans = Array.from(html.getElementsByTagName("span"))
|
||||
const brs = Array.from(html.getElementsByTagName("br"))
|
||||
const subtles = Array.from(html.getElementsByClassName("subtle"))
|
||||
if (divs.length + spans.length + brs.length + subtles.length > 0) {
|
||||
warnings.push(
|
||||
"At " +
|
||||
context +
|
||||
": the question contains a div, a span, a br or an element with class 'subtle'. Please, use a `questionHint` instead.\n The question is: " +
|
||||
question.textFor("en")
|
||||
`At ${context}: the question for ${lng} contains a div, a span, a br or an element with class 'subtle'. Please, use a \`questionHint\` instead.
|
||||
The question is: ${question.textFor(lng)}`
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
result: json,
|
||||
errors,
|
||||
|
|
|
@ -37,10 +37,20 @@ class ExtractQuestionHint extends DesugaringStep<QuestionableTagRenderingConfigJ
|
|||
const hint: Record<string, string> = {}
|
||||
|
||||
for (const language in json.question) {
|
||||
const parts = json.question[language].split(/<br ?\/>/i)
|
||||
const q = json.question[language]
|
||||
const parts = q.split(/<br ?\/>/i)
|
||||
if (parts.length == 2) {
|
||||
json.question[language] = parts[0]
|
||||
hint[language] = new FixedUiElement(parts[1]).ConstructElement().textContent
|
||||
continue
|
||||
}
|
||||
|
||||
const divStart = q.indexOf("<div")
|
||||
if (divStart > 0) {
|
||||
json.question[language] = q.substring(0, divStart)
|
||||
hint[language] = new FixedUiElement(
|
||||
q.substring(divStart)
|
||||
).ConstructElement().textContent
|
||||
}
|
||||
}
|
||||
if (Object.keys(hint).length > 0) {
|
||||
|
@ -83,7 +93,7 @@ class FixQuestionHint extends Script {
|
|||
}
|
||||
const layers: LayerConfigJson[] = contents["layers"] ?? [contents]
|
||||
for (const layer of layers) {
|
||||
for (let i = 0; i < layer.tagRenderings.length; i++) {
|
||||
for (let i = 0; i < layer.tagRenderings?.length; i++) {
|
||||
const tagRendering = layer.tagRenderings[i]
|
||||
if (typeof tagRendering !== "object" || tagRendering["question"] === undefined) {
|
||||
continue
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue