/ Published in: PHP
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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php // Example 1: // Renders the body field as format_id '4' (i.e., Markdown) then saves // as format_id '3' (i.e, Full HTML). // // Run all enabled filters for format_id '4' on the body field. $object->body = check_markup($object->body, 4); // Change $format to format_id '3'. $object->format = 3; node_save($object); // Example 2: // Renders several CCK fields as format_id '4' (i.e., Markdown) then saves // as format_id '3' (i.e, Full HTML). // // Run all enabled filters for format_id '4' on $field_notes, $field_description and $field_dimensions. $object->field_notes[0]['format'] = check_markup($object->field_notes[0]['value'], 4, TRUE); $object->field_description[0]['format'] = check_markup($object->field_description[0]['value'], 4, TRUE); $object->field_dimensions[0]['format'] = check_markup($object->field_dimensions[0]['value'], 4, TRUE); // Change $format to format_id '3' for all three fields. $object->field_notes[0]['format'] = 3; $object->field_description[0]['format'] = 3; $object->field_dimensions[0]['format'] = 3; node_save($object); // Example 3: // Simultaneously renders CCK field $field_description and migrates // the new value to the default body field. $object->body = check_markup($object->field_description[0]['value'], 4, TRUE); node_save($object); ?>