Skip to content

Commit

Permalink
style: prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
sifferhans committed Nov 21, 2024
1 parent a31aabc commit 33f807b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
2 changes: 1 addition & 1 deletion components/I18nText.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const translation = computed(() => {
const properties = text.matchAll(/<(\w*)>/g);
return {
text: text.split(/<\w*>/),
properties: properties.toArray().map((x) => x[1]),
properties: Array.from(properties).map((x) => x[1]),
};
});
</script>
Expand Down
54 changes: 29 additions & 25 deletions utils/lyricsEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,40 @@ import type { LyricsVerse } from "@bcc-code/bmm-sdk-fetch";
import { stripHtml } from "string-strip-html";

export function lyricsVersesFromHtml(_html: string) {
const verseStrings = _html
.replaceAll("<h3>", "\n<h3>")
.split("\n")
.filter(Boolean);
const verseObjects = verseStrings
.filter((verseString) => verseString !== "<p></p>")
.map((verseString) => {
const title = verseString.match(/<h3>(.*?)<\/h3>/)?.[1];
const text = verseString
.replaceAll(/<h3>(.*?)<\/h3>/g, "")
.split("</p><p>")
.join("\n")
.replaceAll(/<[^>]*>/g, "");
const verseStrings = _html
.replaceAll("<h3>", "\n<h3>")
.split("\n")
.filter(Boolean);
const verseObjects = verseStrings
.filter((verseString) => verseString !== "<p></p>")
.map((verseString) => {
const title = verseString.match(/<h3>(.*?)<\/h3>/)?.[1];
const text = verseString
.replaceAll(/<h3>(.*?)<\/h3>/g, "")
.split("</p><p>")
.join("\n")
.replaceAll(/<[^>]*>/g, "");

Check failure

Code scanning / CodeQL

Incomplete multi-character sanitization High

This string may still contain
<script
, which may cause an HTML element injection vulnerability.

return { title, text };
});
return { title, text };
});

return verseObjects
return verseObjects;
}

export function lyricsVersesToHtml(verses: LyricsVerse[]) {
return verses.map((verse) => {
const title = verse.title ? `<h3>${verse.title}</h3>` : ''
const text = verse.text ? `<p>${verse.text.split('\n').join('</p><p>')}</p>` : ''
return `${title}${text}`
}).join('')
return verses
.map((verse) => {
const title = verse.title ? `<h3>${verse.title}</h3>` : "";
const text = verse.text
? `<p>${verse.text.split("\n").join("</p><p>")}</p>`
: "";
return `${title}${text}`;
})
.join("");
}

export function lyricsCleanupHtml(html: string) {
return stripHtml(html, {
ignoreTags: ['h3', 'p'],
}).result
}
return stripHtml(html, {
ignoreTags: ["h3", "p"],
}).result;
}

0 comments on commit 33f807b

Please sign in to comment.