How to set some words of a sentence bold / strong with pug?

1k Views Asked by At

I use pug as a templating engine.

I'm able to load content on my page. Following some snippets of my code:

server.js

routing.get('/introduction', (req, resp) => {

    loadContent( function(err, content){

        if(content){
            resp.render('intro_page', content);
        }
    });
});


function loadContent( cb ){
    const cont = {
        explanation: ['Word three of paragraph one shall be bold. ', 'Words one and five of paragraph 2 shall be bold.', 'Words one up to four of paragraph 3 shall be bold.', 'and so on'],
    };

    return cb(null, cont);
}

intro_page.pug

div
    each paragraph in explanation
        div= paragraph

wished result

Word three of paragraph one shall be bold.

Words one and five of paragraph 2 shall be bold.

Words one up to four of paragraph 3 shall be bold.

and so on

Is there a way with the pug and my approach to set arbitrarily selected words bold? My online search stilled without result. How can I do this?

1

There are 1 best solutions below

0
On

I have found my working solution. To whom it my concern:

server.js

routing.get('/introduction', (req, resp) => {

    loadContent( function(err, content){

        if(content){
            resp.render('intro_page', content);
        }
    });
});


function loadContent( cb ){
    const bo = '<span style="font-weight: bold">';
    const bc = '</span>';
    const bk = '<br/><br/>';
    const cont = {
        explanation: [`Word three ${bo} of ${bc} paragraph one shall be bold. ${bo} Words ${bc} one and five ${bo} of ${bc} paragraph 2 shall be bold. ${bo} Words one up to ${bc} four of paragraph 3 shall be bold. ${bk} and so on`],
    };

    return cb(null, cont);
}

Important are the `. Not to be confused with '. Template literals only work with back ticks.

intro_page.pug

div
    div= !{explanation}