如何用哈巴狗将句子中的某些单词设为粗体/强壮?

时间:2019-09-12 06:28:03

标签: javascript node.js pug jade4j

我将哈巴狗用作模板引擎。

我可以在页面上加载内容。遵循我的代码片段:

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

希望的结果

第一段的第三个字应为粗体。

第2款中的一词和一词应为粗体。

第3款中最多1个四个词应为粗体。

以此类推

哈巴狗和我的方法是否可以将任意选择的单词设置为粗体?我的在线搜索仍然没有结果。我该怎么办?

1 个答案:

答案 0 :(得分:0)

我找到了可行的解决方案。我关心谁:

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);
}

重要的是`。不要与'混淆。模板文字仅适用于back ticks

intro_page.pug

div
    div= !{explanation}