@@ -93,7 +93,10 @@ def find_mods_toml() -> Path:
9393
9494def read_mc_publish_table (mods_toml : Path ) -> dict [str , str ]:
9595 try :
96- data = tomllib .loads (mods_toml .read_text ())
96+ block_text = extract_mc_publish_block (mods_toml .read_text ())
97+ if block_text is None :
98+ return {}
99+ data = tomllib .loads (block_text )
97100 except tomllib .TOMLDecodeError as exc :
98101 sys .exit (f"ERROR: Invalid TOML in { mods_toml } : { exc } " )
99102 table = data .get ("mc-publish" )
@@ -107,6 +110,8 @@ def read_mc_publish_table(mods_toml: Path) -> dict[str, str]:
107110def validate_file_value (name : str , value : str ) -> tuple [bool , str ]:
108111 if not value .strip ():
109112 return False , "value cannot be empty"
113+ if "${" in value :
114+ return False , "value contains a template placeholder"
110115 if name == "loader" and value not in ALLOWED_LOADERS :
111116 allowed_list = ", " .join (sorted (ALLOWED_LOADERS ))
112117 return False , f"loader must be one of: { allowed_list } "
@@ -129,6 +134,30 @@ def is_table_header(line: str) -> bool:
129134 return stripped .startswith ("[" ) and stripped .endswith ("]" )
130135
131136
137+ def is_mc_publish_header (line : str ) -> bool :
138+ stripped = strip_inline_comment (line )
139+ return stripped .startswith ("[mc-publish" ) or stripped .startswith ("[[mc-publish" )
140+
141+
142+ def extract_mc_publish_block (text : str ) -> str | None :
143+ lines = text .splitlines ()
144+ header_indices = [index for index , line in enumerate (lines ) if strip_inline_comment (line ) == "[mc-publish]" ]
145+ if not header_indices :
146+ return None
147+ if len (header_indices ) > 1 :
148+ sys .exit ("ERROR: Multiple [mc-publish] tables found in mods.toml" )
149+
150+ start_index = header_indices [0 ]
151+ end_index = len (lines )
152+ for index in range (start_index + 1 , len (lines )):
153+ if is_table_header (lines [index ]) and not is_mc_publish_header (lines [index ]):
154+ end_index = index
155+ break
156+
157+ block_lines = lines [start_index :end_index ]
158+ return "\n " .join (block_lines ) + "\n "
159+
160+
132161def build_mc_publish_block (values : dict [str , str ], ordered_keys : list [str ]) -> list [str ]:
133162 lines = ["[mc-publish]" ]
134163 for key in ordered_keys :
@@ -148,7 +177,7 @@ def update_mc_publish_block(mods_toml: Path, values: dict[str, str], ordered_key
148177 if start_index is not None :
149178 end_index = len (lines )
150179 for index in range (start_index + 1 , len (lines )):
151- if is_table_header (lines [index ]):
180+ if is_table_header (lines [index ]) and not is_mc_publish_header ( lines [ index ]) :
152181 end_index = index
153182 break
154183 block_lines = lines [start_index + 1 : end_index ]
0 commit comments