Proposal
This ticket is a proposal about automatically adding clickable anchor links and table of contents links for documentation headings on Drupal.org.
User Story
As non-developers & newcomers to Drupal we need clickable anchor icons in the documentation pages, so that:
- we can easily and quickly copy a link/url to a specific documentation page section
- we have a visual reminder about available clickable anchor icons
Assumptions
- Assumes the clickable anchor icons is clear and meaningful to all audience. Not just some audience(s).
Options
The following shows options to choose from about clickable anchor icons. To test simply click on any anchor below.
Option 1: Clickable Anchor Character
Example
Section Header ⚓
Examples in context
Code
<h4><a id="option-1---anchor" name="option-1---anchor"></a>Section Header <a href="#option-1---anchor">⚓</a></h4>
Option 2: Clickable Prefix Hastag
Example
# Section Header
Examples in context
Code
<h4><a id="option-2---anchor" name="option-2---anchor"></a><a href="#option-2---anchor">#</a> Section Header</h4>
Option 3: Clickable Hastag Suffix
Example
Section Header #
Examples in context
- TBD
Code
<h4><a id="option-3---anchor" name="option-3---anchor"></a>Section Header <a href="#option-3---anchor">#</a></h4>
Option 4: Full Text Anchor
Example
Writing and contributing documentation
Examples in context
Code
<h4><a id="option-4---anchor" name="option-4---anchor">Writing and contributing documentation</a></h4>
Option 5: Use the TOC
- Don't add visible anchor links to short pages without a TOC
- If a page has a TOC, the items in the TOC are visible anchor links.
Deployed solution
Option 2 with Clickable Prefix Hastag is used in the implementation that has gone live on drupal.org.
Comment | File | Size | Author |
---|---|---|---|
#31 | 2943370-drupalorg-31.patch | 9.84 KB | grasmash |
#31 | 2943370-bluecheese-31.patch | 4.02 KB | grasmash |
#7 | Schermafbeelding 2018-04-02 om 14.58.02.png | 98.02 KB | bertboerland |
Comments
Comment #2
FrancewhoaAdded "Issue summary"
Comment #3
Francewhoa@Francewhoa :) Note to myself. To facilitate cross-ticket communications, added invisible anchors.
Comment #4
FrancewhoaHi drumm :) Thanks for all your Drupal contributions. This is my reply to your comment #9
I added a summary of options here. Those were some of the end results of some general consensus about clickable anchors. Each option include link to real example(s). Including those contributed by hansfn.
BTW those past discussions were spread over multiple channels. Including but not limited to IRC, documentation comments, forum comments, and so on. And spreading years. I would love to go dig each one of those, but that's not realistic with my present workload. Speaking for myself I don't need those past discussions. I propose we focus our effort on the present audiences needs. But if you really need all of those past discussion you're welcome to dig in, search, compile, and add them to this ticket :)
That's also my understanding. I also recall that initially the clickable anchor icons were hashtags #, those were used years back, the ⚓️ emoji came in later, and replaced the hashtags in a specific context. Which include and is limited to the documentation book and their sub-pages for newcomers and non-developers, which are listed in the "Scope" section.
I was not proposing to standardized the clickable anchor icons. I'm assuming hansfn was proposing this. I will let him clarify his proposal. Speaking for myself I proposed this User Story and its Assumptions.
Comment #5
hansfn CreditAttribution: hansfn commentedI think drumm's and my reaction comes from the fact that we expected "past discussions" to be a discussion in the drupal.org issue queue - with a conclusion. Anyway, let's focus on the task at :-)
I'll add a 5 option to the summary:
I wonder if the first point, "Don't add visible anchor links to short pages without a TOC" could be a general rule.
Have to run!
Comment #6
hansfn CreditAttribution: hansfn commentedComment #7
bertboerland CreditAttribution: bertboerland commentedif you want to have visual anchors, I like the way http://guide.bash.academy/inception/ is doing it. otherwise, the making jist the title clickable is the norm.
Comment #8
grasmash CreditAttribution: grasmash commentedI'm adding the "Documentation Initiative" tag as this is a related UX improvement related.
I'd like to cast a vote for 2 things:
Comment #9
ressa CreditAttribution: ressa at Ardea commentedTo make maintenance easier, how about adding anchors as well as TOC automatically, based on h2, h3 and h4 headers on a page?
@bertboerland's example of visualization in #7 at http://guide.bash.academy/inception/ is interesting, not only because it uses automatic anchors and TOC, generated from h2, h3 or h4 headers, from this script: https://guide.bash.academy/js/main.js
Scripts disabled
Scripts enabled
From: http://guide.bash.academy/inception/
Comment #10
hansfn CreditAttribution: hansfn commentedJust a comment about automatic TOC and clickable anchors: Great, really great, but numeric anchor IDs aren't stable. We should use anchors IDs based on heading text which are slightly more stable since they only change if someone changes the text. Numeric anchors change every time someone adds or remove a heading (at the same level).
Maybe the golden middle way could be to insert anchors manually for the headings that we know will be linked to from Drupal core itself or other documentation, and use autmatic numeric anchors for the rest? (The script should use any existing anchors, only generate when missing.)
Comment #11
ressa CreditAttribution: ressa at Ardea commentedI agree, numerical anchors are inferior to the more stable header, as seen at Wikipedia:
https://en.wikipedia.org/wiki/Protein#Cell_signaling_and_ligand_binding
Comment #12
grasmash CreditAttribution: grasmash commentedTrying to consolidate this conversation into a list of requirements:
The requirements appear to be:
Agree or disagree?
Comment #13
ressa CreditAttribution: ressa at Ardea commentedThanks for summarizing @grasmash, that looks very good to me. Perhaps it could be added, that the table of content should be indented, helping visualize the hierarchy?
Comment #14
grasmash CreditAttribution: grasmash commentedComment #15
ressa CreditAttribution: ressa at Ardea commentedNice, thanks!
Comment #16
hansfn CreditAttribution: hansfn commentedThe summary in comment 14 looks good. (A detail regarding the TOC: I think we should ignore h5 and below.)
When we "all" agree on this, we should move the issue to the drupal.org queue. Hopefully the needed JavaScript can be added quite quickly.
Comment #17
grasmash CreditAttribution: grasmash at Acquia commentedUpdated reqs as per #16:
All respondents in the last month seem to agree on this list, that would seem to constitute a quorum? I'm moving this issue to Drupal.org Enhancement queue for further work.
Note that the implementation method is not part of the requirements. I'd like someone from the Drupal.org team, with knowledge of its architecture, to provide guidance for how we should implement these requirements. E.g., using javascript vs. text formatters, etc. I'd personally lean toward using a text formatter so that the markup is modified server-side, cached, and delivered to the client in its final form.
Comment #18
grasmash CreditAttribution: grasmash at Acquia commentedIt looks like this issue started as a proposal to manually and optionally add anchor links as a matter of docs standards. It has since evolved into a feature request to automatically generate anchors. Changing title and description to match new state.
Comment #19
grasmash CreditAttribution: grasmash at Acquia commentedComment #20
ressa CreditAttribution: ressa at Ardea commentedI had a look at the available Drupal 7 TOC modules, and if using a text formatter is preferred, as opposed to using javascript, then the TOC Node module might serve as a starting point.
It does not use the title for anchor, but generates a numerical anchor, and also doesn't insert visible anchors at the destination, so these two features have to be added.
Comment #21
drummComment #22
dqdWhile not completely disagreeing, I would like to point to the aspect that this TOCs are actually only small footprints on the clients side but a huge footprint in summary on the servers side while pages are in edit wars. Since Drupal.org has already a huge amount of server side processing in its pockets.
Comment #23
grasmash CreditAttribution: grasmash at Acquia commented@drumm Do you have any pointers for implementation? I'd like to make this issue actionable.
Comment #24
drummThis probably won’t use the text/filter format API, that’s not meant to be context-aware, it doesn’t know what field or content type it is processing.
toc_node looks like it acts on every page load,
toc_node_node_post_render()
, which isn’t ideal, since that does HTML parsing and manipulation.I think a field formatter might be best, especially if the results land in the field cache.
An advantage of server-side processing is that it can attempt to keep anchors going to the same place as revisions are made and headings are edited. toc_node looks like it does this; I haven't dug into the algorithm to see how effective it might be.
Comment #25
grasmash CreditAttribution: grasmash at Acquia commentedI've created a fork of the Table of Contents module and posted it in #2983144: Refactor module to provide and use field formatter.
The fork provides all of the TOC functionality required.
Provides a field formatter for text fields which will:
The rest of the functionality can be achieved with custom styling.
@drumm can you review the implementation in the fork and assert that it is acceptable for Drupal.org? Also, what is the preferred way to use a patched or forked module in the Drupal.org codebase?
I'll follow up with a patch to the drupalorg project once the implementation is approved.
Comment #26
grasmash CreditAttribution: grasmash at Acquia commentedNeed a quick review to determine next steps.
If implementation is approved, this issue will require patches that:
Comment #27
drummInstead of the new library, can we use
filter.module
’sfilter_dom_load()
and related functions?Comment #28
grasmash CreditAttribution: grasmash at Acquia commentedI was not aware of filter_dom_load(), I'll look into it.
Comment #29
grasmash CreditAttribution: grasmash at Acquia commentedI think that using DOMDocument, which used by filter_dom_load(), would limit the functionality of the module.
From what I can tell, it's not possible to use CSS selectors like "h2.toc" with DOMDocument. We'd need to limit selector specification to _only_ class or _only_ tag, and the parsing would be much clunkier.
In short, we _could_ use it, but it would require a degradation in functionality and would add more complexity to the module itself.
Comment #30
grasmash CreditAttribution: grasmash at Acquia commentedThis issue has been in "needs review" status for 27 days. How can this be moved forward?
Comment #31
grasmash CreditAttribution: grasmash at Acquia commentedAdding patches. Steps to merge:
Comment #32
grasmash CreditAttribution: grasmash at Acquia commented@drumm asked for a performance review before merging this.
Comment #33
drummI confirmed that the DOM was processed twice per page load and not cached.
Looking at table_of_contents’s 8.x branch, I also found a way to use selectors with PHP’s DOM library - symfony/css-selector.
Both of these are addressed by #3072354: Add caching, use PHP’s DOMDocument and symfony/css-selector.
Comment #34
drummWe’ll also need #3072743: Allow configuring block when field is only displayed via Panelizer so the table of contents block pane doesn’t disappear.
Comment #36
drummThis is now deployed!
I’ve updated the 3 example pages linked from the issue summary to remove the bespoke anchors and let the automated table of contents take over:
IDs are automatically assigned based on the heading content, if there is not already an
id
attribute on the heading tag. When updating pages, be sure to move over any existing IDs.Comment #37
drummFollowup for a mobile styling oversight: #3072799: Fix styles for documentation heading anchors on smaller-than-desktop screens
Comment #38
hansfn CreditAttribution: hansfn commentedThank you, drumm. I'm so happy to see this live!
Comment #39
ressa CreditAttribution: ressa at Ardea commentedThank you @grasmash @drumm and everybody else involved with getting this done! It looks really great, and will be super useful for getting an overview of documentation pages, as well as allow linking to a certain documentation page section.
Comment #40
grasmash CreditAttribution: grasmash at Acquia commented@neil Thanks so much for the merge!
At present, it looks like the new capability is not present on the Official Documentation pages, like:
https://www.drupal.org/docs/official_docs/en/_local_development_guide.html
Can it be added there?
Comment #41
drummI opened a followup for that: #3075522: Add clickable anchors to official documentation pages
Comment #43
FrancewhoaThanks all for your contributions :) I look forward to trying it
Comment #44
Francewhoa@bertboerland, drumm, grasmash, and all contributors :) Done I tried it using those examples above.
Wow. It is fantastic. I love it. Easy to use, looks good, and filled with automation-magic. I like that the # sign is faded a little. It keeps the focus on the page content on the right side. While at the same time the anchor is visible. Plus the # signs are always display at the same location. So easy to recall & find when users need one. I also noticed the automated "On this page" table of content display around the top right side of the doc page. Pure-joy :)