英文:
Is there any way to get hyperlinked results from a code block in org mode?
问题
在org模式下,当您从代码块生成链接时:
#+begin_src shell :results output
for f in *; do
if [[ "$f" == "index.org" ]]; then
continue
fi
printf -- "- [[file:$f][$f]]\n"
done
#+end_src
#+RESULTS:
: - link_one
: - link_two
: - link_three
尽管它们不会“展开”(以格式[[file:link_one][link_one]]显示),但在Emacs中仍然无法与它们交互作为链接。
为了澄清,我试图在索引页面上使用这个功能,以自动链接到该目录中的所有其他页面。我认为这样做从org模式本地实现会很酷,而不是编写一个脚本来执行,这是一个更优雅的解决方案。
这个第一个问题可以通过删除结果块中的冒号来解决,但这很麻烦。
此外,只要#+RESULTS:块存在,导出为HTML时不会识别链接,而是选择将它们显示为纯文本,尽管Emacs(编辑器)“理解”删除链接前面的所有冒号时它们应该是链接。换句话说:HTML导出功能不识别它们为链接,尽管Emacs可以。我的问题是:如何生成链接从代码块,以便导出器和Emacs自动识别它们?
我已经尝试过查找,但这是一个非常小众的问题。有一些方法可以从代码块获取链接,但它们涉及将所有输出写入文件,这不是我想要的。也许有一些小技巧,可以通过使用它来使其工作?
英文:
In org mode, when you generate links from code blocks:
#+begin_src shell :results output
for f in *; do
if [[ "$f" == "index.org" ]]; then
continue
fi
printf -- "- [[file:$f][$f]]\n"
done
#+end_src
#+RESULTS:
: - link_one
: - link_two
: - link_three
Even though they don't "expand" (shown in the format [[file:link_one][link_one]]),
you still cannot interact with them in emacs as links.
For clarification, I am trying to use this on an index page to
automaticlly link in all the other pages in that directory. I think
it would look cool to do this from org mode natively instead of
writing a script to do it, and it's a more elegant solution.
This first problem can be solved by deleting the colons in the results block, but that is a pain.
Furthermore, so long as the #+RESULTS: block is there, exporting to html does not recognize
the links and instead opts to display them as plaintext, even though emacs (the editor )
"understands" that they should be links when you delete all the colons at the front of the links. In other words: the html export function doesn't
recognize them as links, even though emacs does. My question is: how can you generate links from
code blocks such that they are recognized by the exporter and by emacs automatically?
I've tried looking around but it's a very niche problem. There are ways to get links
from code blocks, but they involve writing all the output to a file, which is not what
I want. Maybe there is some hack where I can make it work by using that?
答案1
得分: 1
我找到答案了。基本上,另一篇帖子有一个类似的(但不完全相同)问题,他们的解决方案是使用 :results output raw
,这几乎可以解决问题。你还需要添加 :exports both
,以便导出器识别代码块的输出。
英文:
I've found the answer. Basically another post had a similar (but not the same)
problem, and their solution was to use :results output raw
instead, which
almost worked. You also need to add :exports both
in order for the exporter to recognize the output of the code blocks.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论