<commit_before>namespace pxt.docs.codeCard {

    const repeat = pxt.Util.repeatMap;

    export interface CodeCardRenderOptions {
        hideHeader?: boolean;
        shortName?: boolean;
    }

    export function render(card: pxt.CodeCard, options: CodeCardRenderOptions = {}): HTMLElement {
        const repeat = pxt.Util.repeatMap;
        let color = card.color || "";
        if (!color) {
            if (card.hardware && !card.software) color = 'black';
            else if (card.software && !card.hardware) color = 'teal';
        }
        const url = card.url ? /^[^:]+:\/\//.test(card.url) ? card.url : ('/' + card.url.replace(/^\.?\/?/, ''))
            : undefined;
        const link = !!url;
        const div = (parent: HTMLElement, cls: string, tag = "div", text: string | number = ''): HTMLElement => {
            let d = document.createElement(tag);
            if (cls)
                d.className = cls;
            if (parent) parent.appendChild(d);
            if (text) d.appendChild(document.createTextNode(text + ''));
            return d;
        }
        const a = (parent: HTMLElement, href: string, text: string, cls: string): HTMLAnchorElement => {
            let d = document.createElement('a');
            d.className = cls;
            d.href = href;
            d.appendChild(document.createTextNode(text));
            d.target = '_blank';
            parent.appendChild(d);
            return d;
        }

        let r = div(null, 'ui card ' + (card.color || '') + (link ? ' link' : ''), link ? "a" : "div");

        r.setAttribute("role", "option");
        r.setAttribute("aria-selected", "true");

        if (url) (r as HTMLAnchorElement).href = url;
        if (!options.hideHeader && (card.header || card.blocks || card.javascript || card.hardware || card.software || card.any)) {
            let h = div(r, "ui content " + (card.responsive ? " tall desktop only" : ""));
            let hr = div(h, "right floated meta")
            if (card.any) div(hr, "ui grey circular label tiny", "i", card.any > 0 ? card.any : "");<commit_msg>Auto link youtube vids in cards from id (#5274)<commit_after>namespace pxt.docs.codeCard {

    const repeat = pxt.Util.repeatMap;

    export interface CodeCardRenderOptions {
        hideHeader?: boolean;
        shortName?: boolean;
    }

    export function render(card: pxt.CodeCard, options: CodeCardRenderOptions = {}): HTMLElement {
        const repeat = pxt.Util.repeatMap;
        let color = card.color || "";
        if (!color) {
            if (card.hardware && !card.software) color = 'black';
            else if (card.software && !card.hardware) color = 'teal';
        }
        const url = card.url ? /^[^:]+:\/\//.test(card.url) ? card.url : ('/' + card.url.replace(/^\.?\/?/, ''))
            : card.youTubeId ? `https://www.youtube.com/watch?v=${card.youTubeId}` : undefined;
        const link = !!url;
        const div = (parent: HTMLElement, cls: string, tag = "div", text: string | number = ''): HTMLElement => {
            let d = document.createElement(tag);
            if (cls)
                d.className = cls;
            if (parent) parent.appendChild(d);
            if (text) d.appendChild(document.createTextNode(text + ''));
            return d;
        }
        const a = (parent: HTMLElement, href: string, text: string, cls: string): HTMLAnchorElement => {
            let d = document.createElement('a');
            d.className = cls;
            d.href = href;
            d.appendChild(document.createTextNode(text));
            d.target = '_blank';
            parent.appendChild(d);
            return d;
        }

        let r = div(null, 'ui card ' + (card.color || '') + (link ? ' link' : ''), link ? "a" : "div");

        r.setAttribute("role", "option");
        r.setAttribute("aria-selected", "true");

        if (url) (r as HTMLAnchorElement).href = url;
        if (!options.hideHeader && (card.header || card.blocks || card.javascript || card.hardware || card.software || card.any)) {
            let h = div(r, "ui content " + (card.responsive ? " tall desktop only" : ""));
            let hr = div(h, "right floated meta")
            if (card.any) div(hr, "ui grey circular label tiny", "i", card.any > 0 ? card.any : "");
{'fraction_non_alphanumeric': 0.16250291851505955, 'fraction_numerical': 0.0014008872285780996, 'mean_word_length': 2.0998552821997105, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4013871', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1256, 'n_words': 320}