Skip to content

Commit 4ddfe10

Browse files
kartbenfabiobaltieri
authored andcommitted
doc: boards: extensions: simplify DTS binding description extraction
Previous implementation was unneccesarily complex, and cutting of words such as "802.15.4" to "802.". Signed-off-by: Benjamin Cabé <[email protected]>
1 parent bace008 commit 4ddfe10

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

doc/_scripts/gen_boards_catalog.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import logging
55
import os
66
import pickle
7+
import re
78
import subprocess
89
import sys
910
from collections import namedtuple
@@ -36,28 +37,21 @@ def get_first_sentence(cls, text):
3637
The first sentence found in the text, or the entire text if no sentence
3738
boundary is found.
3839
"""
39-
# Split the text into lines
40-
lines = text.splitlines()
40+
if not text:
41+
return ""
4142

42-
# Trim leading and trailing whitespace from each line and ignore completely blank lines
43-
lines = [line.strip() for line in lines]
43+
text = text.replace('\n', ' ')
44+
# Split by double spaces to get paragraphs
45+
paragraphs = text.split(' ')
46+
first_paragraph = paragraphs[0].strip()
4447

45-
if not lines:
46-
return ""
48+
# Look for a period followed by a space in the first paragraph
49+
period_match = re.search(r'(.*?)\.(?:\s|$)', first_paragraph)
50+
if period_match:
51+
return period_match.group(1).strip()
4752

48-
# Case 1: Single line followed by blank line(s) or end of text
49-
if len(lines) == 1 or (len(lines) > 1 and lines[1] == ""):
50-
first_line = lines[0]
51-
# Check for the first period
52-
period_index = first_line.find(".")
53-
# If there's a period, return up to the period; otherwise, return the full line
54-
return first_line[: period_index + 1] if period_index != -1 else first_line
55-
56-
# Case 2: Multiple contiguous lines, treat as a block
57-
block = " ".join(lines)
58-
period_index = block.find(".")
59-
# If there's a period, return up to the period; otherwise, return the full block
60-
return block[: period_index + 1] if period_index != -1 else block
53+
# If no period in the first paragraph, return the entire first paragraph
54+
return first_paragraph
6155

6256
@classmethod
6357
def get_cached_description(cls, node):

0 commit comments

Comments
 (0)