Thornily
Thornily

Reputation: 584

Adding anchors to Markdown section results in incomplete HTML fragments in section titles in the rendered Markdown

When i try to use this code

# Table of contents
1. [Introduction](#introduction)
2. [Some paragraph](#paragraph1)
    1. [Sub paragraph](#subparagraph1)
3. [Another paragraph](#paragraph2)

## This is the introduction <a name="introduction"></a>
Some introduction text, formatted in heading 2 style

## Some paragraph <a name="paragraph1"></a>
The first paragraph text

### Sub paragraph <a name="subparagraph1"></a>
This is a sub paragraph, formatted in heading 3 style

## Another paragraph <a name="paragraph2"></a>
The second paragraph text

I get this as the output.

Introduction
Some paragraph
Sub paragraph
Another paragraph
" class="reference-link">This is the introduction
Some introduction text, formatted in heading 2 style

" class="reference-link">Some paragraph
The first paragraph text

" class="reference-link">Sub paragraph
This is a sub paragraph, formatted in heading 3 style

My question is can I get rid of the class="reference-link"> bit?

For my editor, I am using an online editor called ipandao http://editor.md.ipandao.com/#introduction.

I don't know if its just the editor, or a piece of my code. Because I am very new to markdown (.md)

Upvotes: 3

Views: 98

Answers (2)

charlesreid1
charlesreid1

Reputation: 4821

Move the <a> tags to the line before the title they are supposed to anchor to, like this:

# Table of contents
1. [Introduction](#introduction)
2. [Some paragraph](#paragraph1)
    1. [Sub paragraph](#subparagraph1)
3. [Another paragraph](#paragraph2)

<a name="introduction"></a>
## This is the introduction 
Some introduction text, formatted in heading 2 style

<a name="paragraph1"></a>
## Some paragraph
The first paragraph text

<a name="subparagraph1"></a>
### Sub paragraph
This is a sub paragraph, formatted in heading 3 style

<a name="paragraph2"></a>
## Another paragraph
The second paragraph text

I tested this out on ipandao and it got rid of the class reference link fragment you were seeing, and the anchor links work great too.

Upvotes: 1

selfagency
selfagency

Reputation: 1578

Markdown compilers often have built-in rules to automatically add generated IDs or classnames to headers. You need to tell your compiler to not autogenerate the IDs and classnames or use the autogenerated ones instead.

Upvotes: 0

Related Questions