来自数据库的数据显示在网页上,带有html标签而不是格式化文本

时间:2017-10-14 17:29:33

标签: javascript html node.js mongodb ckeditor

使用Express,MongoDB,Pug和CKEditor的Node.js应用程序4.问题是:我尝试将数据从编辑器提交到数据库中,然后在网页上显示它们。数据看起来像带有html标签的纯文本,而不是编辑器中看到的带格式的文本。

我的问题是:为什么数据无法正常显示以及如何解决此问题?

图片1 - 提交前格式化

Formatting before submit

图片2 - 网页上数据库中的数据

Rendered data from DB

网页来源:

extends layout

block content
  h1.page-header= article.title
  h5 Written by #{author}
  p= article.body

代码片段:

1)article.pug

extends layout

block content
  h1.page-header #{title}
  form(method='POST' action='/articles/add')
    #form-group
      label Title:
      input.form-control(name='title' type='text')
    #form-group
      label Body:
      textarea.form-control(name='body' id='editor')
    br
    input.btn.btn-primary(type='submit' value='Submit')

2)add_article.pug

CKEDITOR.replace('editor')

3)main.js

    section .data
Msg1: db 'Masukkan nama Anda ',0xa
Msg1ln equ $-Msg1

Name: db ' ', 0xa               ; space characters

msg_done: db 'File telah dibuat ', 0xa
;msg_doneln equ $-msg_done


section .text
   global _start         

_start:                  

   ; Output  'Masukkan nama Anda '
mov eax, 4              ; write…
mov ebx, 1              ; to the standard output (screen/console)…
mov ecx, Msg1           ; the information at memory address prompt
mov edx, Msg1ln         ; 19 bytes (characters) of that information
int 0x80                ; invoke an interrupt

; Accept input and store the user’s name
mov eax, 3              ; read…
mov ebx, 1              ; from the standard input (keyboard/console)…
mov ecx, Name               ; storing at memory location name…
mov edx, 23                 ; 23 bytes (characters) is ok for my name
int 0x80

   ;create the file
   mov  eax, 8
   mov  ebx, Name
   mov  ecx, 0777        ;read, write and execute by all
   int  0x80             ;call kernel

   mov [fd_out], eax

    ;write the message indicating end of file write
   mov eax, 4
   mov ebx, 1
   mov ecx, msg_done
   mov edx, 18
   int  0x80

   mov  [fd_in], eax


   mov  eax,1             ;system call number (sys_exit)
   int  0x80              ;call kernel

section .bss
fd_out resb 1
fd_in  resb 1

1 个答案:

答案 0 :(得分:1)

默认情况下,Pug中的HTML会被转义。您需要在var f = new FontFace('Font name', 'url(/path/to/font.ttf)'); f.load().then(function() { // Ready to use the font in a canvas context console.log('font ready'); ctx.font = '48px Font name'; ctx.strokeText('Hello world', 100, 100); }); 中包含内容以使其无法转义。在此处查看更多信息:https://pugjs.org/language/interpolation.html#string-interpolation-unescaped

请注意,渲染未转义的HTML可能会带来安全风险。