组织模式表内的代码块 [英] Code blocks inside tables for org-mode

查看:44
本文介绍了组织模式表内的代码块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢 org-tables,我用它们来记录各种事情.我现在正在为 Nix 记录一些单行代码(在阅读完这篇 优秀指南,在今年的EuroPython),我遇到了一些问题:

I love org-tables, I use them to document all sorts of things. I was now documenting some one-liners for Nix (after reading this excellent guide by Domen Kožar, given at this year's EuroPython), and I got into some problems:

* NIX Oneliners

|------------------+---------------------------------------------+------------------------------|
| DATE             | COMMAND                                     | DESCRIPTION                  |
|------------------+---------------------------------------------+------------------------------|
| <2014-07-24 Thu> | curl -L http://git.io/nix-install.sh § bash | Install nix                  |
| <2014-07-24 Thu> | nix-env -qaP § grep python3-3               | search for python3-3 package |
|------------------+---------------------------------------------+------------------------------|

命令实际上应该是 curl -L http://git.io/nix-install.sh |bashnix-env -qaP |grep python3-3,但由于管道破坏了整个事情,我需要使用另一个字符(在这种情况下§)

The commands should be actually curl -L http://git.io/nix-install.sh | bash and nix-env -qaP | grep python3-3, but since the pipe breaks the whole thing, I need to use another character (in this case §)

我的问题是:如何告诉 org-mode 在一个区域中字面意义获取文本?我不想对管道使用转义序列,因为我想从我的文档.

My question is: how can I tell org-mode to take a text in a region literally? I do not want to use a escape sequence for the pipe, because I want to do easy copy-paste to the shell from my documentation.

我想要的是类似于markdown中的代码块:

What I want is something similar to the code block in markdown:

`do | not | care | about | this`

这在org-mode中存在吗?

事件使用 = this |技巧 = 在表格内不起作用.

Event using = this | trick = does not work inside tables.

推荐答案

你不能那样做:你不能逃避|"表条目中的字符:你能做的最好的事情就是用看起来像它的东西替换它.在 ML 上有几个关于这个的问题,最好的答案似乎是 #xa6 (|) 处的 Unicode 字符 - 参见例如此消息和封闭线程.

You cannot do that: you cannot escape the "|" character in a table entry: the best you can do is replace it with something that looks like it instead. There have been several questions on the ML about this and the best answer seems to be the Unicode character at #xa6 (¦) - see e.g. this message and the enclosing thread.

但是,您可以存储表中代码块的链接.在代码块内,您可以拥有任意代码,因此那里的特殊字符没有问题,另外,您可以执行代码块.

However, you can store links to code blocks in the table. Inside a code block, you can have arbitrary code so there is no problem with special characters there, and as a bonus, you can execute the code blocks.

像这样:

* Table of code blocks

| Name | Code block |
|------+------------|
| foo  | [[foo][foo]]        |
| bar  | [[bar][bar]]        |


#+name: foo
#+begin_src bash
echo "Foo"
#+end_src

#+RESULTS: foo
: Foo

#+name: bar
#+begin_src bash
echo "Bar"
#+end_src

这篇关于组织模式表内的代码块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆