chasberry / orgmode-accessories

Add ons for orgmode
78 stars 18 forks source link

internal links orgmode vs rmarkdown #20

Closed fkgruber closed 3 years ago

fkgruber commented 3 years ago

Hi In org-mode we can create internal links to any section putting the anchor <> and then using and creating a link with [[myling]]. However, this does not work in the resulting html generated from the rmd. Instead we need to use a different notation: for anchors: {#mylink} and for the link my link.

Is there a way so that when we generate the rmd file the orgmode style internal link are converted to the rmd style link?

thanks FKG

fkgruber commented 3 years ago

It seems the issue only happens if we use the anchors <>. If instead I use org-store-link to get the link then it works fine.

chasberry commented 3 years ago

The handling of links usually depends on the 'md backend.

Where does {#mylink} come from? Is this for org or for markdown? Do you have a reference I can check?

It seems like the placement of the <<...>> anchor also has an effect. If you put the link between the asterisk(s) and the headline text, it breaks. But otherwise, I think it is OK.

If you think the current behavior is a bug in 'md you can file a report on the org-mode list.

If you have an rmarkdown reference for the link style you mention, I will consider adding it to org-rmd-link.

fkgruber commented 3 years ago

I modified one of your examples to illustrate the problem. It only happens when you use the table of content. If in the yaml you set toc: false then it works. With toc:true it does not.

#+title: markdown demo
#+date: <2019-08-28 Wed>
#+author: Charles Berry
#+email: ccberry@ucsd.edu
#+language: en
#+creator: Emacs 26.1 (Org mode 9.2.5)

* Ravel-markdown backend

** test link
THis work: [[id:042B3D25-346C-45BE-B306-43A8803166B9][This ddoc]]

This does not work: [[tstlink]]

** intro

The Ravel-markdown exporter will produce =*.Rmd= files,

** R markdown

=*.Rmd= files can be processed by =markdown::render()=

Various output formats can be produced

** Handling of src blocks

Here is an R src block. When =markdown::render()= is run the block is
executed and its output include in the document.

#+begin_src R
a <- rnorm(100)
summary(a)
#+end_src

** Inline src blocks <<tstlink>>

** YAML front matter

YAML export blocks like this:

#+begin_export yaml
output:
  html_document:
      toc: true
      toc_float: true
#+end_export

: #+begin_export yaml
: output: html_document
: #+end_export

will be combined and added to front matter.

The author, title and date will be included if the corresponding
`:with-*' options are set.

The blocks should not be indented although lines within them may be
indented consistent with YAML.

** This document as =*.Rmd= 
   :PROPERTIES:
   :ID:       042B3D25-346C-45BE-B306-43A8803166B9
   :END:

Here is some code to print the document:

#+name: print-rmd
#+begin_src emacs-lisp :eval no :exports none
  (org-ravel-export-to-buffer 'rmd "tmp markdown output"
                  nil nil nil nil nil nil
                  org-ravel-engines
                  "md")
  (with-temp-buffer
  (insert-buffer "tmp markdown output")
  (kill-buffer "tmp markdown output")
  (buffer-string))
#+end_src

The result of running that code looks like this:

#+begin_src emacs-lisp :noweb eval :eval never-export :exports results :results replace
<<print-rmd>>
#+end_src
chasberry commented 3 years ago

I modified one of your examples to illustrate the problem.

You have two *.Rmd files that differ only by toc:true versus toc:false.

And one seems to work as you expect and one does not when you run rmarkdown::render() on each.

This looks like a bug in rmarkdown. But you can fix this by putting the anchor on its own line.

This does not seem like a bug in ox-md, but if you think it is take it up on the org-mode list.