Skip to content

Commit

Permalink
lib(get-hml): remove all other classes than the ones we want to keep
Browse files Browse the repository at this point in the history
Co-authored-by: Oscar Dominguez <dominguez.celada@gmail.com>
  • Loading branch information
wolfy1339 and oscard0m committed Jun 26, 2022
1 parent 8ae222d commit 71528ff
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/get-html.ts
Expand Up @@ -31,9 +31,20 @@ export const getHtml = async (
$('[data-testid="callout"]').remove();
const data = $("#article-contents").parent().parent();
data.find("*").each((i, el) => {
const classes = $(el).attr("class") ?? "";
if (!classes.includes("language-json") && !classes.includes("warning")) {
$(el).removeAttr("class");
const classes = $(el).attr("class");

if (classes) {
const filteredClasses = classes
.split(" ")
.filter((classSelector) =>
["language-json", "warning"].includes(classSelector)
);

if (filteredClasses.length) {
$(el).attr("class", filteredClasses.join(" "));
} else {
$(el).removeAttr("class");
}
}
});
const html = data.html() ?? "";
Expand Down

0 comments on commit 71528ff

Please sign in to comment.