Jump to content

CKEditor on a Markdown content


rooofl
 Share

Recommended Posts

Hello! I have a textarea field already full of Markdown content. My clients need it to have CKEditor on it. That may be a silly question, but I can’t figure out how to use CKEditor with Markdown.
Is it possible to either:

  • interpret Markdown in HTML on the fly, in the CKEditor field
  • convert all Markdown in HTML so CKEditor fields show HTML as they are supposed to do (I guess)

Thank you for your answers.

Link to comment
Share on other sites

13 hours ago, rooofl said:

interpret Markdown in HTML on the fly, in the CKEditor field

I'm 99% sure there is no module or editor available that works like that - but a Markdown WYSIWYG would be a great addition.

13 hours ago, rooofl said:

convert all Markdown in HTML so CKEditor fields show HTML as they are supposed to do

About how many pages are we talking here? In case the number is way lower than 100 pages, a large strong coffee and a nice playlist would be a great start to copy everything over manually. If that's not possible or if there are more pages, you could try to update a real HTML field (TinyMCE nowadays, and not CKEditor anymore).

In general this could work like this in a loop:

// this duplicates the content in fieldname1 into fieldname2 for all pages with
// the template called: templatename
$source = "fieldname1";
$destination = "fieldname2";
$template = "templatename";

foreach($pages->find("template=$template") as $p) {
    // set outputFormatting to 'false' so the plain value is copied
    $p->of(false);
    $p->$destination = $p->$source;
    $p->save($destination);
}

See: https://processwire.recipes/recipes/duplicate-content-between-fields/

In your case we would need to tweak it a bit more and get the generated HTML first, then drop it into the new $destination field and go from there.

BUT... from that moment the client should only be using the CKEditor/TinyMCE field and no markdown anymore.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Thank you
@wbmnfktr for your answer. I think it is a bit more complicated than I thought. I understand what you wrote, and it totally make sense, but I think the economy will choose for me : keeping the markdown field as it is. However, I just discovered the module InputfieldEasyMDE, and that might be what I am looking for, as it keeps the markdown field content and just adds formatting options on a icon bar.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...