html 在数据库中保留锚标记

whhtz7ly  于 2022-11-27  发布在  其他
关注(0)|答案(1)|浏览(133)

我想在一个数据库中保存一篇文章,在这个例子中是MongoDB,并且isome单词必须链接到另一个页面。
当我将文章提交到EJS模板时,我希望我在写文章时插入的锚标记作为链接而不是纯文本工作,因为它正在发生。
文本示例:

const article = "Stack Overflow and the Stack Exchange network help people find the answers they need, when they need them. Comprising 173 Q&A communities, including **<a** **href='https://stackoverflow.com'>**Stack Overflow**</a>**, over 100 million people visit every month to ask questions, learn, and share technical knowledge. Our products and tools empower people to find what they need to develop technology at work or at home. These products include, Stack Overflow for Teams, Stack Overflow Advertising, Collectives™ on Stack Overflow, and Stack Overflow Talent."

在模板中,p标记将接收文章文本:

<div class="row">
    <div class="col-6">
        <p class="reflexion text-justify text-truncate">
            **<%= posts[0].compose %>**
        </p>
    </div>
</div>

问题是:当从数据库中检索文本并将其提交给模板时,锚标记显示为纯文本而不是链接。

Stack Overflow and the Stack Exchange network help people find the answers they need, when they need them. Comprising 173 Q&A communities, including <ahref='https://stackoverflow.com'>Stack Overflow</a>, over 100 million people visit every month to ask questions, learn, and share technical knowledge. Our products and tools empower people to find what they need to develop technology at work or at home. These products include, Stack Overflow for Teams, Stack Overflow Advertising, Collectives™ on Stack Overflow, and Stack Overflow Talent."

如何从数据库返回文本,以便锚标记显示为链接而不是普通文本?

aor9mmx1

aor9mmx11#

看看EJS homepage,它告诉您:
<%=将值输出到模板中(HTML转义)
由于您希望输出呈现为HTML而不是转义,请查看下一行:
<%-将未转义的值输出到模板中
确保您采取措施保护自己免受cross-side scripting attacks的攻击。

相关问题