cebe / markdown

A super fast, highly extensible markdown parser for PHP
http://markdown.cebe.cc/
MIT License
997 stars 141 forks source link

Get all headings for table of contents #174

Open Wulfheart opened 4 years ago

Wulfheart commented 4 years ago

Hello,

is it possible to get all headings from a string in an extension? I need this for autogenerating a table of contents.

Thank you in advance

cebe commented 3 years ago

There is an implementation of this in yii2-apidoc package:

https://github.com/yiisoft/yii2-apidoc/blob/e56aa1f065e4ece1a68b21de653b02ed0da2dadd/helpers/ApiMarkdown.php#L94-L121

could be useful to extract this into a trait and add it to this package. Happy to review and merge pull requests for this.

akshitagupta20 commented 3 years ago

@cebe Hi, I would like to contribute. How should I proceed?

cebe commented 3 years ago

@akshitagupta20 Hi, thanks for offering help. The solution would be a trait, that can be added to a custom markdown class:

<?php

class MyCustomMarkdown extends Markdown
{
     use HeadlineExtractionTrait;
// ..
}

HeadlineExtractionTrait should be a class from this repo and should contain the code similar to the one linked above, providing the collection of headlines as well as a getHeadlines() method.

Hope that is clear, feel free to ask more detailed question.

akshitagupta20 commented 3 years ago

I am really new with Open-Source and I am very much interested in contributing not just cause of Hacktoberfest, so can you please further guide me how to solve this issue. If you could spare some time, Es wäre eine große Hilfe.

Ayushman00100 commented 2 years ago

@cebe Hi, I would like to contribute. How should I proceed?

cebe commented 2 years ago

I already explained it above, please ask more concrete question.