EDIT: update w.r.t. comments
So the final solution/workaround is:
- use source blocks, as they include highlighting when exported
- comment out, i.e. put
# before, the self written output lines
- then in the function
org-html-src-block replace the line
(code (org-html-format-code src-block info))
(code (with-temp-buffer (insert (org-html-format-code src-block info))
(while (not (eobp))
(print (search-forward ">"))
(if (looking-at "# ")
(insert "$ "))
search-forward code probably has to get slightly improved for inputs without fontification)
I think you should use a source block for this instead, e.g. as follows
#+begin_src sh :exports both
if true; then echo hello; fi
You will get the output by running/exporting it (the
:exports both header argument makes that both the code and the result get exported).
Then subsequently you can format exported output how you prefer it. You can define a derived backend for this (so I guess you should create e.g.
my-sh source blocks).
You can read more about it here and here. Especially check out the function
org-export-define-derived-backend in the latter link. You can then set your personal
my-org-html-src-block translator function (that you can adapt from the original
org-html-src-block function) for source blocks in the
:translate-alist. (To understand the code in the
org-html-src-block function, I would recommend to use
edebug. I guess you can get rid of most of the code, and just keep and modify 'the essence' of it).