【问题标题】:how to use emacsclient -e "command" to convert a .org file to html?如何使用 emacsclient -e "command" 将 .org 文件转换为 html?
【发布时间】:2018-01-05 08:09:26
【问题描述】:

我想用emacsclient -e "command"将org模式文件转换成html文件,如:

emacsclient -e "(org-html-export-as-html ./mynote.org)" > ./mynote.html

希望它将输出保存到 mynote.html 文件中。
但我还不熟悉elisp。其实org-html-export-as-html有很多参数我不知道怎么用。

【问题讨论】:

    标签: html emacs org-mode emacsclient


    【解决方案1】:

    A/ 你可以“自己”做:

    emacsclient -e "(progn (find-file \"file.org\") (org-html-export-to-html) (kill-buffer))" 
    

    警告:要使其正常工作,您应该使用

    启动 Emacs
    emacs --daemon 
    

    或者如果您已经运行了 Emacs,请输入 M-x server-start

    B/ 使用 github 包

    https://github.com/nhoffman/org-export

    它会创建一些已编译的 lisp 可执行文件:

    • 组织导出 html
    • org-export 纠结
    • ...

    但是我个人的经验是命令行方法更快。

    C/ Bonus,纠结文件

    您可以使用相同的命令行方法来处理文件:

    emacsclient -e "(org-babel-tangle-file \"file.org\")"
    

    更新,提供有关 C/ 的更多详细信息

    “缠结”一词源自literate programming

    文学编程(LP)工具用于获得两种表示 来自有文字的源文件:适合进一步编译或 由计算机执行,“纠结”的代码,以及另一个用于查看 作为格式化的文档,据说是从 文学来源。 [3]而第一代识字编程 工具是特定于计算机语言的,后来的工具是 与语言无关,存在于编程语言之上。

    你有一个独特的文件:

    #+TITLE: My Org file
    
    * Configuration
    
    #+BEGIN_SRC bash :tangle yes :tangle "tangled.sh" :shebang "#!/bin/bash"
    echo "This is my configuration script"
    echo "..do something interesting here.."
    #+END_SRC
    

    您可以通过 html 导出它(A/ 或 B/ 部分),但也可以导出它包含的代码,这里是一个 shell 脚本。在 Emacs 中,这可以使用 C-c C-v t 来完成,或者在 shell 中,使用我在 C/ 部分中提供的命令来完成。结果是自动生成tangled.sh 文件。

    您可以在这里查看:Babel: active code in Org-mode 了解更多详情。

    【讨论】:

    • 一个非常适合我! B 似乎很棒,但我还没有测试。 C print nil 没有任何内容。你能给我一些关于C的解释吗?文档说方法Extract the bodies of source code blocks in FILE.不知道是什么意思
    • 你好,我可以在导出html文件时设置body-only,例如:emacsclient -e "(progn (setq body-only 1) (find-file \"docker.org\") (org-html-export-to-html) (kill-buffer))"。我尝试过,但完全没有影响。
    • 我终于在 elisp 中找到了 &optional 用法。只输出正文可以处理emacsclient -e "(progn (find-file \"file.org\") (org-html-export-to-html nil nil nil 1 nil) (kill-buffer))" 是可以的。 ;-)
    • 我已经详细介绍了C部分(见更新)
    • 我总是使用“命令行”方法(A/ 和 C/)。过去,我测试过 B/,但命令比直接 emacs 服务器 + shell 命令行方法慢得多。也许现在不再是这种情况了,我不知道。
    【解决方案2】:

    恕我直言,正确的方法应该是

    emacsclient -e "(org-html-publish-to-html '()  \"file.org\" \".\")"
    

    但它抱怨 *ERROR*: ‘org-publish-cache-get’ called, but no cache present - 对我来说它看起来像是 Org 模式中的错误

    【讨论】:

    • 如果你想导出你应该使用导出函数;如果你想发布,你应该使用发布功能。但发布需要比导出更多的设置。
    • @Nick - 是的,我的错 - 你是对的......但是要使用导出功能,还需要更多设置......
    • 不是真的:请参阅其他答案。您打开文件并导出它。
    猜你喜欢
    • 1970-01-01
    • 2016-09-26
    • 1970-01-01
    • 2019-12-03
    • 2016-03-10
    • 2016-12-26
    • 2012-11-05
    • 1970-01-01
    • 2011-05-25
    相关资源
    最近更新 更多