0

我使用 pug 作为模板引擎。

我可以在我的页面上加载内容。按照我的一些代码片段:

服务器.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

期望的结果

第一段三字加粗

第二款一字加粗。

第 3 款第 1至第 4 个单词应加粗。

等等

哈巴狗和我的方法有没有办法将任意选择的单词设置为粗体?我的在线搜索仍然没有结果。我怎样才能做到这一点?

4

1 回答 1

1

我找到了我的工作解决方案。致我所关心的人:

服务器.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);
}

重要的是`。不要与 '. 模板文字仅适用于反引号

intro_page.pug

div
    div= !{explanation}
于 2019-09-16T07:00:37.020 回答