TextformatterRockHeadlineIDs by bernhard

TextformatterRockHeadlineIDs

A message to Russian �� people


If you currently live in Russia, please read this message.

SWUbanner


Textformatter that applies id attributes to all headlines (h1-h6) in the markup field.

// input
<h1>This is my headline</h1>
// output
<h1 id='this-is-my-headline'>This is my headline</h1>

What if an id already exists?


If an id already exists in the input it will leave this id as is:

// input
<h1 id='foo'>foo</h1>
<h2>bar</h2>
// output
<h1 id='foo'>foo</h1>
<h2 id='bar'>bar</h2>

What if an id is used twice?


It will automatically apply dashes until the id is unique:

// input
<h1>foo</h1>
<h2>foo</h2>
<h3>foo</h3>
// output
<h1 id='foo'>foo</h1>
<h2 id='foo-'>foo</h2>
<h3 id='foo--'>foo</h3>

What about special characters?


Special characters will be sanitized according to your transliterate settings:

// input
<h1>Sehr schön</h1>
// output
<h1 id='sehr-schoen'>Sehr schön</h1>

Customize


You can customize the generated ID via hooking into getID:

$wire->addHookAfter("TextformatterRockHeadlineIDs::getID", function($event) {
  $event->return .= "-hooked";
});
// input
<h1>foo</h1>
// output
<h1 id='foo-hooked'>foo</h1>

Debugging


You can use tracy to debug this formatter:

img

Install and use modules at your own risk. Always have a site and database backup before installing new modules.

Latest news

  • ProcessWire Weekly #549
    In the 549th issue of ProcessWire Weekly we’re going to check out the latest core updates, highlight one older yet still very relevant third party module, and more. Read on!
    Weekly.pw / 17 November 2024
  • Custom Fields Module
    This week we look at a new ProFields module named Custom Fields. This module provides a way to rapidly build out ProcessWire fields that contain any number of subfields/properties within them.
    Blog / 30 August 2024
  • Subscribe to weekly ProcessWire news

“We chose ProcessWire because of its excellent architecture, modular extensibility and the internal API. The CMS offers the necessary flexibility and performance for such a complex website like superbude.de. ProcessWire offers options that are only available for larger systems, such as Drupal, and allows a much slimmer development process.” —xport communication GmbH