【问题标题】:Including the '$' sign when exporting from org-mode Babel?从 org-mode Babel 导出时包括“$”符号?
【发布时间】:2017-10-23 17:22:45
【问题描述】:

我正在使用 org-mode 编写一本技术书籍。我想导出到markdown(GitHub Flavored)代码和结果,它工作正常。但我也想导出$ 或之前的任何内容(例如,当我在终端中输入内容时,(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

有什么想法吗?

【问题讨论】:

    标签: emacs org-mode


    【解决方案1】:

    对于 HTML 输出,您可以添加 export filter 类似

    (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)
    

    自从&lt;pre class="src src-sh"&gt;python --version&lt;/pre&gt; 在 HTML 输出中非常明确地识别该命令后,它就起作用了。不幸的是,Latex 导出器包装了这两个代码并生成了一个verbatim 环境,这使得以这种方式只在代码前面放一个美元符号是不可能的。

    【讨论】:

    • 谢谢。我想导出到 GitHub 风格的 markdown
    猜你喜欢
    • 1970-01-01
    • 2021-02-19
    • 1970-01-01
    • 2012-02-23
    • 2012-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多