Cookbook /
CountBetweenMarkers
Summary:
Summary: Count the number of lines between two markers inside a wiki page
Version: 20260123
Prerequisites: PmWiki 2.2.0 or later, PHP 8.0 or later
Status: Stable
Maintainer: Holger Kremb
License: GPL-3.0-or-later
Discussion: CountBetweenMarkers-Talk
Compatibility
- Tested with PHP 8.5.2
- Last tested on PmWiki 2.5.5
Questions answered by this recipe
- How can I count the number of lines between two markers on a page?
- How can I count lines between markers on another page?
- How can I avoid marker duplication when using anchors?
Description
This recipe provides a markup directive to count the number of text lines between two markers on a wiki page. It is useful for documentation statistics, validation of structured sections, or technical overviews where only parts of a page should be evaluated.
Markers are passed in a protected form to avoid duplication when PmWiki renders anchors.
Installation
- Download countbetweenmarkers.zipΔ
- Copy countbetweenmarkers.php into your cookbook/ directory
- Add the following line to config.php: include_once("$FarmD/cookbook/countbetweenmarkers.php");
Usage
Basic usage on the current page:
(:pmlinecount start="[[#Pm_Start]]" end="[[#Pm_End]]":)
Count lines on another page:
(:pmlinecount page=Group.Page start="[[#Pm_Start]]" end="[[#Pm_End]]":)
The result is the number of text lines found between the two markers.
Notes
- The prefix Pm_ must be used in marker names to prevent anchor duplication.
- Marker names are arbitrary.
- Anchors in the page can be named freely, e.g. #Foo and #Bar; in the directive call use [[#Pm_Foo]] and [[#Pm_Bar]].
- In the directive call, prefix marker names with Pm_ (e.g. ) to prevent anchor duplication.
- Empty or missing markers return no output.
- Counts raw page text lines; visual line wrapping is ignored.
Change log / Release notes
- 2026/01/25 – Initial public release
See also
Contributors
- Holger Kremb
Comments
See discussion at CountBetweenMarkers-Talk
User notes : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.