2016-11-25 37 views
0

我正在使用parsedown和codeigniter。在我的textarea上,如果我添加了一些空行,它们不会在预览中显示出来。它只是增加了在预览框中一个\n使用parsedown和codeigniter不显示空的换行符

正如这个图片注意图所示:预览图像

enter image description here

底框,你可以在机顶盒是一个textarea看到。最后一行之前有一个很大的差距。它没有显示在预览? 如果我试着和BR或nlbr更换换行符这对parsedown缩进代码

问题用笨和parsedown我怎么能保证我 从控制器,该会表现出相同的ammount的回声它线。

脚本

<script type="text/javascript"> 
$(document).ready(function() { 
    $('#editor').on('paste cut mouseup mousedown mouseout keydown keyup', function(){ 
     var postData = { 
      'html' : $('#editor').val(), 
     }; 
     $.ajax({ 
      type: "POST", 
      url: "<?php echo base_url('example/preview');?>", 
      data: postData, 
      dataType: 'json', 
      success: function(json){ 
       $('#output').html(json['output']); 
      } 
     }); 
    }); 
}); 
</script> 

控制器

<?php 

class Example extends CI_Controller { 

public function __construct() { 
    parent::__construct(); 
    $this->load->library('parsedown'); 
} 

public function index() 
{ 
    $this->load->view('example_view'); 
} 

public function preview() { 
    $data['success'] = false; 
    $data['output'] = ''; 

    if ($this->input->post('html')) { 
     $data['success'] = true; 
     // Using br or nlbr effect the code indents so can not use it. 
     $data['output'] = str_replace('\n', '<br/>', $this->parsedown->text($this->input->post('html'))); 
    } 

    echo json_encode($data); 
} 

回答

0

您需要使用双断标签来创建一个空行。

Something on this line 
<br><br> 
This line has a blank line above it. 

你可以工作,什么是需要一个以上的空行。

请在http://parsedown.org/demo上试试。

+0

我不想为textarea上的每一个新行添加
我希望php能够做到这一点。我也尝试过str_replace中的
,但不能用于parsedown – user4419336

+0

那么当你将它发送到parsedown,那么你翻译\ n或\ r \ n - 两个测试 - 并添加
就像nl2br()一样... – TimBrownlaw

+0

这会影响到什么时候有预标签等将不得不寻找其他的东西 – user4419336