Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert item.title with html tags to html #232

Open
dogia opened this issue Aug 25, 2022 · 0 comments
Open

Convert item.title with html tags to html #232

dogia opened this issue Aug 25, 2022 · 0 comments

Comments

@dogia
Copy link

dogia commented Aug 25, 2022

I have desingned if helps a function that convert an item with html subtags to html

use: extract(item.title);

function extract(item, tag = '') {
    if(typeof item === 'object') {
        if(Array.isArray(item)) {
            let content = '';
            for(const i in item) {
                content = `${content} ${extract(item[i], tag)}`;
            }
            while(content[0] === ' ')
                content = content.substring(1);
            return content;
        } else {
            let attr = '';
            let content = '';
            for(const i in item) {
                if(i === '$') {
                    for(const j in item[i]) {
                        const value = item[i][j];
                        attr = `${attr} ${j}="${value}"`;
                    };
                } else if(i === '_') {
                    content = `${content} ${item[i]}`;
                } else {
                    content = `${content} ${extract(item[i], i)}`;
                }
            }
            while(content[0] === ' ')
                content = content.substring(1);
            
            if(tag !== '')
                return `<${tag}${attr}>${content}</${tag}>`;
            else
                return content;
        }
    } else if(typeof item === 'string') {
        if (tag !== '')
            return `<${tag}>${item}</${tag}>`;
        else
            return `${item}`;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant