lpa Posted January 14, 2018 Share Posted January 14, 2018 I have some fields defined as basic Textarea fields with htmlspecialchars, Newlines to XHTML Line Breaks and Markdown/Parsedown Extra textformatters. The content is maintained as plain text with line breaks and some simple Markdown coding. Now the editors would like to use CKeditor for those fields. What should I do to convert the current newlines and Markdown formatting to HTML formatting shown properly in CKeditor? Link to comment Share on other sites More sharing options...
dragan Posted January 14, 2018 Share Posted January 14, 2018 If there are many such fields, consider changing the textarea values via API + regex. e.g. with https://gist.github.com/jbroadway/2836900 Just take care about when using / removing / adding which textformatters in the whole process. Perhaps do a test with only a handful of fields first, and see if it works out OK? 1 Link to comment Share on other sites More sharing options...
Robin S Posted January 14, 2018 Share Posted January 14, 2018 For each field that you want to change to CKEditor, add a new CKEditor field to the template. Then use the API to set the formatted value of the textarea field to the CKEditor field. When you have done the API operations and checked that everything is okay you can delete the old textarea field. See here: 2 Link to comment Share on other sites More sharing options...
adrian Posted January 14, 2018 Share Posted January 14, 2018 37 minutes ago, Robin S said: Then use the API to set the formatted value of the textarea field to the CKEditor field. If you're not comfortable doing this manually, take a look at this action in the AdminActions module:Copy Content to Other Field This action copies the content from one field to another field on all pages that use the selected template. This can be useful if you decide you need to split one field into two to allow different settings on different templates. It also makes it easy to move content from one field type to another one that is incompatible. 2 Link to comment Share on other sites More sharing options...
Macrura Posted January 14, 2018 Share Posted January 14, 2018 if you don't want to add the textformatter to the field, you can also do something like this.. $markdown = $this->wire('modules')->get("TextformatterMarkdownExtra"); $htmlVersion = $markdown->markdown($page->textarea_field,2); 1 Link to comment Share on other sites More sharing options...
Robin S Posted January 15, 2018 Share Posted January 15, 2018 2 hours ago, adrian said: If you're not comfortable doing this manually, take a look at this action in the AdminActions module:Copy Content to Other Field This action copies the content from one field to another field on all pages that use the selected template. This is a good suggestion, but the action code would need to be modified in order to work in this case. By default that action copies the unformatted value from one field to another, but in this case the formatted value is needed in order for the newlines/markdown to be converted to HTML. 2 Link to comment Share on other sites More sharing options...
lpa Posted January 16, 2018 Author Share Posted January 16, 2018 So based on your suggestions the change in any case needs a conversion from Markdown to HTML by copying the content to another field and then using the new fields. Thanks for this. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now