Summary generator in a web page
This script works locally or directly on a server and builds a static menu from the titles and subtitles in an HTML page. It avoids a tedious job.
For each heading it generates an identifier or takes into account any existing identifier, then it builds a hierarchical menu from the titles and places in the menu links on the subtitles in the page.
You can later change the structure of the page and automatically update the menu.
The Scriptol syntax is:
solp automenu [-hn] [path]filename
php automenu.php [-hn] [path]filename
The option corresponds to the level of hierarchy to be taken into account to build the menu, the default for the deepest level is h3, and you can specify from h2 to h6.
The menu is presented in a fieldset with the caption "Summary". You can change this default caption by changing the value of the legend variable in the source code in Scriptol:
legend text = "Summary"
In the PHP code:
$legend = "Summary";
To go further, for example replace the fieldset by a layer or to associate attributes, you have to the code in the main function.
How it works
The creation of the menu goes through the following steps:
- Scanning the page to identify the numbers already in use, so you do not reuse a number that is already underway for the generation of identifiers.
- An identifier is generated and added to each title.
- The titles are taken from the page and placed in a table.
- From this table, the script builds a hierarchical and indented menu, with links to sections in the content.
- This menu is inserted after the tag <h1>.
You can then manually move it where you want in the page.
- During an update, the menu is changed in the same location.
Conditions and limitations
For best results, the page should be well-formed with a hierarchy of titles <h1>, <h2>, <h3>, etc.. according to their destination.
The result will be random if one uses these tags in the side panels, or for other purposes than the semantic structure, which is a practice discouraged.
Identifiers must have the tag name in prefix. For example H221, h322, etc. ... It is essential for proper indentation. These names are generated automatically by the software unless an identifier already exists.
License and credit
The script written by Denis Sureau is under GPL 3.0
The script uses the Simple HTML parser by Jose Solorzano (https://sourceforge.net/projects/php-html/). This parser is under the MIT license.