Skip to content

Add anchors for headings in handbook pages#115

Open
richardswain wants to merge 1 commit into
mainfrom
115-add-anchors
Open

Add anchors for headings in handbook pages#115
richardswain wants to merge 1 commit into
mainfrom
115-add-anchors

Conversation

@richardswain

Copy link
Copy Markdown

When deep-linking handbook content it's not easy to get a URL directly to the relevant heading ie:

  1. Page https://handbook.hmn.md/working-here/continuous-improvement/personal-development-plan/
  2. Relevant heading of interest HOW AND WHEN SHOULD I UPDATE MY PDP?
  3. There is no way for readers to quickly get a link to sub-content or headings.

Why this is useful? When sharing specific handbook information (policies, or specific policies etc) we will share the page link, then tell the person to scroll to x heading. So much mental weight can be lifted by matching the reader experience with current day expectations.

Related: humanmade/h2#418 however - the code there may not be instantly portable.

@richardswain

Copy link
Copy Markdown

@tareiking Does this work for you?

Comment thread functions.php
* @return string $content The filtered post content.
*/
function anchor_content_headings( $content ) {
$content = preg_replace_callback( "/\<h([1|2|3|4|5])\>(.*?)\<\/h([1|2|3|4|5])\>/", function ( $matches ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no guard to prevent this matching a heading which already contains linked text, and a link cannot appear inside a link so one of them would break.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants