MCPcopy
hub / github.com/chinesehuazhou/python-weekly / replace_front_matter_field

Function replace_front_matter_field

resources/weekly_workflow.py:124–127  ·  view source on GitHub ↗

替换 front matter 中的单行字段,并尽量保留原始引号风格

(content, field_name, new_value)

Source from the content-addressed store, hash-verified

122 return description
123
124def replace_front_matter_field(content, field_name, new_value):
125 """替换 front matter 中的单行字段,并尽量保留原始引号风格"""
126 pattern = rf"^({field_name}:\s*['\"]?)(.*?)(['\"]?\s*)$"
127 return re.sub(pattern, rf"\g<1>{new_value}\g<3>", content, count=1, flags=re.MULTILINE)
128
129def split_and_generate_files(input_file, tmp_en_file):
130 """

Callers 1

split_and_generate_filesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected