Skip to content

Commit

Permalink
doc: boards: extensions: simplify DTS binding description extraction
Browse files Browse the repository at this point in the history
Previous implementation was unneccesarily complex, and cutting of
words such as "802.15.4" to "802.".

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
  • Loading branch information
kartben committed Feb 28, 2025
1 parent b23734d commit 13ee25c
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions doc/_scripts/gen_boards_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import os
import pickle
import re
import subprocess
import sys
from collections import namedtuple
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 13ee25c

Please sign in to comment.