Convert Drupal content fields from Markdown to Full HTML for display in CKEditor


/ Published in: PHP
Save to your folder(s)

While these examples convert Markdown fields to HTML for use in CKEditor, the same method can be used to render the filters of any input_format.


Copy this code and paste it in your HTML
  1. <?php
  2. // Example 1:
  3. // Renders the body field as format_id '4' (i.e., Markdown) then saves
  4. // as format_id '3' (i.e, Full HTML).
  5. //
  6. // Run all enabled filters for format_id '4' on the body field.
  7. $object->body = check_markup($object->body, 4);
  8. // Change $format to format_id '3'.
  9. $object->format = 3;
  10. node_save($object);
  11.  
  12.  
  13.  
  14. // Example 2:
  15. // Renders several CCK fields as format_id '4' (i.e., Markdown) then saves
  16. // as format_id '3' (i.e, Full HTML).
  17. //
  18. // Run all enabled filters for format_id '4' on $field_notes, $field_description and $field_dimensions.
  19. $object->field_notes[0]['format'] = check_markup($object->field_notes[0]['value'], 4, TRUE);
  20. $object->field_description[0]['format'] = check_markup($object->field_description[0]['value'], 4, TRUE);
  21. $object->field_dimensions[0]['format'] = check_markup($object->field_dimensions[0]['value'], 4, TRUE);
  22. // Change $format to format_id '3' for all three fields.
  23. $object->field_notes[0]['format'] = 3;
  24. $object->field_description[0]['format'] = 3;
  25. $object->field_dimensions[0]['format'] = 3;
  26. node_save($object);
  27.  
  28.  
  29. // Example 3:
  30. // Simultaneously renders CCK field $field_description and migrates
  31. // the new value to the default body field.
  32.  
  33. $object->body = check_markup($object->field_description[0]['value'], 4, TRUE);
  34. node_save($object);
  35. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.