markdown link to header - hyperlink

I'm using GitLab to write a read.me file.
I tried to create a link to a header. According to the wiki an id should be automatically created:
see here
I created a header using:
### 1. This is my Header
and tried to create a link to it:
[link](#1--this-is-my-header)
but it is not working.
What am I doing wrong?

In the Documentation you link to we learn that...
The IDs are generated from the content of the header according to the
following rules:
All text is converted to lowercase.
All non-word text (e.g., punctuation, HTML) is removed.
All spaces are converted to hyphens.
Two or more hyphens in a row are converted to one.
If a header with the same ID has already been generated, a unique incrementing number is appended, starting at 1.
Note rule 4: "Two or more hyphens in a row are converted to one." However, the example you tried has two hyphens in a row (after the 1). Remove one of them and you should have it.
[link](#1-this-is-my-header)
From time to time I have encountered a unique header which is converted into an ID in some non-obvious way. A quick way to work out the ID is to use your browser's view source and/or inspect tools to view the HTML source code. For example, you might find the following HTML for your example:
<h3 id="1-this-is-my-header">1. This is my Header</h3>
Then just use the contents of the id attribute with a hash to link to that header: #1-this-is-my-header.

Markdown IDs are generated using some rules i've been able to google: (text to lowercase, non-word punctuation removed, spaces converted to hyphens, two or more hyphens in a row converted to one, naming collisions have incremented number appended, ...)
I found an easy way to figure out what the anchor link should be. Use your browser's HTML inspector to inspect the header you want to link to. The header tag's ID should be what you use. So for example my heading looks like this in the HTML inspector:
<h2 id="markdown-header-changing-plsql-parameters-and-shared-developers-lifecycle">
Changing PL/SQL parameters and shared developer's lifecycle
</h2>
And I can link to it in markup like so:
[See instructions below](#markdown-header-changing-plsql-parameters-and-shared-developers-lifecycle)
And now "See instructions below" is linked to my header anchor.

There is a simpler way than the inspector, at least in GitLab-flavored mardown : hover over the header and a "chain" icon appears : right-click on it and copy the link.
header with clickable chain

Related

XSLT: How to generate id attribute of HTML whose value is constant regardless of change of source XML and also proper as a part of URL

I use XSLT 1.0 to transform source XML file to HTML document. In source file there are section elements.
<section name="Name of this section">
...
</section>
And it is transformed to HTML as following (h2 may change to h3, h4, etc. according to the level of nesting).
<h2 id="...">Name of this section</h2>
id attribute is used to reference this section from other HTML document.
Link to the section
Currently geterate-id function is used to generate the value of id attribute. But it may change when structure of source XML file is changed. And it results in breakage of link from other HTML document. So I would like to make value of id attribute constant even if structure of source file is changed.
At first I considered using the value of name attribute. But sometimes it includes characters that is improper as a part of URL (space, question mark, non-ASCII UTF-8 characters, etc.). So it can't be used.
Next I considered adding id attribute to section element of source XML file and using it as is in HTML file. It surely provide proper value but adding it to all section element in source file is bothersome. So I would like to think of it as last resort.
Then is there any way to generete the value of id attribute that is constant regardless of change of source file and also proper as a part of URL?
Maintainer of documents referencing mine told me encode-for-uri() of XSLT 2.0 and str:encode-uri() of EXSLT. I use xsltproc of libxslt as processor and it supports EXSLT. So I decided to use str:encode-uri(#name) as value of id attribute. There are two drawbacks about it. At first it doesn't guarantee uniqueness. If there are multiple section elements with the same name attribute value in source XML file, then id value will be duplicated. The second point is that when the value of the name attribute changes, the id value also changes. However, in my case they don't really matter. The value of name attribute is unique within source file and seldom changed. So I can make id unique and almost constant enough for my case.

How to link to internal link with ampersand?

I am trying to make an internal link to a heading called "word & word".
Since I am using Jekyll, the content is in Markdown files and the heading I want to link to looks like this:
### word & word
I know that I can not use & in URLs.
Therefore this would not be an option:
#word-&-word
I also tried:
#word-%26-word
and
#word-&-word
#word-%26amp;-word
#word-%20amp%3B-word
However, both versions are not working.
What would be the appropriat way to fix this?
Kramdown is striping non alphanumeric from header id's and replacing spaces by -.
You can just check this behavior with :
- mandatory
{:toc}
### word & word
Resulting link in generated table of content is #word--word
See kramdown documentation

substitute space character in lua

I am creating a template in Wikipedia to link articles to an external website which is a book archive called fadedpage.com. I am generating a url to link to a specific author page. Part of the url is the author's name which contains one or more spaces. For example, the url for the author "Ian Fleming" is: http://fadedpage.com/csearch.php?author=Fleming, Ian. My template call structure is {{FadedPage|id=Fleming, Ian|name=Ian Fleming|author=yes}}.
For my template I am replicating an existing template which uses a script coded in lua to parse the template arguments. I have been able to generate all of the url except for the space character between the last and first name.
I could code the template call as: {{FadedPage|id=Fleming,%20Ian|name=Ian Fleming|author=yes}} which works OK but I would rather have the call format as it looks on the fadedpage website, ie. with the embedded space. So I need a way in lua to find the space character within the string and substitute it for the string "%20". So far I haven't figured out how to do it. Any help would be appreciated.

Prevent Ruby from changing & to &?

I need to display some superscript and subscript characters in my webpage title. I have a helper method that recognizes the pattern for a subscript or superscript, and converts it to &sub2; or ²
However, when it shows up in the rendered page's file, it shows up in the source code as:
&sub2;
Which is not right. I have it set up to be:
<% provide(:title, raw(format_title(#hash[:page_title]))) %>
But the raw is not working. Any help is appreciated.
Method:
def format_title(name)
label = name
if label.match /(_[\d]+_)+|(~[\d]+~)+/
label = label.gsub(/(_([\d]+)_)+/, '&sub\2;')
label = label.gsub(/(~([\d]+)~)+/, '&sup\2;')
label.html_safe
else
name
end
end
I have even tried:
str.gsub(/&/, '&')
but it gives back:
&amp;sub2;
You can also achieve this with Rails I18n.
<%= t(:page_title_html, scope: [:title]) %>
And in your respective locale file. (title.en.yml most probably):
title:
page_title: "Title with ²"
Here is a chart for HTML symbols regarding subscript and superscripts.
For more information check Preventing HTML character entities in locale files from getting munged by Rails3 xss protection
Update:
In case you need to load the page titles dynamically, first, you'll have to install a gem like Page Title Helper.
You can follow the guide in the gem documentation.
There are two of issues with your example, one is of matter and the other is just a coincidence.
The first issue is you are trying to use character entities that do not actually exist. Specifically, there are only ¹, ² and ³ which provide 1, 2 and 3 superscript symbols respectively. There is no such character entity as &sup4; nor any other superscript digits. There are though bare codepoints for other digits which you can use but this would require a more involved code.
More importantly, there are no subscript character entities at all in HTML5 character entities list. All subscript digits are bare codepoints. Therefore it makes no sense to replace anything with &sub2; or any other "subscript" digit.
The reason you didn't see your example working is due to the test string you chose. Supplying anything with underscores, like _2_mystring will be properly replaced with &sub2;. As &sub2; character entity is non-existent, the string will appear as is, creating an impression that raw method somehow doesn't work.
Try to use ~2~mystring and it will be replaced with the superscript character entity ² and will be rendered correctly. This illustrates that your code correct, but the basic assumption about character entities is not.

Linking on a Redmine Wiki

I'm writing a wiki on Redmine for the program my company just developed. I've been reading Redmine Wiki formatting pages but I simply can't find how to link to headers on a page that hold spaces.
For example:
This works [[Setup#Oracle|Oracle Setup]]
This does not work [[Setup#Oracle DB|Oracle DB Setup]]
The second I have a header with a space, hyphen, underscore... ANYTHING more than one word, Redmine is unable to link.
Any ideas how to link correctly?
Hyphens worked for me using the textile formatting.
[[Wiki#Test-link-target|a link]]
If you open the wiki page you should see a little paragraph symbol next to each header that appears when you hover your mouse there. That should give you the (semi-)permalink you can use. You can always look at the wiki pages source for the link names.
One problem I remember when working on the Markdown filter was that each text formatter would create it's table of contents separately. So the anchor links for textile might be different than the ones for plain text or Markdown.

Resources