grav-plugin-shortcode-core icon indicating copy to clipboard operation
grav-plugin-shortcode-core copied to clipboard

Shortcodes are applied for code blocks

Open ViliusS opened this issue 10 months ago • 2 comments

I'm not sure if I should report this directly to Grav or here, but when this plugin is enabled and the page contains markdown code block, maching shortcode text is stripped from the code block. Example:

---
title: Test page
taxonomy:
    category:
        - docs
---

Test SQL query:
```sql
SELECT 1 AS [color] FROM test_table
```

The [color] will be stripped out from the final display on generated HTML page.

ViliusS avatar Feb 17 '25 10:02 ViliusS

Shortcode parsing is not really smart enough to know if you are using a codeblock or anything where a shortcode is not intended to be processed, you have to do it manually. Just surround your code block with the [raw][/raw] shortcode:

    ---
    title: Test page
    taxonomy:
        category:
            - docs
    ---
    
    [raw]
    Test SQL query:
    ```sql
    SELECT 1 AS [color] FROM test_table
    ```
    [/raw]

https://github.com/getgrav/grav-plugin-shortcode-core?tab=readme-ov-file#raw

rhukster avatar Feb 17 '25 16:02 rhukster

Cool, it works!

Could you steer me to the code path which would be the best place to implement such automatic codeblock detection? I think I could spare some hours and try to implement it.

ViliusS avatar Feb 17 '25 17:02 ViliusS