Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there an option to remove "numbered" prefixes for headings' anchors? #21

Open
lazharichir opened this issue Mar 9, 2023 · 1 comment
Assignees
Labels

Comments

@lazharichir
Copy link

Wondering what you would recommend to automatically remove the "1. " or "1) " of the headings from the slugified anchor?

For instance, so that <h2>1. How To Do This</h2> becomes <h2 id="how-to-do-this">1. How To Do This</h2> and not <h2 id="1-how-to-do-this">1. How To Do This</h2>?

@caseyamcl caseyamcl self-assigned this Mar 9, 2023
@caseyamcl
Copy link
Owner

Hi @lazharichir,

There is no "batteries included" way, but there is indeed a way to do this if you're willing to do a bit of extra coding.

You can extend the UniqueSlugify class and override the slugify method with your own implementation; something like this:

use TOC\UniqueSlugify;

class MySlugifier extends UniqueSlugify
{
    public function slugify($string, $options = null): string
    {
        // write your own logic to remove the numeric prefix here...

        parent::slugify($string, $options);
    }
}

Then, when instantiating the MarkupFixer class, simply pass your own instance of the Slugifier to the constructor:

$markupFixer  = new TOC\MarkupFixer(null, new MySlugifier());

Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants