Closed tasmanwebsolutions closed 7 years ago
This is a question out of scope for this issue tracker since it's PHP related and not at all related to showdown (you can try www.stackoverflow.com, for instance).
However, the problem is that your string has linebreaks.
So the resulting code is something like this:
<script type="text/javascript">
var converter = new showdown.Converter(),
text = '#Hello
How are you
jjjjjjjj',
target = document.getElementById('output'),
html = converter.makeHtml(text);
target.innerHTML = html;
</script>
which is invalid javascript.
@wolfgang1983 maybe try substituting the single quotes around the php code with backticks, which support multiline text.
<script type="text/javascript">
var converter = new showdown.Converter(),
text = `<?php echo $preview;?>`,
target = document.getElementById('output'),
html = converter.makeHtml(text);
target.innerHTML = html;
</script>
for more support from template strings
check this
I have now had to do couple changes on my insert database end with codeigniter
public function insert() {
$data = array(
'question' => $this->db->escape(trim(str_replace('\n', PHP_EOL, $this->input->post('html'))))
);
$this->db->where('question_id', '1');
$this->db->update('question', $data);
}
Works fine now.
I am trying to convert my text from my database column
I echo text to view but says error SyntaxError: unterminated string literal
What do I need to do for text from database to be able to work with showdown
My text that I insert looks like this example below
Hello
How are you