Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8816389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:36:38+00:00 2026-06-14T04:36:38+00:00

I’m having a problem with Codemirror where the live preview mode is not working

  • 0

I’m having a problem with Codemirror where the live preview mode is not working for Markdown. I’m basically just trying to achieve the same effect as on SO. As it stands the live preview works for HTML but not Markdown. I’ve followed several of the demos and tried a few things with no luck and I’m here as a last resort. Here is the relevant code:

In the head of my document I’m loading:

<script src="editor/lib/codemirror.js"></script>
<link rel="stylesheet" href="editor/lib/codemirror.css">
<script src="editor/lib/util/overlay.js"></script>
<script src="editor/mode/markdown/markdown.js"></script>

Note: I have the Codemirror files inside a folder called editor. That’s the only real deviation from the normal setup I’ve done.

Then in the <body> of my document I’ve got a <form> with 2 elements:

<textarea id="content" name="content"></textarea>
and
<iframe id="preview"></iframe>

Then at the bottom of my page I’m running the following JavaScript (I’m using jQuery 1.8.2 too by the way):

// Initialize the editor when document finishes loading
    jQuery(document).ready(function() {
        var delay;
    var editor = CodeMirror.fromTextArea(document.getElementById("content"), {
        lineNumbers: false,
        mode: 'markdown',
        matchBrackets: false,
        theme: "ambiance",
        onChange: function() {
          clearTimeout(delay);
          delay = setTimeout(updatePreview, 300);
        }
        });




    // Initialize the live-preview mode
    function updatePreview() {
        var previewFrame = document.getElementById('preview');
        var preview =  previewFrame.contentDocument ||  previewFrame.contentWindow.document;
        preview.open();
        preview.write(editor.getValue());
        preview.close();
        }
        setTimeout(updatePreview, 300);
    });

I can’t figure out what I’m doing wrong. I’ve tried loading overlay mode along with XML to no avail. I found 2 posts here but they weren’t exactly relevant and the code didn’t work for me. The live preview is showing up and updating but the problem is that I’m getting just a single string of text with no formatting.

So, for example, the following Markdown:
# Heading 1

A paragraph with __bold__ *text*.

And [a link](http://example.com)

Will output this in the live preview iframe exactly as I type it here:

# Heading 1 A paragraph with __bold__ *text*.And [a link](http://example.com)

It doesn’t make the underscores or asterisks into bold or italicized text and completely ignores line breaks.

Any ideas as to what’s going wrong? I couldn’t even modify the demos to get it to work. I must be missing some knowledge.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:36:40+00:00Added an answer on June 14, 2026 at 4:36 am

    Browsers don’t display markdown, they display HTML. You’ll have to add a step where you convert them markdown to HTML using, for example, https://github.com/chjj/marked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I've tracked down a weird MySQL problem to the two different ways I was
I'm trying to select an H1 element which is the second-child in its group

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.