mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-20 03:35:51 +00:00
rippleapi - update version and add a filter to mark the doc with currently-built version
This commit is contained in:
@@ -97,10 +97,11 @@ pages:
|
||||
category: References
|
||||
html: reference-rippleapi.html
|
||||
# Currently this is the only page that's fetched remotely.
|
||||
md: https://raw.githubusercontent.com/ripple/ripple-lib/0.16.7/docs/index.md
|
||||
md: https://raw.githubusercontent.com/ripple/ripple-lib/0.16.10/docs/index.md
|
||||
ripple.com: https://ripple.com/build/rippleapi/
|
||||
filters:
|
||||
- remove_doctoc
|
||||
- add_version
|
||||
sidebar: true
|
||||
targets:
|
||||
- local
|
||||
|
||||
@@ -155,7 +155,7 @@ def parse_markdown(page, target=None, pages=None):
|
||||
for filter_name in page_filters:
|
||||
if "filter_markdown" in dir(filters[filter_name]):
|
||||
logging.info("... applying markdown filter %s" % filter_name)
|
||||
md = filters[filter_name].filter_markdown(md)
|
||||
md = filters[filter_name].filter_markdown(md, target=target, page=page)
|
||||
|
||||
# Actually parse the markdown
|
||||
logger.info("... parsing markdown...")
|
||||
@@ -166,7 +166,7 @@ def parse_markdown(page, target=None, pages=None):
|
||||
for filter_name in page_filters:
|
||||
if "filter_html" in dir(filters[filter_name]):
|
||||
logging.info("... applying HTML filter %s" % filter_name)
|
||||
html = filters[filter_name].filter_html(html)
|
||||
html = filters[filter_name].filter_html(html, target=target, page=page)
|
||||
|
||||
# Some filters would rather operate on a soup than a string.
|
||||
# May as well parse once and re-serialize once.
|
||||
@@ -176,7 +176,7 @@ def parse_markdown(page, target=None, pages=None):
|
||||
for filter_name in page_filters:
|
||||
if "filter_soup" in dir(filters[filter_name]):
|
||||
logging.info("... applying soup filter %s" % filter_name)
|
||||
filters[filter_name].filter_soup(soup)
|
||||
filters[filter_name].filter_soup(soup, target=target, page=page)
|
||||
# ^ the soup filters apply to the same object, passed by reference
|
||||
|
||||
# Replace links for any non-default target
|
||||
|
||||
31
tool/filter_add_version.py
Normal file
31
tool/filter_add_version.py
Normal file
@@ -0,0 +1,31 @@
|
||||
################################################################################
|
||||
## Add version to markdown filter ##
|
||||
## Author: Rome Reginelli ##
|
||||
## Copyright: Ripple Labs, Inc. 2016 ##
|
||||
## ##
|
||||
## Adds a message to the beginning of a file with a version number, based on ##
|
||||
## the URL of the remotely-fetched markdown. ##
|
||||
################################################################################
|
||||
import re
|
||||
import logging
|
||||
|
||||
def filter_markdown(md, target=None, page=None):
|
||||
"""Finds the version number and adds it to the start of the page."""
|
||||
version_regex = r"https://raw.githubusercontent.com/([A-Za-z0-9_.-]+)/([A-Za-z0-9_.-]+)/([A-Za-z0-9_-]+\.[A-Za-z0-9_.-]+)/.+\.md"
|
||||
|
||||
try:
|
||||
version_match = re.match(version_regex, page["md"])
|
||||
except (TypeError, KeyError):
|
||||
logging.warning("couldn't get MD path from page %s" % page)
|
||||
return md
|
||||
|
||||
try:
|
||||
github_owner = version_match.group(1)
|
||||
github_project = version_match.group(2)
|
||||
vnum = version_match.group(3)
|
||||
url = "https://github.com/%s/%s/releases/%s" % (github_owner, github_project, vnum)
|
||||
md = ("<p style='margin-top: 1em; font-style: italic'>Updated for <a href='%s' title='view on GitHub'>version %s</a></p>"%(url, vnum))+md
|
||||
except AttributeError:
|
||||
logging.warning("version regex didn't match: %s" % version_match)
|
||||
|
||||
return md
|
||||
@@ -8,7 +8,7 @@
|
||||
################################################################################
|
||||
import re
|
||||
|
||||
def filter_soup(soup):
|
||||
def filter_soup(soup, target=None, page=None):
|
||||
"""make links ending in > render like buttons"""
|
||||
buttonlinks = soup.find_all("a", string=re.compile(">$"))
|
||||
for link in buttonlinks:
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
## compatibility with those. ##
|
||||
################################################################################
|
||||
|
||||
def filter_markdown(md):
|
||||
def filter_markdown(md, target=None, page=None):
|
||||
"""Python markdown requires markdown="1" on HTML block elements
|
||||
that contain markdown. AND there's a bug where if you use
|
||||
markdown.extensions.extra, it replaces code fences in HTML
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
################################################################################
|
||||
import re
|
||||
|
||||
def filter_html(html):
|
||||
def filter_html(html, target=None, page=None):
|
||||
"""Uncomment multicode tab divs"""
|
||||
MC_START_REGEX = re.compile("<!-- *<div class=['\"]multicode['\"][^>]*> *-->")
|
||||
MC_END_REGEX = re.compile("<!-- *</div> *-->")
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
################################################################################
|
||||
|
||||
|
||||
def filter_markdown(md):
|
||||
def filter_markdown(md, target=None, page=None):
|
||||
"""Strip out doctoc Table of Contents for RippleAPI"""
|
||||
DOCTOC_START = "<!-- START doctoc generated TOC please keep comment here to allow auto update -->"
|
||||
DOCTOC_END = "<!-- END doctoc generated TOC please keep comment here to allow auto update -->"
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
################################################################################
|
||||
import re
|
||||
|
||||
def filter_soup(soup):
|
||||
def filter_soup(soup, target=None, page=None):
|
||||
"""replace underscores with dashes in h1,h2,etc. for backwards compatibility"""
|
||||
headers = soup.find_all(name=re.compile("h[0-9]"), id=True)
|
||||
for h in headers:
|
||||
|
||||
Reference in New Issue
Block a user