From 13ee25ca9f1e2a5239d892ef23fadc6b914ee0d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Cab=C3=A9?= Date: Fri, 28 Feb 2025 17:58:41 +0100 Subject: [PATCH] doc: boards: extensions: simplify DTS binding description extraction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previous implementation was unneccesarily complex, and cutting of words such as "802.15.4" to "802.". Signed-off-by: Benjamin Cabé --- doc/_scripts/gen_boards_catalog.py | 32 ++++++++++++------------------ 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/doc/_scripts/gen_boards_catalog.py b/doc/_scripts/gen_boards_catalog.py index 681b7a735b6c..1a1b678c5dda 100755 --- a/doc/_scripts/gen_boards_catalog.py +++ b/doc/_scripts/gen_boards_catalog.py @@ -4,6 +4,7 @@ import logging import os import pickle +import re import subprocess import sys from collections import namedtuple @@ -36,28 +37,21 @@ def get_first_sentence(cls, text): The first sentence found in the text, or the entire text if no sentence boundary is found. """ - # Split the text into lines - lines = text.splitlines() + if not text: + return "" - # Trim leading and trailing whitespace from each line and ignore completely blank lines - lines = [line.strip() for line in lines] + text = text.replace('\n', ' ') + # Split by double spaces to get paragraphs + paragraphs = text.split(' ') + first_paragraph = paragraphs[0].strip() - if not lines: - return "" + # Look for a period followed by a space in the first paragraph + period_match = re.search(r'(.*?)\.(?:\s|$)', first_paragraph) + if period_match: + return period_match.group(1).strip() - # Case 1: Single line followed by blank line(s) or end of text - if len(lines) == 1 or (len(lines) > 1 and lines[1] == ""): - first_line = lines[0] - # Check for the first period - period_index = first_line.find(".") - # If there's a period, return up to the period; otherwise, return the full line - return first_line[: period_index + 1] if period_index != -1 else first_line - - # Case 2: Multiple contiguous lines, treat as a block - block = " ".join(lines) - period_index = block.find(".") - # If there's a period, return up to the period; otherwise, return the full block - return block[: period_index + 1] if period_index != -1 else block + # If no period in the first paragraph, return the entire first paragraph + return first_paragraph @classmethod def get_cached_description(cls, node):