从组织模式 Babel 导出时包括'$'符号?



我正在使用org模式写一本技术书。我想导出到 markdown(GitHub 风味)代码和结果,它工作正常。但我也想导出$或之前的任何内容(例如 (venv) $当我在终端中输入内容时。

现在我有这个:

#+BEGIN_SRC sh :exports both
  python --version
#+END_SRC
#+RESULTS:
: Python 3.6.2

导出到这里:

python --version
Python 3.6.2

我想要的是这个:

$ python --version
Python 3.6.2

有什么想法吗?

对于 HTML 输出,您可以添加导出过滤器,例如

(defun my-html-dollar-sign-filter (text backend info)
  "Add a $ sign to the beginning of code blocks"
  (when (org-export-derived-backend-p backend 'html)
        (replace-regexp-in-string
         "\(<pre class="src src-sh">\)" "\1$ " text)))
(add-to-list 'org-export-filter-src-block-functions
             'my-html-dollar-sign-filter)

它起作用,因为<pre class="src src-sh">python --version</pre>在 HTML 输出中非常明确地标识了该命令。不幸的是,Latex导出器包装了代码并导致verbatim环境,这使得不可能以这种方式在代码前面放置美元符号。

最新更新