Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chat window: wrap code always in code blocks #113

Open
monkeyjunglejuice opened this issue Mar 23, 2025 · 8 comments
Open

Chat window: wrap code always in code blocks #113

monkeyjunglejuice opened this issue Mar 23, 2025 · 8 comments

Comments

@monkeyjunglejuice
Copy link

monkeyjunglejuice commented Mar 23, 2025

When the LLM generates code, e. g. during an /ask prompt, code is not wrapped within a code block, hence certain characters trigger Markdown (?) formatting instead of being displayed verbatim.

E.g. when the LLM generates code like this ...

  def start_link(initial_state \\ %{}) do
    GenServer.start_link(__MODULE__, initial_state, name: __MODULE__)
  end

__MODULE__ is displayed as MODULE in the output.

Telling the LLM ... "Wrap code you provide always in code blocks. Otherwise, some characters apply text formatting instead of being displayed verbatim."

... doesn't help either. The LLM complies with this request, which gives me syntax highlighting, but even then double-underscores and other characters that are used for Markdown formatting still trigger text formatting.

It seems that the chat window's output is basically based on Markdown (?) It would be nice if the user could select org-mode as the underlying output, with code blocks wrapped accordingly.

@tninja
Copy link
Owner

tninja commented Mar 23, 2025

Thanks for using aider.el and the feedback. I am able to reproduce the issue by enter: "/ask write a example python application to demo how to use __MODULE__". In the code block it shouldn't render it as BOLD and remove __.

But when I check .aider.chat.history.md file, use markdown-mode and did (setq markdown-fontify-code-blocks-natively t), the code block rendering is correct. So it means markdown-mode.el work properly, and we missed something in this function: https://github.com/tninja/aider.el/blob/main/aider-core.el#L48

@tninja
Copy link
Owner

tninja commented Mar 23, 2025

Just let the aider comint session ignore these special characters including __. Confirmed that it work properly on my laptop. Would you mind try the main branch or reinstall from melpa again?

@MatthewZMD
Copy link

MatthewZMD commented Mar 23, 2025

The problem is not markdown rendering bold or italics, that is the desired behavior, it should render italics when it supposed to, the problem is the output sometimes doesn't have code fences, your fix doesn't address the underlying problem but hides it, that's why I did't follow with your approach in aidermacs.

@tninja
Copy link
Owner

tninja commented Mar 23, 2025 via email

@MatthewZMD
Copy link

MatthewZMD commented Mar 23, 2025

What are you talking about? I'm not even mod on reddit. This is weird, I'm not authorized to delete comments on reddit. Why start a drama in this issue?

I'm just giving my two cents regarding this issue, and only this issue, maybe you stop being so hostile? Your ego is blowing my nose right now.

@tninja
Copy link
Owner

tninja commented Mar 23, 2025

Yes it is very weird because it is the first time my comment got deleted by other people (twice or even more). I never see my post got deleted by anybody else.

Go back to the problem. There is pros and cons of this fix.

Pros: it fix the BOLD text in codeblock, which shouldn't happen in code block.
Cons: it even inhibit BOLD or italic text in regular markdown text outside of code block.

Comparing Pros and Cons, the fix is valuable since codeblock showing original code is more valuable to people, and text rendering properly (only bold or italic) is less important.

A better fix to ONLY inhibit BOLD text rendering in codeblock should happen somewhere around this line: https://github.com/tninja/aider.el/blob/main/aider-core.el#L64. It will take more time to investigate. @CeleritasCelery have more experience on the highlight part than me. I would be very appreciate if he is willing to help on this problem, especially if we can still keep using markdown as syntax highlight solution.

@MatthewZMD
Copy link

MatthewZMD commented Mar 23, 2025

Yeah, he's very knowledgeable in syntax highlighting, that's why I value his inputs, and especially his pull requests. A super nice contributor 👍👍

@tninja
Copy link
Owner

tninja commented Mar 26, 2025

The cons of this fix: it even inhibit BOLD or italic text in regular markdown text outside of code block. Might be OK. Because there is risk that the markdown text beside codeblock could describe the symbol, to help explain the code. For example, __MODULE__. Rendering that in markdown will make it difficult to read.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants