Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
On my website https://peterme.net i recently posted two articles on embedding NimScript into programs. However all links with the word "nimscript" in them gets rewritten to have "nimscxxxript" instead, including the one from part 1 to part 2. I tried to both change them through the UI and changing them through the source code editor, but when I save the page the transformation happens. What is causing this strange behaviour?
@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.
3 posts Page 1 of 1