Jump to content

Minify Product Descriptions, etc


bsmither

Recommended Posts

Recently, the forums had a conversation where the OP expressed frustration with the inability to get a CSV file (Export Catalogue) properly loaded into a spreadsheet.

It seems the spreadsheet is honoring a line break character (EOL) that is part of a data field. This causes that part of the data in front of the EOL to be on one spreadsheet row, where everything after the EOL appears on the next spreadsheet row -- and additional rows for every additional EOL in the data.

The solution is to have the product description editor (CKEditor, which is also used for other rich text entries) be configured to not embed EOLs for the sake of pretty-printing the HTML output.

However, there are a few cases where having embedded EOLs is desired by the composing author. One such case is the HTML tag <pre>. Web browsers will honor spans of spaces and EOLs in the content within the <pre> block, and will show the text in a mono-spaced font. This allows for <table>-less tabular data without resorting to CSS.

Normally, the editor outputs this:

{EOL}
<p>{EOL}
	This is product copy.</p>{EOL}
{EOL}
<p>{EOL}
	This is more product copy.</p>{EOL}
{EOL}
<p>{EOL}
	And even more product copy.</p>{EOL}

Where {EOL} is the line ending characters that raise the problems with importing CSV data into spreadsheets.

The following code snippet will configure CKEditor to not add all of those line endings for pretty-printing, resulting in:

<p>This is product copy.</p><p>This is more product copy.</p><p>And even more product copy.</p>

In admin, Manage Hooks, Code Snippets tab, click Add Snippet.

Make these settings:

Enabled: Checked
Unique ID: minify_rte@cubecart
Execution Order: 99
Description: Configures CKEditor to not pretty-print its output.
Trigger: admin.body_js
Version 1.0
Author: https://forums.cubecart.com/topic/50671-minify-product-descriptions-etc/
PHP Code:
<?php
$body_js[] = CC_STORE_URL.'/'
            .((!$GLOBALS['config']->isEmpty('config', 'adminFolder'))
              ? $GLOBALS['config']->get('config', 'adminFolder')
              : 'admin')
            .'/skins/'
            .((!$GLOBALS['config']->isEmpty('config', 'admin_skin'))
              ? $GLOBALS['config']->get('config', 'admin_skin')
              : 'default')
            .'/js/special_ckeditor_config.js';
?>

Then, create a new file:

Path and Name: /admin/skins/default/js/special_ckeditor_config.js

Contents:

CKEDITOR.on('instanceReady', function( ev ) {
  var blockTags = ['div','h1','h2','h3','h4','h5','h6',
  'p','pre','li','blockquote','ul','ol',
  'table','thead','tbody','tfoot','td','th',];

  for (var i = 0; i < blockTags.length; i++)
  {
     ev.editor.dataProcessor.writer.setRules( blockTags[i], {
        indent : false,
        breakBeforeOpen : false,
        breakAfterOpen : false,
        breakBeforeClose : false,
        breakAfterClose : false
     });
  }
});

Take note: CKEditor will still include HTML_Entities in the output:

&#39; for apostrophe
&quot; for quote
&lt; for <
&amp; for &
etc.

The Export Catalogue function does not clean that up.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...