0
我正在使用parsedown和codeigniter。在我的textarea上,如果我添加了一些空行,它們不會在預覽中顯示出來。它只是增加了在預覽框中一個\n
使用parsedown和codeigniter不顯示空的換行符
正如這個圖片注意圖所示:預覽圖像
底框,你可以在機頂盒是一個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);
}
我不想爲textarea上的每一個新行添加
我希望php能夠做到這一點。我也嘗試過str_replace中的
,但不能用於parsedown – user4419336
那麼當你將它發送到parsedown,那麼你翻譯\ n或\ r \ n - 兩個測試 - 並添加
就像nl2br()一樣... – TimBrownlaw
這會影響到什麼時候有預標籤等將不得不尋找其他的東西 – user4419336