diff --git a/README.md b/README.md index 79e983a..1ad5cf6 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ Laravel Table of Content Generator Generates a Table of Contents from ***H1...H6*** Tags in HTML Content - This package provides a simple library to build a Table-of-Contents from HTML markup. It does so by evaluating your *H1...H6* tags. It can also automatically add appropriate *id* anchor attributes to header tags so that in-page links work. @@ -22,7 +21,7 @@ Installation Options Install with composer : -` composer require fxcjahid/laravel-table-of-content ` +`composer require fxcjahid/laravel-table-of-content` Usage ----- @@ -35,24 +34,37 @@ This package contains two main classes: Basic Example: ```php -$myHtmlContent = <<This is a header tag with no anchor id -

Lorum ipsum doler sit amet

-

This is a header tag with an anchor id

-

Stuff here

-

This is a header tag with an anchor id

+use Fxcjahid\LaravelTableOfContent\Table; +use Fxcjahid\LaravelTableOfContent\MarkupFixer; + +$content = <<This is heading H2 +

This is heading H3

+

This is heading H4

+

This is heading H1

END; -$markupFixer = new MarkupFixer(); -$tocGenerator = new Table(); -// This ensures that all header tags have `id` attributes so they can be used as anchor links -$htmlOut = "
" . $markupFixer->fix($myHtmlContent) . "
"; +/** + * Get Markup tag fixies + */ + +$getFixContent = $markup->fix($content); + +/** + * Get Table Of content + * Levels 1-6 (It's will skip heading tag) + */ + +$getTableOfContent = $toc->getTableContent($getFixContent, 2); + + +$htmlOut = "
" . $getFixContent . "
"; +$htmlOut .= "
" . $getTableOfContent . "
"; + +return $htmlOut; -// This generates the Table of Contents in HTML -$htmlOut .= "
" . $tocGenerator->getHtmlMenu($htmlOut) . "
"; -echo $htmlOut; ``` This produces the following output: @@ -109,8 +121,9 @@ use Fxcjahid\LaravelTableOfContent\MarkupFixer; /** * Get Table Of content + * Note: without ID arttibutes Table can't generate */ - $getTableOfContent = $toc->getTableContent($content); + $getTableOfContent = $toc->getTableContent($getFixContent); $htmlOut = "
" . $getFixContent . "
"; $htmlOut .= "
" . $getTableOfContent . "
";