0

我正在使用parsedown和 codeigniter。在我的文本区域中,如果我添加了一些空行,它们不会出现在预览中。它只\n在预览框中添加一个

如图所示注意:预览是图像中的底部框

在此处输入图像描述

正如您在顶部框中看到的那样,它是一个文本区域。在最后一行之前有一个很大的差距。它没有在预览中显示?如果我尝试用 br 或 nlbr 替换换行符,它会影响 parsedown 上的缩进代码

使用 codeigniter 和 parsedown 的问题我如何确保当我从控制器回显它时将显示相同数量的行。

脚本

<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);
}
4

1 回答 1

0

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

IE

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

您可以计算出多个空行所需的内容。

在http://parsedown.org/demo中玩一下来测试它。

于 2016-11-25T05:10:08.400 回答