Ok, if I understand you correctly, implementing the mechanism akin to the latex one, setting a new variable `org-html-prefer-user-labels` would change the relevant exported HTML for the following piece of org:
---------------------- #+NAME: test_fun #+BEGIN_SRC js :exports code function test_fun() { } #+END_SRC Link to [[test_fun]] #+CAPTION: Caption of Another Test Fun #+NAME: another_test_fun #+BEGIN_SRC js function another_test_fun() { } #+END_SRC Link to [[another_test_fun]] ----------------------- from #+BEGIN_EXAMPLE html <pre class="src src-js" id="orgsrcblock1"> ... </pre> <pre class="src src-js" id="orgsrcblock2"> ... </pre> Link to <a href="#orgsrcblock1">1</a> Link to <a href="#orgsrcblock2">1</a> #+END_EXAMPLE to #+BEGIN_EXAMPLE html <pre class="src src-js" id="test_fun"> ... </pre> <pre class="src src-js" id="another_test_fun"> ... </pre> Link to <a href="#test_fun">1</a> Link to <a href="#another_test_fun">1</a> #+END_EXAMPLE Looking at `org-html-link`, `org-export-get-reference` is only called to get the _internal_ reference. That works perfectly fine already, and I am quite happy with the way org mode generates labels/ids for the exported code. That should, however, have no influence of the link description (called `desc` in the code in `org-html-link`), which is the thing that I actually want to change? In summary, my exported output is supposed to look like that: #+BEGIN_EXAMPLE html <pre class="src src-js" id="orgsrcblock1"> ... </pre> <pre class="src src-js" id="orgsrcblock2"> ... </pre> Link to <a href="#orgsrcblock1">test_fun</a> Link to <a href="#orgsrcblock2">another_test_fun</a> #+END_EXAMPLE Regards, timor 2016-06-17 13:56 GMT+02:00 Nicolas Goaziou <m...@nicolasgoaziou.fr>: > Hello, > > timor <timor...@gmail.com> writes: > >> Why is the link text set to "1" in both cases? > > This is just a nonsensical number because Org does not know what to > number. If you want to number source blocks, you need to add a caption > to them. > >> Thanks for the pointer. I tried to see the effect of that variable, >> but I noticed that for latex export, a \ref{orgsrcblock1} tag is >> created, although the listing in the exported latex code does not >> provide a "target" to link to at all. > > If `org-latex-prefer-user-labels' is non-nil, no \ref{orgsrcblock1} is > created. > >> I was more thinking along the lines of treating internal links to >> named blocks in the same way that external links in HTML export are >> treated: >> For [[http://some/url]], the link text is simply set to the target, >> the target being the external web page. >> For [[some_named_block]] the link text should then also be the name of >> the target, in that case the target being the source block. > > I think the way to go is to create an equivalent to > `org-latex-prefer-user-labels' and to turn it off by default. > > It boils down to creating a wrapper around `org-export-get-reference', > e.g. `org-html--reference' and replace it in the file. > > It should also be tested when cross-referencing data in a published > project. > > Regards, > > -- > Nicolas Goaziou