I am using parsedown and codeigniter. On my textarea if I have added a few empty lines they do not show up in preview. It only adds one \n
in preview box
As shown in this image Note: preview is the bottom box in image
As you can see in the top box which is a textarea. There is a large gap just before the last line. It does not show that in preview? If I try and replace the newlines with br or nlbr it effects the indented code on parsedown
Question using codeigniter and parsedown how can I make sure when I echo it from controller that the will show same ammount of lines.
Script
<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>
Controller
<?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);
}
for each new line on textarea I want the php end to be able to be able to do it. I have also tried
in str_replace but not work with parsedown – Nov 25 '16 at 05:22
just like nl2br() does... – TimBrownlaw Nov 25 '16 at 05:26