• Login
Community
  • Login

[markdown] syntax color support for code blocks

Scheduled Pinned Locked Moved Notepad++ & Plugin Development
2 Posts 2 Posters 954 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E
    Emanuel Oliveira
    last edited by Oct 5, 2024, 5:48 PM

    Hi all,

    I was able to add several custom markdown styles via Language > User Defined Language:
    1 markdown color styles.png

    But all user defined languages I downloaded () don’t have support to the markdown 4 backticks <language>

    ```sql
    select 'hello world
    .```
    

    or python like following:
    2 code blocks all same color.png

    All code block have same color.

    I understand basics of how markdown as USer Defined Language done, but Ii don’t see easy way for me to add BNF syntax just inside code blocks ?

    Is this even possible to do ?

    Thanks so much, I been using Notepad++ for many years, and recently started creating markdown files, but I’m missing this color support inside code blocks.

    Thanks for suggesting if this possible (via User Defined Language) or via some plugin ?

    Cheers ~

    1 Reply Last reply Reply Quote 0
    • P
      PeterJones
      last edited by Oct 5, 2024, 7:14 PM

      The UDL can handle doing different colors for `single backticks` vs triple

      ```
      long code
      ```
      

      For example, here is a screenshot using the “markdown (preinstalled)” UDL that comes with Notepad++:
      5bee2f23-5331-485e-a948-783587fdf052-image.png

      Then, if I remove the single ticks from Delimiter 2 and move it to Delimiter 8 (which was empty before) and give 8 a different color, it works just fine:

      8df18d51-af9a-4f45-986a-aca6e6284a4d-image.png

      The one thing to keep in mind with making Delimiters for “triple” vs “single”: you have to put the triple before the single, otherwise when it’s doing it’s parsing, it will match on the single rule first. (It searches through the delimiters in the 1-8 order)

      And if you wanted to allow specific keywords (say keyword8) inside the triple quotes (delimiter 2), then you can go into the styler for delimiter2 and allow keyword8 inside:
      49f17867-6e52-4cdd-8d39-75f0f46c731b-image.png
      fc5ebe90-be88-4a3b-a81b-53b5a5ee8432-image.png

      I am not sure what you were trying to indicate with the “BNF” in your question: if you just meant keywords, then I’ve shown it works. But something like the @udtf(...) would be more difficult – at least with the way “markdown (preinstalled)” is defined. And getting full python highlighting inside of the code-block markdown is not possible, the way that UDL and N++ is implemented.

      But, at some point, based on the complexity you are describing, it might go beyond what UDL is capable of: UDL was meant for “simple” syntaxes, and if you wanted something more complicated, then the idea was that a lexer plugin could be the next step to bridge the gap between UDL and what N++ provides natively.

      1 Reply Last reply Reply Quote 2
      2 out of 2
      • First post
        2/2
        Last post
      The Community of users of the Notepad++ text editor.
      Powered by NodeBB | Contributors