W
W
weranda2015-08-17 10:56:39
PHP
weranda, 2015-08-17 10:56:39

How to implement automatic output of links in the presence of headings in the content?

Greetings.
There is material content:

<p>какой то текст...</p>
<p>какой то текст...</p>

<h2>ЗАГОЛОВОК 1</h2>
<p>какой то текст...</p>
<p>какой то текст...</p>

<h2>ЗАГОЛОВОК 2</h2>
<p>какой то текст...</p>
<p>какой то текст...</p>

How to implement automatic generation of heading navigation output at the beginning of the article so that when saving the document, it is parsed for the presence of headings (subheadings) in it and links to headings are displayed at the beginning of the article?
To make it look like this:
<a href="#anchor1">ЗАГОЛОВОК 1</a>
<a href="#anchor2">ЗАГОЛОВОК 2</a>

<p>какой то текст...</p>
<p>какой то текст...</p>

<a id="anchor1"> </a>
<h2>ЗАГОЛОВОК 1</h2>
<p>какой то текст...</p>
<p>какой то текст...</p>

<a id="anchor2"> </a>
<h2>ЗАГОЛОВОК 2</h2>
<p>какой то текст...</p>
<p>какой то текст...</p>

I'll explain in more detail. There is content of the material - text and headings (h2, h3, h4). It is necessary to make it so that when saving, an anchor is inserted before the heading, and at the beginning of the article, links to these anchors with the contents of the heading are displayed.
Is this possible? If yes, please tell me how, with the help of what, in what way, where and what to read and an example?
REVO

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Zuev, 2015-08-17
@weranda

Example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question