trilbymedia / grav-plugin-page-toc Goto Github PK
View Code? Open in Web Editor NEWGrav TOC Plugin with new independent Anchor generation to compliment the existing Table-of-Contents support.
License: MIT License
Grav TOC Plugin with new independent Anchor generation to compliment the existing Table-of-Contents support.
License: MIT License
Setting "starting header tag" to greater value than H1 (e.g. H3) leads to multiple bullets on first line (3 bullets for H3) on toc display.
I would expect only 1 bullet.
I'd like to translate 'Table of Contents' in page-toc.html.twig
Can it be done, and if so, where exactly do I put the modified page-toc.html.twig
in my inherited theme?
Or have I misunderstood:
This will replace the shortcode syntax with the Table of Contents with the components/page-toc.html.twig Twig template. Either the default one included in the page-toc plugin or an overridden version from your theme.
If the Page Toc Plugin is enabled, then page-level Twig cannot be processed, specifically links ...<a href="{{ page.url|e }}">...
and resources ...<img src="{{ img.url|e }}">...
. The escaped code is returned instead of the URL.
Edit 06/16/2022: Markdown syntax is not processed either, specifically [{{ page.title|e }}]({{ page.url|e }})
and ![{{ img.title|e }}]({{ img.url|e }})
.
More info: getgrav/grav#3589.
I installed this plugin and found that my implementation of multiple columns (based on this recipe) stopped working. After some digging, I discovered the reason for this is that this plugin changes the HTML rendering of the markdown ---
from <hr />
to <hr>
. Is there a reason for this change? Can it be documented somewhere?
Hello
It is possible to change the title "Table of Contents" (translate it) ?
I dont find the option or parameters in files...
Thanks
When upgrading from 3.0.0 to 3.1.0 I (only now) noticed double anchors on my website. This is because I also use the official plugin Anchors. Since I don't see the point in having this twice, but I do want to keep anchors elsewhere, I decided to disable them in the TOC plugin.
After saving those settings my site crashes with the error below:
"Argument 2 passed to Grav\Plugin\PageToc\MarkupFixer::traverseHeaderTags() must be of the type int, string given, called in /var/www/vhosts/example.com/www.example.com/user/plugins/page-toc/classes/MarkupFixer.php on line 57 ◀"
When restoring the anchor settings in the TOC plugin and refreshing the same error persisted. I now have the TOC disabled to keep my website functional.
In my user/config/plugins/page-toc.yaml
is the following:
enabled: true
active: false
start: '2'
depth: '6'
Other than that, no custom changes enabled.
Hi, what would be the preferred way to make a TOC collapsible/extendable? Like an accordion, so that you can hide its content if you don't need it.
TIA,
Marco
When one (like me) doesn;t include any h1 levels (# My h1 heading
) in the page content, the generated html incorrectly does insert an empty first level li (which is rendered ugly in default Quark). I haven't had the time to look at the PHP code yet, but I guess it should be doable to make the output dependant of the real number of heading levels in the page?
## First heading
Text
### Sub heading
Text
## Second heading
Text
<ul>
<li class="first last">
<span></span>
<ul class="menu_level_1">
<li class="first">
<a href="#firstheading">First heading</a>
<ul class="menu_level_2">
<li class="first">
<a href="#subheading">Sub heading</a>
</li>
</ul>
</li>
<li>
<a href="#secondheading">Second heading</a>
</li>
</ul>
</li>
</ul>
<ul>
<li class="first last">
<a href="#firstheading">First heading</a>
<ul class="menu_level_1">
<li class="first">
<a href="#subheading">Sub heading</a>
</li>
</ul>
</li>
<li>
<a href="#secondheading">Second heading</a>
</li>
</ul>
</li>
</ul>
Learn4 theme.
When I use in chapter.md
:
page-toc:
active: false
Then all child docs
become without TOC.
How to disable TOC for the chapter without activating in every child page?
Twig template doesn't affect anchor generation...
0 - Argument 1 passed to Knp\Menu\Renderer\ListRenderer::render() must implement interface Knp\Menu\ItemInterface, array given, called in ../public/user/plugins/page-toc/vendor/caseyamcl/toc/src/TocGenerator.php on line 153
This error shows when I enter an empty page.
Hello :-)
Thank you for this plugin! Been using it for a while and very happy with it. I do have a minor issue which I cannot pinpoint why it happens. Can you point me in the right direction to fix this?
Just before the actual TOC, (and after <h4></h4>
) I get this: <ul><li class="first last"><span></span>
<div class="page-toc">
<h4>Table of Contents</h4>
<ul><li class="first last"><span></span>
<ul class="menu_level_1">
<li class="first"><a href="#introduction">Introduction</a></li>
<li><a href="#what-is-a-domain-name">What is a Domain name?</a></li>
<li><a href="#extensions">Extensions</a>
<ul class="menu_level_2">
<li class="first"><a href="#original-tld-s">Original TLD's</a></li>
<li><a href="#country-tld-s">Country TLD's</a></li>
<li class="last"><a href="#vanity-tld-s">Vanity TLD's</a></li>
</ul>
</li>
</ul>
Using this plugin in modular pages doesn't seem to produce anchors for headers that come from modules.
Is this a known limitation?
Hello,
Currently I have the Anchors plugin installed on my site and I was looking to use the TOC plugin as well, I just wonder if they are compatible or if they will be fighting to generate different anchors.
Thanks for your time!
After updating to grav-plugin-page-toc-3.2.2.zip the sublevels of my page are no longer displayed.
markdown of page
[toc]
### Portaal
....
#### Stappenplan
### Demonstratievideo's
#### Overstappen op het portaal
....
#### Inloggen in LRP via het portaal
...
#### Tweede / volgende rol koppelen aan portaal-account
...
#### Gebruikersnaam (e-mail) van het portaal wijzigen
...
### Zie ook
#### Gebruikersnaam vergeten
...
#### Wachtwoord vergeten
...
#### Nieuwe telefoon
...
#### 2FA resetten
...
#### installeren 2FA-app / authenticatie-app
...
### Veelgestelde vragen
...
I can't get the plugin to work
I'm testing a blank Grav CMS installation in which only the page-toc plugin has been added.
I've modified the Home page by adding at the top: [toc]
Here's the result:
There is only one level the highest.
The file www/user/plugins/page-toc/page-toc.yaml is unchanged and contains:
enabled: true # Plugin enabled
include_css: true # Include CSS
active: true # Anchor IDs processed and generated for all pages
start: 1 # Start header tag level (1 = h1) for TOC
depth: 6 # Depth from start (2 = 2 levels deep) for TOC
hclass: # Custom Header TOC styling classes
anchors: # Anchor configuration
start: 1 # Start header tag level (1 = h1)
depth: 6 # Depth from start (2 = 2 levels deep)
link: true # Enabled auto-generation of clickable link with fragment
aria: Anchor # Aria label to use
class: # Custom Header anchor styling classes
icon: '#' # Icon to use, can be a symbol, emoji, ascii etc.
position: after # Position to put the anchor,before|after
copy_to_clipboard: false # Copy to clipboard functionality
slug_maxlen: 25 # Max length of slugs used for anchors
slug_prefix: # A prefix used in front of generated slugs
Copying user/plugins/page-toc/page-toc.yaml
to user/config/plugins/page-toc.yaml
doest no help.
I've tried several times, but there's never more than one level in the Table of contents.
Thank you in advance for your help.
Jean-Louis
(Probably not a bug but I didn't know where to post this)
Sorry for this question, but I've spent some hours on trying to achieve the result that my TOC, generated by page-toc
, is inlined just after the <h1>...</h1>
block so that it appears as if the TOC was made as part of the given page.
I am very feeble in the art of TWIG and coding up Grav, so is this something I should forget about? I've made minor adjustments in my own theme, which derives from the Quark theme, but I just don't seem to be able to get any TOC output anywhere, whatsoever :-)
The plugin is active, configurable, and locally set active in the front matter. Please let me know if you need more information.
Thanks in advance. By the way, if you don't answer questions here, please just close the issue and sorry for the interruption.
The code found in the Usage section of the README needs a |raw
to work with the latest Grav.
E.g.: {{ table_of_contents|raw }}
After updating to version 3.2.1 I get an error on my page.
The cause is the character ⌘ in the text.
After returning to version 3.2.0, the error does not occur.
PHP Version 7.4.30
errorlog
/home/mydomain/domains/sub-domain.domain.nl/public_html/system/src/Grav/Common/Debugger.php(843): Whoops\Run->handleError()
[internal function]: Grav\Common\Debugger->deprecatedErrorHandler()
/home/mydomain/domains/sub-domain.domain.nl/public_html/user/plugins/page-toc/classes/HtmlHelper.php(34): iconv()
/home/mydomain/domains/sub-domain.domain.nl/public_html/user/plugins/page-toc/classes/MarkupFixer.php(46): Grav\Plugin\PageToc\MarkupFixer->getHTMLParser()
/home/mydomain/domains/sub-domain.domain.nl/public_html/user/plugins/page-toc/page-toc.php(97): Grav\Plugin\PageToc\MarkupFixer->fix()
/home/mydomain/domains/sub-domain.domain.nl/public_html/vendor/symfony/event-dispatcher/EventDispatcher.php(264): Grav\Plugin\PageTOCPlugin->onPageContentProcessed()
/home/mydomain/domains/sub-domain.domain.nl/public_html/vendor/symfony/event-dispatcher/EventDispatcher.php(239): Symfony\Component\EventDispatcher\EventDispatcher->doDispatch()
/home/mydomain/domains/sub-domain.domain.nl/public_html/vendor/symfony/event-dispatcher/EventDispatcher.php(73): Symfony\Component\EventDispatcher\EventDispatcher->callListeners()
/home/mydomain/domains/sub-domain.domain.nl/public_html/system/src/Grav/Common/Grav.php(597): Symfony\Component\EventDispatcher\EventDispatcher->dispatch()
/home/mydomain/domains/sub-domain.domain.nl/public_html/system/src/Grav/Common/Page/Page.php(817): Grav\Common\Grav->fireEvent()
Hello,
Thanks for your TOC PHP integration.
I want your TOC under my pages menu.
for example :
i don't really understand why it's not working with that :
<li class="nav-item {{ current_page }}">
{% for page in pages.children.visible %}
{% set current_page = (page.active or page.activeChild) ? 'active' : '' %}
<a class="nav-link" href="{{ page.url }}">
{{ page.menu }}
</a>
{% if config.get('plugins.page-toc.active') or attribute(page.header, 'page-toc').active %}
<div class="page-toc">
{% set table_of_contents = toc(page.content) %}
{% if table_of_contents is not empty %}
{{ table_of_contents }}
{% endif %}
</div>
{% endif %}
{% endfor %}
</li>
Of course if i put your plugins like that it's works but TOC is not in the good position.
<li class="nav-item {{ current_page }}">
{% for page in pages.children.visible %}
{% set current_page = (page.active or page.activeChild) ? 'active' : '' %}
<a class="nav-link" href="{{ page.url }}">
{{ page.menu }}
</a>
{% endfor %}
</li>
{% if config.get('plugins.page-toc.active') or attribute(page.header, 'page-toc').active %}
<div class="page-toc">
{% set table_of_contents = toc(page.content) %}
{% if table_of_contents is not empty %}
{{ table_of_contents }}
{% endif %}
</div>
{% endif %}
Can you help me ?
I just ran a bunch of updates on one site where I use this plugin. The table of contents didn't show up any more, and after some digging now I found out that toc(page.content)
simply returns empty. I have no idea why, I already took other plugins out of the equation. What could be the issue here?
I put this bit in my base.html.twig
template (and it used to work like this):
{% set table_of_contents = toc(page.content) %}
{% if table_of_contents is not empty %}
<h2 id="headline-toc">Auf dieser Seite:</h2>
{{ table_of_contents|raw }}
{% endif %}
Many thanks for your help!
When attempting to install, Grav reports
One of the packages require Grav >=1.7.26. Please update Grav to the latest release.
Grav web site indicates 1.7.25 is the latest stable release.
https://github.com/trilbymedia/grav-plugin-page-toc/releases/tag/3.2.3
fix the TOC, now I show H2,H3... in the TOC (not only H1)
... But my page is badly encoding the characters !
This only affect the content/body of my article...
Not the title
All works fine when this plugin v.3.2.3
is disabeled...
You can see the result into my work in progress GRAV here :
https://dn.vincent-bonnefille.fr/a/un_jardin
Example :
Lost garden => �©conomie de l'attention
should be :
Lost garden => Économie de l'attention
It the same under Chromium / Firefox
I follow this to try a fix by myself
getgrav/grav#1437
document.characterSet
in my browserUTF-8
"<meta charset="utf-8">
Thanks for all,
your work and time
all links coming in grav plugin admin are dead links referring to https://github.com/getgrav/grav-plugin-page-toc
I was working on highlighting for anchor links in viewport and realized js throws an error for id's beginning with a number. Maybe it could be an option to replace/append leading numbers with a character?
Using the sample code in the readme:
Ut sed nisl suscipit metus sollicitudin [anchor]<span>ornare</span>[/anchor] nec vitae nulla. In pretium massa ex, in [anchor="vulputate"]vulputate tellus[/anchor] accumsan vel.
Nullam [anchor id="tempor"]tempor quis lorem[/anchor] venenatis finibus. Curabitur dapibus nulla sed tristique pretium. Nullam tempor quis [anchor prefix="sec2.2-"]lorem venenatis finibus[/anchor].
This is the HTML output I get in v. 3.2.2
<p>Ut sed nisl suscipit metus sollicitudin <a id="" href="#" class="inline-anchor" aria-label="Anchor"><span>ornare</span></a> nec vitae nulla. In pretium massa ex, in <a id="vulputate" href="#vulputate" class="inline-anchor" aria-label="Anchor">vulputate tellus</a> accumsan vel. </p>
<p>Nullam <a id="tempor" href="#tempor" class="inline-anchor" aria-label="Anchor">tempor quis lorem</a> venenatis finibus. Curabitur dapibus nulla sed tristique pretium. Nullam tempor quis <a id="sec2.2-" href="#sec2.2-" class="inline-anchor" aria-label="Anchor">lorem venenatis finibus</a>.</p>
As opposed to v. 3.0.0 when the feature was introduced:
<body id="toc_generator_6572fb87d779b"><p>Ut sed nisl suscipit metus sollicitudin <a id="ornare" href="#ornare" class="inline-anchor" aria-label="Anchor"><span>ornare</span></a> nec vitae nulla. In pretium massa ex, in <a id="vulputate" href="#vulputate" class="inline-anchor" aria-label="Anchor">vulputate tellus</a> accumsan vel. </p>
<p>Nullam <a id="tempor" href="#tempor" class="inline-anchor" aria-label="Anchor">tempor quis lorem</a> venenatis finibus. Curabitur dapibus nulla sed tristique pretium. Nullam tempor quis <a id="sec2.2-lorem-venenatis-finibus" href="#sec2.2-lorem-venenatis-finibus" class="inline-anchor" aria-label="Anchor">lorem venenatis finibus</a>.</p></body>
Evidently, the no-options and prefix variants are not picking up the text from inside the shortcode.
I'm using Grav v1.7.43 - PHP 8.3.0.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.