SilentVoid13 / Templater

A template plugin for obsidian
https://silentvoid13.github.io/Templater
GNU Affero General Public License v3.0
3.17k stars 190 forks source link

Templater applies syntax highligthing to non-Templater template markup inside a markdown codeblock #1204

Open vburzynski opened 1 year ago

vburzynski commented 1 year ago

Plugin information (please complete the following information):

Describe the bug When I have Templater's syntax highlighting enabled, If I have a markdown codeblock containing code with the same opening and closing tags, then Templater improperly applies syntax highlighting to these lines.

Example code block demonstrating an ERB Template fragment (Ruby on Rails):

# file: app/views/records/index.html.erb
<%= render partial: "records/records" %>

Templater will apply syntax highlighting to the second line.

Second Example:

# file: app/views/records/index.turbo_stream.erb
<%= turbo_stream.update(@frame_id) do %>
  <%= render partial: "records/records" %>
<% end %>

Expected behavior A clear and concise description of what you expected to happen.

Templater should not highlight lines within a markdown codeblock

Screenshots If applicable, add screenshots to help explain your problem.

templater-example-bug

Additional context Add any other context about the problem here.

Zachatoo commented 12 months ago

Templater does support replacing Templater tags inside of codeblocks, so it does make sense why it does it's syntax highlighting. I definitely don't think we should remove support for Templater tags in codeblocks, but I do think there's an argument for disabling just the syntax highlighting in codeblocks.

HippyCraig commented 7 months ago

'm trying to document some code and the code blocks are behaving a little differently in a callout vs just being in the note independently. I looked on the forums but couldn't find anything to solve the issue but what I did find was people discussing that the java <> brackets may be causing a rendering issue possible that it thinks there are HTML instead of just code.

Below is a screen shot of what I am seeing, on the left is the source of the MD file the Right is rendered in Read View. Unfortunately the render is not always consistent, sometime its completely off without any change but there is no discernable pattern to it.

image

I have tried to use other characters in place of the <> like escaping it or even using < but the render just looks the same it does in edit mode, it doesn't resolve to anything

image

I tried a clean vault with no plugins and it worked like I would expect it to. Im ok with putting escape character within my code block but when I add them and go to the reading pane it shows the escape character as well as the charter is supposed to escape in the first place.

Again if there was a way to escape the character in the editing page but rendered correctly I would be fine and I think that would solve the problem for most.

nielsbom commented 7 months ago

I think I came across the same bug. I'm not a 100% sure it's actually a bug though. Using the following note content:

```bash
echo '<%'

I am outside the codeblock



Templater shows this as:
![CleanShot 2024-02-23 at 15 21 33](https://github.com/SilentVoid13/Templater/assets/327080/63682719-af8f-4b5e-967e-573fda5cfed2)

Disabling Templater's setting "Syntax Highlighting on Desktop" (I'm working on desktop) produces this:

![CleanShot 2024-02-23 at 15 22 27](https://github.com/SilentVoid13/Templater/assets/327080/d571abd4-5d19-4a22-98b0-6a7c953d139b)
scmanjarrez commented 6 months ago

I also think that's a bug, the mere presence of <% just destroys the code block rendering. I had to disable every plugin until I found that templater was causing this issue with my code blocks.

HippyCraig commented 6 months ago

Interesting is there a way to escape that? or even use some sort of char code ASCII 60 and 37 to display instead of the actual <% or even a unicode character number

ASCII

&gt;&#37;  = <%
&#37;&lt;    = %>

UTF-8

&#x003C;&#x0025;  = <%
&#x0025;&#x003E;   = %>
HippyCraig commented 4 months ago

Im sorry just having a little trouble following this last part of the thread, is this issue being tabled? Is there some sort of work around to have it display? Or is it marked as some future feature request?

Zachatoo commented 4 months ago

This is a very difficult problem to solve, the syntax highlighting code is very complex and was written by someone who no longer contributes to the Templater project. I don't know when this will be fixed.

For now, I suggest disabling syntax highlighting for Templater if you are affected by this issue. Or only enabling it when you're working on A template and disabling it when you're done.

HippyCraig commented 4 months ago

Ok thanks, I was just curious is all.