Skip to content

Instantly share code, notes, and snippets.

@albannurkollari
Created March 25, 2023 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save albannurkollari/84d34ae91eef82a8f16d334618a1f1d0 to your computer and use it in GitHub Desktop.
Save albannurkollari/84d34ae91eef82a8f16d334618a1f1d0 to your computer and use it in GitHub Desktop.
e2e-filters-with-unified-plugins-pr-body-parser
import { unified } from 'unified';
import remarkParse from 'remark-parse';
import remarkGfm from 'remark-gfm';
import remarkRehype from 'remark-rehype';
import rehypeFormat from 'rehype-format';
import rehypeStringify from 'rehype-stringify';
import rehypeRaw from 'rehype-raw';
import { load as cheerioLoad } from 'cheerio';
(async () => {
const { process: parser } = unified()
.use(remarkParse)
.use(remarkRehype, { allowDangerousHtml: true })
.use(rehypeRaw)
.use(remarkGfm)
.use(rehypeFormat)
.use(rehypeStringify);
const file = await gh().then(parser);
const $ = cheerioLoad(file.value);
const detailsNodes = $('#e2e-filters').children(
'details:has(input[checked])'
);
const env = [...detailsNodes].reduce((acc, detail) => {
const { id } = detail.attribs;
const checkboxes = [...$(`#${id} input[checked]`)];
const values = checkboxes.map(({ nextSibling: ns }: any) =>
ns?.nodeValue.trim()
);
return { ...acc, [id]: values.join(':') };
}, {});
console.log(env);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment