mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-20 11:45:50 +00:00
Use Dactyl mainlined hoverlinks code
This commit is contained in:
@@ -26,7 +26,6 @@ filter_paths:
|
||||
|
||||
default_filters:
|
||||
- multicode_tabs
|
||||
- unicode_header_ids
|
||||
- buttonize
|
||||
- callouts
|
||||
- badges
|
||||
@@ -66,6 +65,8 @@ default_keys: &defaults
|
||||
# Override them with --vars to change which fork/branch to edit.
|
||||
github_forkurl: https://github.com/ripple/xrpl-dev-portal
|
||||
github_branch: master
|
||||
# Hover icon markup for permalinking headers
|
||||
hover_anchors: <i class="fa fa-link"></i>
|
||||
# Script tags used in a variety of tools & examples.
|
||||
lodash_tag: '<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js" integrity="sha512-WFN04846sdKMIP5LKNphMaWzU7YpMyCU245etK3g/2ARYbPK9Ub18eG+ljU96qKRCWh+quCY7yefSmlkQw1ANQ==" crossorigin="anonymous"></script>'
|
||||
ripple_lib_tag: '<script type="application/javascript" src="assets/js/ripple-lib-1.9.1.min.js"></script>'
|
||||
@@ -77,7 +78,6 @@ targets:
|
||||
display_name: XRPL.org
|
||||
<<: *defaults
|
||||
prefix: ""
|
||||
hover_anchors: <i class="fa fa-link"></i>
|
||||
link_subs:
|
||||
"./src/api-v3/paths/preparations/payments.ts": "https://github.com/xpring-eng/xrp-api/blob/master/src/api-v3/paths/preparations/payments.ts"
|
||||
readability_goals:
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
################################################################################
|
||||
## Unicode-friendly header IDs ##
|
||||
## Author: Rome Reginelli ##
|
||||
## Copyright: Ripple Labs, Inc. 2016-2019 ##
|
||||
## License: MIT https://github.com/ripple/xrpl-dev-portal/blob/master/LICENSE ##
|
||||
## ##
|
||||
## Changes the header ID formula to accept more unicode characters, so ##
|
||||
## non-English, non-Latin-script headers can have nice IDs. Closely matches ##
|
||||
## the behavior of GitHub-Flavored Markdown. ##
|
||||
################################################################################
|
||||
import re
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
## HTML5's 'id' attribute requirements are:
|
||||
## - Must be at least one character in length.
|
||||
## - Must not contain ASCII whitespace.
|
||||
## - Must be unique within the document.
|
||||
## - No other requirements. (HTML4 had stricter requirements.)
|
||||
|
||||
## Python-Markdown's default ID formula (as of v3.1.1) is:
|
||||
## 1. normalize unicode to NFKD form (so it can strip accent marks)
|
||||
## 2. remove all non-ASCII characters (this is the problem for us)
|
||||
## 3. remove leading/trailing whitespace
|
||||
## 4. convert to lowercase
|
||||
## 5. remove everything except space, hyphen, alphanumerics, and underscores
|
||||
## 6. replace each block of consecutive whitespace/hyphens with a single hyphen
|
||||
## 7. add _1, _2 etc. suffixes to non-unique IDs
|
||||
## Later, the dev portal uses a filter to replace underscores with dashes.
|
||||
|
||||
## The new formula is similar, but has some important differences:
|
||||
## 1. No Unicode normalization. We'd rather leave things as-is.
|
||||
## 2. Leave the string as unicode throughout.
|
||||
## 5. Keep hyphens, unicode "space" and unicode "word" characters (includes
|
||||
## underscores). Replace everything else with spaces, then strip trailing
|
||||
## spaces.
|
||||
## 7. Add -1, -2 suffixes to non-unique IDs.
|
||||
## The end result is that this standard closely matches GitHub-flavored
|
||||
## Markdown in almost all cases. (The exceptions are cases where GFM makes
|
||||
## invalid empty IDs, for example with emoji headers...)
|
||||
|
||||
HOVERANCHOR_FIELD = "hover_anchors"
|
||||
|
||||
def idify(utext):
|
||||
"""Make a string ID-friendly (but more unicode-friendly)"""
|
||||
utext = re.sub(r'[^\w\s-]', '', utext).strip().lower()
|
||||
utext = re.sub(r'[\s-]+', '-', utext)
|
||||
if not len(utext):
|
||||
# Headers must be non-empty
|
||||
return '_'
|
||||
return utext
|
||||
|
||||
def filter_soup(soup, currentpage={}, **kwargs):
|
||||
"""Generate new IDs for all headers"""
|
||||
uniqIDs = {}
|
||||
headers = soup.find_all(name=re.compile("h[0-9]"))
|
||||
for h in headers:
|
||||
new_id = idify(h.get_text())
|
||||
if new_id not in uniqIDs.keys():
|
||||
uniqIDs[new_id] = 0
|
||||
else:
|
||||
# not unique, append -1, -2, etc. to this instance
|
||||
uniqIDs[new_id] += 1
|
||||
new_id = "{id}-{n}".format(id=new_id, n=uniqIDs[new_id])
|
||||
|
||||
h["id"] = new_id
|
||||
|
||||
hoveranchor_contents = currentpage.get("hover_anchors", False)
|
||||
if hoveranchor_contents:
|
||||
hoverlink = soup.new_tag("a", attrs={
|
||||
"href": "#"+new_id,
|
||||
"class": "hover_anchor",
|
||||
"aria-hidden": "true"})
|
||||
hoverlink.append(BeautifulSoup(hoveranchor_contents, "html.parser"))
|
||||
h.append(hoverlink)
|
||||
Reference in New Issue
Block a user