【问题标题】:Empty newlines not show up on preview using parsedown and codeigniter使用 parsedown 和 codeigniter 在预览中不显示空换行符
【发布时间】:2017-04-09 10:20:24
【问题描述】:

我正在使用 parsedown 和 codeigniter。在我的 textarea 上,如果我添加了一些空行,它们不会显示在预览中。它只在预览框中添加了一个\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);
}

【问题讨论】:

    标签: codeigniter parsedown


    【解决方案1】:

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

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

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

    http://parsedown.org/demo 中进行测试。

    【讨论】:

    • 我不想为 textarea 上的每一行添加
      我希望 php 端能够做到这一点。我也在 str_replace 中尝试过
      但不适用于 parsedown
    • 好吧,当你把它发送到 parsedown 时,你翻译 \n 或 \r\n - 测试两者 - 并添加
      就像 nl2br() 一样......
    • 如果有前置标签等干扰将不得不找到其他东西
    • 好吧,还有其他选择……我去设置这个解析器看看。
    猜你喜欢
    • 2011-09-26
    • 2012-06-04
    • 2013-12-28
    • 1970-01-01
    • 1970-01-01
    • 2010-12-30
    • 2020-12-03
    • 2017-03-03
    • 2021-04-03
    相关资源
    最近更新 更多