karthink / gptel

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

Source blocks with language==org breaks formatting #378

Open osheari1 opened 1 month ago

osheari1 commented 1 month 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 1 day 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.