Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first part turns into '<pre><code>' #534

Closed
ghost opened this issue Jan 1, 2015 · 4 comments
Closed

first part turns into '<pre><code>' #534

ghost opened this issue Jan 1, 2015 · 4 comments

Comments

@ghost
Copy link

ghost commented Jan 1, 2015

I have news, once in a list with all news and once where a single new is showed.

The news on the list has a small cut at 200 chars just like this:

$('.new_post_content').each(function() {
       var text = $(this).text();
       text = text.length > 200 ? ( text.substr(0, 200) + "..." ) : text;
       var marked_text = marked(text);
       $(this).html(marked_text);
});

All is working there, the single news is displayed like this:

$('.post-content').each(function() {
      var text = $(this).html();
      var marked_text = marked(text);
      $(this).html(marked_text);
});

On the single new the first paragraph is displayed with <pre><code></code></pre>.

What is the reason for this?

@jme783
Copy link

jme783 commented Mar 25, 2015

+1, I don't know why my MD is being wrapped with this as opposed to rendering correctly. Does anyone know why this is happening or what I can do to fix?

@dongli
Copy link

dongli commented Sep 12, 2015

+1, I meet the similar problems.

@jonathantneal
Copy link

This is because your text likely has a lot of indentations, which would be interpreted as a code block.

<div>
    Hello World
</div>
// get inner html
innerHTML = div.innerHTML; // "\n\tHello World\n" will be interpreted as a code block

// try trimming the innerHTML
div.innerHTML = marked(innerHTML.trim());

Alternatively, you could detect the shortest indentation on any line, and use regex to replace that length of indentation on every line.

https://github.com/sindresorhus/strip-indent

@joshbruce
Copy link
Member

#983

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants