WIP fixing relative links

check the FIXMEs
This commit is contained in:
Filipp
2023-03-28 11:00:26 +03:00
parent c2fa0e5f0e
commit 4ec155d70d
2 changed files with 31 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
import os
import re
import subprocess
import urllib
import inflect
from dataclasses import dataclass
@@ -1173,6 +1174,33 @@ def string_impl(p):
"string": lambda x: x
}.get(p.get("format", p["type"]), lambda x: f"{x}.to_string()")
MD_LINKS_CAPTURE = re.compile(r'''
\[ # Opening bracket for the "name" part of the url
([^]]+?) # Some amount of non-closing bracket `]` symbols,
# Captured in a group
\] # Close the name part
\s* # maybe a whitespace
\( # Opening a paren for the url part
([^)]+?) # Url, captured in a group
\) # closing paren
''', re.VERBOSE)
# FIXME: combine with links handling in <lib.mako>.docs
def fix_relative_links(url_base):
url_parsed = urllib.parse.urlparse(url_base)
url_base = f"{url_parsed.scheme}://{url_parsed.netloc}"
def replace_url(url_match: re.match):
original_url = url_match.group(0)
name = url_match.group(1)
url = url_match.group(2)
if url.startswith('/'):
return f"[{name}]({url_base}{url})"
return original_url
def fixer(docs):
# FIXME: replace with proper markdown parser and documentationLink value
return MD_LINKS_CAPTURE.sub(replace_url, docs)
return fixer
if __name__ == '__main__':
raise AssertionError('For import only')

View File

@@ -6,7 +6,7 @@
rust_copy_value_s, organize_params, REQUEST_VALUE_PROPERTY_NAME,
build_all_params, rb_type_params_s, hub_type_params_s, mb_type_params_s, mb_additional_type_params,
struct_type_bounds_s, METHODS_RESOURCE, SPACES_PER_TAB, prefix_all_but_first_with,
METHODS_BUILDER_MARKER_TRAIT, remove_empty_lines, method_default_scope, rust_doc_sanitize)
METHODS_BUILDER_MARKER_TRAIT, remove_empty_lines, method_default_scope, rust_doc_sanitize, fix_relative_links)
%>\
<%namespace name="util" file="../../../lib/util.mako"/>\
<%namespace name="lib" file="lib.mako"/>\
@@ -80,7 +80,7 @@ impl${rb_params} ${ThisType} {
% if 'description' in m:
/// Create a builder to help you perform the following task:
///
${m.description | rust_doc_sanitize, rust_doc_comment, indent_all_but_first_by(1)}
${m.description | fix_relative_links(documentationLink), rust_doc_sanitize, rust_doc_comment, indent_all_but_first_by(1)}
% endif
% if required_props:
///
@@ -91,7 +91,7 @@ impl${rb_params} ${ThisType} {
arg_prefix = "/// * `" + p.name + "` - "
%>\
${arg_prefix}${p.get('description', "No description provided.")
| remove_empty_lines, prefix_all_but_first_with(' ' * SPACES_PER_TAB + '///' + ' ' * (len(arg_prefix) - len('///')))}
| fix_relative_links(documentationLink), remove_empty_lines, prefix_all_but_first_with(' ' * SPACES_PER_TAB + '///' + ' ' * (len(arg_prefix) - len('///')))}
% endfor
% endif
pub fn ${mangle_ident(a)}${type_params}(&self${method_args}) -> ${RType}${mb_tparams} {