Fix Docs plaintext link scan (#14583)
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com> Co-authored-by: UltralyticsAssistant <web@ultralytics.com> Co-authored-by: Ultralytics Assistant <135830346+UltralyticsAssistant@users.noreply.github.com>
This commit is contained in:
parent
3b81b95e1c
commit
80e311a07e
3 changed files with 8 additions and 2 deletions
|
|
@ -192,7 +192,11 @@ def convert_plaintext_links_to_html(content):
|
|||
for paragraph in main_content.find_all(["p", "li"]): # Focus on paragraphs and list items
|
||||
for text_node in paragraph.find_all(string=True, recursive=False):
|
||||
if text_node.parent.name not in {"a", "code"}: # Ignore links and code blocks
|
||||
new_text = re.sub(r"(https?://\S+?)(?=[,.!?;:]?\s|[,.!?;:]?$)", r'<a href="\1">\1</a>', str(text_node))
|
||||
new_text = re.sub(
|
||||
r'(https?://[^\s\'")]+)(?=[,.!?;:]?(?:\s|$)|[\'")])',
|
||||
r'<a href="\1">\1</a>',
|
||||
str(text_node),
|
||||
)
|
||||
if "<a" in new_text:
|
||||
new_soup = BeautifulSoup(new_text, "html.parser")
|
||||
text_node.replace_with(new_soup)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue