Hello,
I accomplished a subtle change to how source output looks in browser's view-source console. It helps to quickly navigate ourselves along the lines.
So I spent a day to make it closer to expected with following source:
BEFORE:
AFTER:
Perhaps, if you see a way to tweak this a little more, I would certainly be interested in coding it a little further.
I added a line to /addons/kfunctions.php
Created folder 'custom-code' in couch/addons/ and placed a file 'custom-events.php' in it.
Content of custom-events.php:
The function above also has traces of my previous code that removes php-style and html-style comments. If you don't want it, it's easy to remove #1-4 elements from both arrays.
Thank you
Do not forget to comment.
I accomplished a subtle change to how source output looks in browser's view-source console. It helps to quickly navigate ourselves along the lines.
So I spent a day to make it closer to expected with following source:
BEFORE:
AFTER:
Perhaps, if you see a way to tweak this a little more, I would certainly be interested in coding it a little further.
I added a line to /addons/kfunctions.php
- Code: Select all
require_once( K_COUCH_DIR.'addons/custom-code/custom-events.php' );
Created folder 'custom-code' in couch/addons/ and placed a file 'custom-events.php' in it.
Content of custom-events.php:
- Code: Select all
<?php
if ( !defined('K_COUCH_DIR') ) die(); // cannot be loaded directly
$FUNCS->add_event_listener( 'alter_str_to_parse', array('CustomEvents', 'tide') );
class CustomEvents{
function tide(&$html){
// https://www.couchcms.com/forum/viewtopic.php?f=8&t=10372#p26841
/* this is a sample comment */
/*
this
is
a comment
*/
/** I wrote this line of comment (since slash-star-star prefectly works even for a single line without ending symbols)
and decided to expand it later, by adding a star-slash to the end of last string */
$target_tags = 'pages|templates|extends|embed|block|block_parent|smart_embed|each|if';
$what = array(
'`\/\*\*.*\s`' // #1 /** comment
, '`(?:\/\*[\s\S]*?\*\/)+?\s`' // #2 /* comment */
, '`.*\*\/\s`' // #3 comment */
, '%<!--(?!<!)[^\[>].*?-->%' // #4 html-comment // won't remove downlevel-revealed or downlevel-hidden [conditional comments].
, '%^(\s*?<cms:.*\/>)$%m' // #5 Any self-closing. Add EOL after it closes the line and preserve spaces before it.
, '%(<cms:.*?\/>\n)%m' // #5.1 Any self-closing. Add EOL after it closes the line.
, '%^\s+(<cms:embed.*\/>)$%m' // #6 A self-closing <cms:embed />. Remove spaces before it.
, '%\n\s+<cms:(?=(' . $target_tags . '))%' // #7 Remove spaces before selected tags
, '%\s+<cms:(?=(' . $target_tags . '))%' // #7.0 Remove spaces before selected tags even without newline before them
, '%\n\s+</cms:(' . $target_tags . ')>%' // #7.1 Remove spaces before closure of selected tags
, '%\n\s+</cms:(' . $target_tags . ')>\n+%' // #7.2 Remove spaces before closure of selected tags and after it
, '%(</cms:.*>)$%mu' // #8 Closure of tag should add EOL. Helpful for one-liners
, '%\r\n\r\n%' // #9 Replace double newline to single
);
$with = array(
'' // #1
, '' // #2
, '' // #3
, '' // #4
, '$1' . PHP_EOL // #5
, '$1' . PHP_EOL // #5.1
, PHP_EOL . '$1' // #6
, PHP_EOL . '<cms:' // #7
, PHP_EOL . '<cms:' // #7.0
, PHP_EOL . '</cms:$1>' // #7.1
, PHP_EOL . '</cms:$1>' // #7.2
, "\n" . '$1' // #8
, PHP_EOL // #9
);
//error_log( print_r( 'BEFORE:' . PHP_EOL . $html, true ) );
$html = preg_replace( $what, $with, $html);
//error_log( print_r( 'AFTER:' . PHP_EOL . $html, true ) );
return 1;
}
}
The function above also has traces of my previous code that removes php-style and html-style comments. If you don't want it, it's easy to remove #1-4 elements from both arrays.
Thank you

Do not forget to comment.
