karthink / gptel

A simple LLM client for Emacs
GNU General Public License v3.0
1.63k stars 151 forks source link

Source blocks with language==org breaks formatting #378

Open osheari1 opened 2 months ago

osheari1 commented 2 months ago

With org-mode source blocks in org-mode buffers, the content of the source block must be escaped, otherwise it breaks parsing. For example

* Non block heading

// This gets formatted correctly
#+begin_src org
,* H1
,** H2
,*** H3
,**** H4
stuff stuff stuff
#+end_src

* Non block heading

#+begin_src org
* H1
** H2
*** H3
**** H4
stuff stuff stuff
#+end_src // this line gets treated as normal text, rather than the closing src block, and thus the content gets treated as normal org headings.

image

However if you update the prompt to ensure all source blocks escape headers, then it won't break the parsing.

* Give a comprehensive guide on how to use the emacs package org-edna. Provide examples. When / if you print out any org mode source blocks for the org language, be sure to escape the content in the source block. For example

#+begin_src org
,* H1
,** H2
,*** H3
text
#+end_src

...
**** Example 1: Basic dependency on another task

Suppose you have two tasks where Task 2 depends on Task 1. Here is how you can express that:

#+begin_src org
,* TODO Task 1 :tag1:
,* TODO Task 2
  :PROPERTIES:
  :BLOCKER: tag1
  :END:
#+end_src

Task 2 cannot be marked as done until Task 1 is completed.

image

karthink commented 2 weeks ago

Sorry for the delay in getting to this.

It looks like it's working correctly then? By default gptel will leave all text inside src blocks untransformed when converting from Markdown to Org. Messing with this introduces all kinds of edge cases. The best way to handle this is to get the LLM to produce correctly formatted blocks, as you do.

osheari1 commented 1 week ago

No worries :smile:

Agreed. I suppose I was thinking more along the lines of making it more obvious to users what they would need to do in this scenario, as it took me a while to figure out.

Maybe we could add a record in the FAQ about how to handle miss-formatted org-mode source blocks? (I'd be happy to do it)

karthink commented 1 week ago

Maybe we could add a record in the FAQ about how to handle miss-formatted org-mode source blocks?

Sounds good! Documentation PR is welcome.