@@ -13,8 +13,8 @@ def read(self, scripts: list[ScriptMetadata]) -> list[ScriptMetadata]: ...
13
13
14
14
class ScriptContentReader :
15
15
def __init__ (self ) -> None :
16
- self ._section_start_regex = r".*code_embedder:.* start"
17
- self ._section_end_regex = r".*code_embedder:.* end"
16
+ self ._section_start_regex = r".*code_embedder:section_name start"
17
+ self ._section_end_regex = r".*code_embedder:section_name end"
18
18
19
19
def read (self , scripts : list [ScriptMetadata ]) -> list [ScriptMetadata ]:
20
20
scripts_with_full_contents = self ._read_full_script (scripts )
@@ -68,7 +68,9 @@ def _extract_part(self, script: ScriptMetadata) -> str:
68
68
start , end = self ._extract_object_part (script )
69
69
70
70
elif script .extraction_type == "section" :
71
- start , end = self ._extract_section_part (lines )
71
+ start , end = self ._extract_section_part (
72
+ lines = lines , section = script .extraction_part
73
+ )
72
74
if not self ._validate_section_bounds (start , end , script ):
73
75
return ""
74
76
@@ -96,11 +98,21 @@ def _extract_object_part(self, script: ScriptMetadata) -> tuple[int | None, int
96
98
97
99
return None , None
98
100
99
- def _extract_section_part (self , lines : list [str ]) -> tuple [int | None , int | None ]:
101
+ def _extract_section_part (
102
+ self , lines : list [str ], section : str | None = None
103
+ ) -> tuple [int | None , int | None ]:
104
+ if not section :
105
+ return None , None
106
+
107
+ updated_section_start_regex = self ._section_start_regex .replace (
108
+ "section_name" , section
109
+ )
110
+ updated_section_end_regex = self ._section_end_regex .replace ("section_name" , section )
111
+
100
112
for i , line in enumerate (lines ):
101
- if re .search (self . _section_start_regex , line ):
113
+ if re .search (updated_section_start_regex , line ):
102
114
start = i + 1
103
- elif re .search (self . _section_end_regex , line ):
115
+ elif re .search (updated_section_end_regex , line ):
104
116
return start , i
105
117
106
118
return None , None
0 commit comments