Fix whitespace, \n delimiters

Bugs remaining:
- [reset to default] and page exit (e.g. save) triggers:
  "500 PUT options. Option 'allowedHtmlTags' is not allowed to be changed"
This commit is contained in:
maphew 2024-11-17 20:30:28 -07:00
parent f3b398570e
commit 8db1205d57

View File

@ -5,16 +5,14 @@ const TPL = `
<div class="options-section"> <div class="options-section">
<h4>${t("import.html_import_tags.title")}</h4> <h4>${t("import.html_import_tags.title")}</h4>
<p class="form-text">${t("import.html_import_tags.description")}</p> <p>${t("import.html_import_tags.description")}</p>
<div class="mb-3">
<textarea class="allowed-html-tags form-control" style="height: 150px; font-family: monospace;" <textarea class="allowed-html-tags form-control" style="height: 150px; font-family: monospace;"
placeholder="${t("import.html_import_tags.placeholder")}"></textarea> placeholder="${t("import.html_import_tags.placeholder")}"></textarea>
<div class="form-text"> <div class="form-text">
${t("import.html_import_tags.help")} ${t("import.html_import_tags.help")}
</div> </div>
</div>
<div> <div>
<button class="btn btn-sm btn-secondary reset-to-default"> <button class="btn btn-sm btn-secondary reset-to-default">
@ -55,22 +53,22 @@ export default class HtmlImportTagsOptions extends OptionsWidget {
try { try {
if (options.allowedHtmlTags) { if (options.allowedHtmlTags) {
const tags = JSON.parse(options.allowedHtmlTags); const tags = JSON.parse(options.allowedHtmlTags);
this.$allowedTags.val(tags.join('\\n')); this.$allowedTags.val(tags.join(' '));
} else { } else {
// If no tags are set, show the defaults // If no tags are set, show the defaults
this.$allowedTags.val(defaultTags.join('\\n')); this.$allowedTags.val(defaultTags.join(' '));
} }
} }
catch (e) { catch (e) {
console.error('Could not load HTML tags:', e); console.error('Could not load HTML tags:', e);
// On error, show the defaults // On error, show the defaults
this.$allowedTags.val(defaultTags.join('\\n')); this.$allowedTags.val(defaultTags.join(' '));
} }
} }
async saveTags() { async saveTags() {
const tagsText = this.$allowedTags.val(); const tagsText = this.$allowedTags.val();
const tags = tagsText.split(/[,\\s]+/) // Split on commas, spaces, or newlines const tags = tagsText.split(/[\n,\s]+/) // Split on newlines, commas, or spaces
.map(tag => tag.trim()) .map(tag => tag.trim())
.filter(tag => tag.length > 0); .filter(tag => tag.length > 0);
@ -78,7 +76,7 @@ export default class HtmlImportTagsOptions extends OptionsWidget {
} }
async resetToDefault() { async resetToDefault() {
this.$allowedTags.val(defaultTags.join('\\n')); // Use actual newlines this.$allowedTags.val(defaultTags.join('\n')); // Use actual newline
await this.saveTags(); await this.saveTags();
} }
} }