by
KK » Mon Jun 01, 2020 4:26 pm
@PMunch, the term 'script' anywhere in an HTML tag's attribute freaks Couch's sanitization routine out, I am sorry.
As a workaround, we can use a shortcode instead (as @gem3 suggested).
To do that please put the following in your couch/addons/kfunctions.php file (if this file is not found, rename kfunctions.example.php to kfunctions.php) -
- Code: Select all
// URL shortcode
// Usage:
// [url https://github.com/PMunch/nimscriptexamples]
// [url https://github.com/PMunch/nimscriptexamples]GitHub[/url]
$FUNCS->register_shortcode( 'url', function($params, $content=null){
global $FUNCS;
extract( $FUNCS->get_named_vars(array(
'href' => '#'
), $params) );
$href = htmlspecialchars( $href, ENT_QUOTES, K_CHARSET );
$href = str_replace ( 'scxxxript', 'script', $href );
if( empty($content) ) $content=$href;
return '<a href="'.$href.'" class="postlink">'.$content.'</a>';
});
Next, as explained in the docs on shortcode (
https://docs.couchcms.com/miscellaneous/shortcodes.html), if suppose your editable region is named 'my_content', currently you'd be displaying it on the fronend like this -
- Code: Select all
<cms:show my_content />
To make it shortcode-aware, change the above to this -
- Code: Select all
<cms:do_shortcodes><cms:show my_content /></cms:do_shortcodes>
And that should be it.
Now you can input the following in admin-panel
- Code: Select all
[url https://github.com/PMunch/nimscriptexamples]
[url https://github.com/PMunch/nimscriptexamples]GitHub[/url]
to get the following output on the frontend -
- Code: Select all
<a href="https://github.com/PMunch/nimscriptexamples" class="postlink">https://github.com/PMunch/nimscriptexamples</a>
<a href="https://github.com/PMunch/nimscriptexamples" class="postlink">GitHub</a>
Hope this helps.