Cláudia
Cláudia

Reputation: 85

How do I create a link to a certain word in markdown?

I am creating the specification for an ontology in Markdown and I have several tables for its classes and properties. When a class is a subclass of another class I want to have a link of the table entry of the super class in the subclass definition. Something like this:

Class Description Subclasses
X Some Description Y
Y Another Description -

I want the column "Subclasses" to have links to other table entries. How can I do it?

Upvotes: 6

Views: 7410

Answers (1)

Waylan
Waylan

Reputation: 42637

You need to create an ID (or name) to link to. This can be accomplished with raw HTML.

As a reminder, Markdown is a subset of HTML. In HTML you can link to any element which has a unique ID attribute set. However, Markdown does not provide a standard way to set an ID on an element. Some extensions may provide nonstandard ways to do this, but without knowing which implementation you are using, we are only left with reverting to raw HTML. Like this:

| Class                 | Description         | Subclasses |
|:--------------------- |:-------------------:| ----------:|
| X                     | Some Description    | [Y](#Y)    |
| <span id="Y">Y</span> | Another Description | -          |

Note the <span> element which wraps the Y and sets an ID to Y. This can then be linked to with the URL #Y from anywhere within the document and with path/to/filename.ext#Y from outside the document.

Finally, I should note that this does not actually work here on StackOverflow as the span element (and its ID) are stripped by their sanitizer for security reasons. However, if no security measures are in place in the environment you are using this, it should work fine.

Upvotes: 7

Related Questions