[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M74HGAZXWQ5PKQ0FE0D5YZ3R":3,"skill-same:01M74HGAZXWQ5PKQ0FE0D5YZ3R":47},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":30,"ownerDescription":31,"updatedAt":32,"install":33,"resources":46},"01M74HGAZXWQ5PKQ0FE0D5YZ3R","docx",null,"Word document manipulation with python-docx - handling split placeholders, headers\u002Ffooters, nested tables","Raidriar7170\u002Fhermes-skilleval","Raidriar7170","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F118113656?v=4","01M74HF0DSG5XS53PVXERD6V51","Adrian Sun","01M74HF0EJJHQE5XJ0MV1MRFHX",29,"MIT","https:\u002F\u002Fgithub.com\u002FRaidriar7170\u002Fhermes-skilleval\u002Fblob\u002Fmain\u002Fartifacts\u002Fv0.3\u002Fskillsbench-pilot\u002Fv0.3-stage2-input-package-candidate-20260701T010000Z\u002Fcandidate-data\u002Fskill-sources\u002Fskillsbench__docx\u002FSKILL.md",[],[],"2026-11-11 15:11:14",false,"---\nname: docx\ndescription: Word document manipulation with python-docx - handling split placeholders, headers\u002Ffooters, nested tables\n---\n\n# Word Document Manipulation with python-docx\n\n## Critical: Split Placeholder Problem\n\n**The #1 issue with Word templates**: Word often splits placeholder text across multiple XML runs. For example, `{{CANDIDATE_NAME}}` might be stored as:\n- Run 1: `{{CANDI`\n- Run 2: `DATE_NAME}}`\n\nThis happens due to spell-check, formatting changes, or Word's internal XML structure.\n\n### Naive Approach (FAILS on split placeholders)\n\n```python\n# DON'T DO THIS - won't find split placeholders\nfor para in doc.paragraphs:\n    for run in para.runs:\n        if '{{NAME}}' in run.text:  # Won't match if split!\n            run.text = run.text.replace('{{NAME}}', value)\n```\n\n### Correct Approach: Paragraph-Level Search and Rebuild\n\n```python\nimport re\n\ndef replace_placeholder_robust(paragraph, placeholder, value):\n    \"\"\"Replace placeholder that may be split across runs.\"\"\"\n    full_text = paragraph.text\n    if placeholder not in full_text:\n        return False\n\n    # Find all runs and their positions\n    runs = paragraph.runs\n    if not runs:\n        return False\n\n    # Build mapping of character positions to runs\n    char_to_run = []\n    for run in runs:\n        for char in run.text:\n            char_to_run.append(run)\n\n    # Find placeholder position\n    start_idx = full_text.find(placeholder)\n    end_idx = start_idx + len(placeholder)\n\n    # Get runs that contain the placeholder\n    if start_idx >= len(char_to_run):\n        return False\n\n    start_run = char_to_run[start_idx]\n\n    # Clear all runs and rebuild with replacement\n    new_text = full_text.replace(placeholder, str(value))\n\n    # Preserve first run's formatting, clear others\n    for i, run in enumerate(runs):\n        if i == 0:\n            run.text = new_text\n        else:\n            run.text = ''\n\n    return True\n```\n\n### Best Practice: Regex-Based Full Replacement\n\n```python\nimport re\nfrom docx import Document\n\ndef replace_all_placeholders(doc, data):\n    \"\"\"Replace all {{KEY}} placeholders with values from data dict.\"\"\"\n\n    def replace_in_paragraph(para):\n        \"\"\"Replace placeholders in a single paragraph.\"\"\"\n        text = para.text\n        # Find all placeholders\n        pattern = r'\\{\\{([A-Z_]+)\\}\\}'\n        matches = re.findall(pattern, text)\n\n        if not matches:\n            return\n\n        # Build new text with replacements\n        new_text = text\n        for key in matches:\n            placeholder = '{{' + key + '}}'\n            if key in data:\n                new_text = new_text.replace(placeholder, str(data[key]))\n\n        # If text changed, rebuild paragraph\n        if new_text != text:\n            # Clear all runs, put new text in first run\n            runs = para.runs\n            if runs:\n                runs[0].text = new_text\n                for run in runs[1:]:\n                    run.text = ''\n\n    # Process all paragraphs\n    for para in doc.paragraphs:\n        replace_in_paragraph(para)\n\n    # Process tables (including nested)\n    for table in doc.tables:\n        for row in table.rows:\n            for cell in row.cells:\n                for para in cell.paragraphs:\n                    replace_in_paragraph(para)\n                # Handle nested tables\n                for nested_table in cell.tables:\n                    for nested_row in nested_table.rows:\n                        for nested_cell in nested_row.cells:\n                            for para in nested_cell.paragraphs:\n                                replace_in_paragraph(para)\n\n    # Process headers and footers\n    for section in doc.sections:\n        for para in section.header.paragraphs:\n            replace_in_paragraph(para)\n        for para in section.footer.paragraphs:\n            replace_in_paragraph(para)\n```\n\n## Headers and Footers\n\nHeaders\u002Ffooters are separate from main document body:\n\n```python\nfrom docx import Document\n\ndoc = Document('template.docx')\n\n# Access headers\u002Ffooters through sections\nfor section in doc.sections:\n    # Header\n    header = section.header\n    for para in header.paragraphs:\n        # Process paragraphs\n        pass\n\n    # Footer\n    footer = section.footer\n    for para in footer.paragraphs:\n        # Process paragraphs\n        pass\n```\n\n## Nested Tables\n\nTables can contain other tables. Must recurse:\n\n```python\ndef process_table(table, data):\n    \"\"\"Process table including nested tables.\"\"\"\n    for row in table.rows:\n        for cell in row.cells:\n            # Process paragraphs in cell\n            for para in cell.paragraphs:\n                replace_in_paragraph(para, data)\n\n            # Recurse into nested tables\n            for nested_table in cell.tables:\n                process_table(nested_table, data)\n```\n\n## Conditional Sections\n\nFor `{{IF_CONDITION}}...{{END_IF_CONDITION}}` patterns:\n\n```python\ndef handle_conditional(doc, condition_key, should_include, data):\n    \"\"\"Remove or keep conditional sections.\"\"\"\n    start_marker = '{{IF_' + condition_key + '}}'\n    end_marker = '{{END_IF_' + condition_key + '}}'\n\n    for para in doc.paragraphs:\n        text = para.text\n        if start_marker in text and end_marker in text:\n            if should_include:\n                # Remove just the markers\n                new_text = text.replace(start_marker, '').replace(end_marker, '')\n                # Also replace any placeholders inside\n                for key, val in data.items():\n                    new_text = new_text.replace('{{' + key + '}}', str(val))\n            else:\n                # Remove entire content between markers\n                new_text = ''\n\n            # Apply to first run\n            if para.runs:\n                para.runs[0].text = new_text\n                for run in para.runs[1:]:\n                    run.text = ''\n```\n\n## Complete Solution Pattern\n\n```python\nfrom docx import Document\nimport json\nimport re\n\ndef fill_template(template_path, data_path, output_path):\n    \"\"\"Fill Word template handling all edge cases.\"\"\"\n\n    # Load data\n    with open(data_path) as f:\n        data = json.load(f)\n\n    # Load template\n    doc = Document(template_path)\n\n    def replace_in_para(para):\n        text = para.text\n        pattern = r'\\{\\{([A-Z_]+)\\}\\}'\n        if not re.search(pattern, text):\n            return\n\n        new_text = text\n        for match in re.finditer(pattern, text):\n            key = match.group(1)\n            placeholder = match.group(0)\n            if key in data:\n                new_text = new_text.replace(placeholder, str(data[key]))\n\n        if new_text != text and para.runs:\n            para.runs[0].text = new_text\n            for run in para.runs[1:]:\n                run.text = ''\n\n    # Main document\n    for para in doc.paragraphs:\n        replace_in_para(para)\n\n    # Tables (with nesting)\n    def process_table(table):\n        for row in table.rows:\n            for cell in row.cells:\n                for para in cell.paragraphs:\n                    replace_in_para(para)\n                for nested in cell.tables:\n                    process_table(nested)\n\n    for table in doc.tables:\n        process_table(table)\n\n    # Headers\u002FFooters\n    for section in doc.sections:\n        for para in section.header.paragraphs:\n            replace_in_para(para)\n        for para in section.footer.paragraphs:\n            replace_in_para(para)\n\n    doc.save(output_path)\n\n# Usage\nfill_template('template.docx', 'data.json', 'output.docx')\n```\n\n## Common Pitfalls\n\n1. **Forgetting headers\u002Ffooters** - They're not in `doc.paragraphs`\n2. **Missing nested tables** - Must recurse into `cell.tables`\n3. **Split placeholders** - Always work at paragraph level, not run level\n4. **Losing formatting** - Keep first run's formatting when rebuilding\n5. **Conditional markers left behind** - Remove `{{IF_...}}` markers after processing\n","# Word Document Manipulation with python-docx\n\n## Critical: Split Placeholder Problem\n\n**The #1 issue with Word templates**: Word often splits placeholder text across multiple XML runs. For example, `{{CANDIDATE_NAME}}` might be stored as:\n- Run 1: `{{CANDI`\n- Run 2: `DATE_NAME}}`\n\nThis happens due to spell-check, formatting changes, or Word's internal XML structure.\n\n### Naive Approach (FAILS on split placeholders)\n\n```python\n# DON'T DO THIS - won't find split placeholders\nfor para in doc.paragraphs:\n    for run in para.runs:\n        if '{{NAME}}' in run.text:  # Won't match if split!\n            run.text = run.text.replace('{{NAME}}', value)\n```\n\n### Correct Approach: Paragraph-Level Search and Rebuild\n\n```python\nimport re\n\ndef replace_placeholder_robust(paragraph, placeholder, value):\n    \"\"\"Replace placeholder that may be split across runs.\"\"\"\n    full_text = paragraph.text\n    if placeholder not in full_text:\n        return False\n\n    # Find all runs and their positions\n    runs = paragraph.runs\n    if not runs:\n        return False\n\n    # Build mapping of character positions to runs\n    char_to_run = []\n    for run in runs:\n        for char in run.text:\n            char_to_run.append(run)\n\n    # Find placeholder position\n    start_idx = full_text.find(placeholder)\n    end_idx = start_idx + len(placeholder)\n\n    # Get runs that contain the placeholder\n    if start_idx >= len(char_to_run):\n        return False\n\n    start_run = char_to_run[start_idx]\n\n    # Clear all runs and rebuild with replacement\n    new_text = full_text.replace(placeholder, str(value))\n\n    # Preserve first run's formatting, clear others\n    for i, run in enumerate(runs):\n        if i == 0:\n            run.text = new_text\n        else:\n            run.text = ''\n\n    return True\n```\n\n### Best Practice: Regex-Based Full Replacement\n\n```python\nimport re\nfrom docx import Document\n\ndef replace_all_placeholders(doc, data):\n    \"\"\"Replace all {{KEY}} placeholders with values from data dict.\"\"\"\n\n    def replace_in_paragraph(para):\n        \"\"\"Replace placeholders in a single paragraph.\"\"\"\n        text = para.text\n        # Find all placeholders\n        pattern = r'\\{\\{([A-Z_]+)\\}\\}'\n        matches = re.findall(pattern, text)\n\n        if not matches:\n            return\n\n        # Build new text with replacements\n        new_text = text\n        for key in matches:\n            placeholder = '{{' + key + '}}'\n            if key in data:\n                new_text = new_text.replace(placeholder, str(data[key]))\n\n        # If text changed, rebuild paragraph\n        if new_text != text:\n            # Clear all runs, put new text in first run\n            runs = para.runs\n            if runs:\n                runs[0].text = new_text\n                for run in runs[1:]:\n                    run.text = ''\n\n    # Process all paragraphs\n    for para in doc.paragraphs:\n        replace_in_paragraph(para)\n\n    # Process tables (including nested)\n    for table in doc.tables:\n        for row in table.rows:\n            for cell in row.cells:\n                for para in cell.paragraphs:\n                    replace_in_paragraph(para)\n                # Handle nested tables\n                for nested_table in cell.tables:\n                    for nested_row in nested_table.rows:\n                        for nested_cell in nested_row.cells:\n                            for para in nested_cell.paragraphs:\n                                replace_in_paragraph(para)\n\n    # Process headers and footers\n    for section in doc.sections:\n        for para in section.header.paragraphs:\n            replace_in_paragraph(para)\n        for para in section.footer.paragraphs:\n            replace_in_paragraph(para)\n```\n\n## Headers and Footers\n\nHeaders\u002Ffooters are separate from main document body:\n\n```python\nfrom docx import Document\n\ndoc = Document('template.docx')\n\n# Access headers\u002Ffooters through sections\nfor section in doc.sections:\n    # Header\n    header = section.header\n    for para in header.paragraphs:\n        # Process paragraphs\n        pass\n\n    # Footer\n    footer = section.footer\n    for para in footer.paragraphs:\n        # Process paragraphs\n        pass\n```\n\n## Nested Tables\n\nTables can contain other tables. Must recurse:\n\n```python\ndef process_table(table, data):\n    \"\"\"Process table including nested tables.\"\"\"\n    for row in table.rows:\n        for cell in row.cells:\n            # Process paragraphs in cell\n            for para in cell.paragraphs:\n                replace_in_paragraph(para, data)\n\n            # Recurse into nested tables\n            for nested_table in cell.tables:\n                process_table(nested_table, data)\n```\n\n## Conditional Sections\n\nFor `{{IF_CONDITION}}...{{END_IF_CONDITION}}` patterns:\n\n```python\ndef handle_conditional(doc, condition_key, should_include, data):\n    \"\"\"Remove or keep conditional sections.\"\"\"\n    start_marker = '{{IF_' + condition_key + '}}'\n    end_marker = '{{END_IF_' + condition_key + '}}'\n\n    for para in doc.paragraphs:\n        text = para.text\n        if start_marker in text and end_marker in text:\n            if should_include:\n                # Remove just the markers\n                new_text = text.replace(start_marker, '').replace(end_marker, '')\n                # Also replace any placeholders inside\n                for key, val in data.items():\n                    new_text = new_text.replace('{{' + key + '}}', str(val))\n            else:\n                # Remove entire content between markers\n                new_text = ''\n\n            # Apply to first run\n            if para.runs:\n                para.runs[0].text = new_text\n                for run in para.runs[1:]:\n                    run.text = ''\n```\n\n## Complete Solution Pattern\n\n```python\nfrom docx import Document\nimport json\nimport re\n\ndef fill_template(template_path, data_path, output_path):\n    \"\"\"Fill Word template handling all edge cases.\"\"\"\n\n    # Load data\n    with open(data_path) as f:\n        data = json.load(f)\n\n    # Load template\n    doc = Document(template_path)\n\n    def replace_in_para(para):\n        text = para.text\n        pattern = r'\\{\\{([A-Z_]+)\\}\\}'\n        if not re.search(pattern, text):\n            return\n\n        new_text = text\n        for match in re.finditer(pattern, text):\n            key = match.group(1)\n            placeholder = match.group(0)\n            if key in data:\n                new_text = new_text.replace(placeholder, str(data[key]))\n\n        if new_text != text and para.runs:\n            para.runs[0].text = new_text\n            for run in para.runs[1:]:\n                run.text = ''\n\n    # Main document\n    for para in doc.paragraphs:\n        replace_in_para(para)\n\n    # Tables (with nesting)\n    def process_table(table):\n        for row in table.rows:\n            for cell in row.cells:\n                for para in cell.paragraphs:\n                    replace_in_para(para)\n                for nested in cell.tables:\n                    process_table(nested)\n\n    for table in doc.tables:\n        process_table(table)\n\n    # Headers\u002FFooters\n    for section in doc.sections:\n        for para in section.header.paragraphs:\n            replace_in_para(para)\n        for para in section.footer.paragraphs:\n            replace_in_para(para)\n\n    doc.save(output_path)\n\n# Usage\nfill_template('template.docx', 'data.json', 'output.docx')\n```\n\n## Common Pitfalls\n\n1. **Forgetting headers\u002Ffooters** - They're not in `doc.paragraphs`\n2. **Missing nested tables** - Must recurse into `cell.tables`\n3. **Split placeholders** - Always work at paragraph level, not run level\n4. **Losing formatting** - Keep first run's formatting when rebuilding\n5. **Conditional markers left behind** - Remove `{{IF_...}}` markers after processing\n",{"name":5,"description":7},"main","8f6a21e53c1363ee18ea6d6e3db1f4b3805ff552","artifacts\u002Fv0.3\u002Fskillsbench-pilot\u002Fv0.3-stage2-input-package-candidate-20260701T010000Z\u002Fcandidate-data\u002Fskill-sources\u002Fskillsbench__docx",1,"https:\u002F\u002Fgithub.com\u002FRaidriar7170\u002Fhermes-skilleval","https:\u002F\u002Fgithub.com\u002FRaidriar7170","https:\u002F\u002Flinkedin.com\u002Fin\u002Fminghongsun","UCSD ECE M.S. '27 | LLM\u002FAgent algorithms, multimodal grounding, post-training & evaluation","2026-09-26 13:41:34",{"source":8,"skillName":5,"commands":34,"prompt":44,"zipAvailable":45},[35,38,41],{"tool":36,"command":37},"npx","npx skills add Raidriar7170\u002Fhermes-skilleval --skill docx",{"tool":39,"command":40},"bunx","bunx skills add Raidriar7170\u002Fhermes-skilleval --skill docx",{"tool":42,"command":43},"pnpm","pnpm dlx skills add Raidriar7170\u002Fhermes-skilleval --skill docx","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FRaidriar7170\u002Fhermes-skilleval\u002Fblob\u002Fmain\u002Fartifacts\u002Fv0.3\u002Fskillsbench-pilot\u002Fv0.3-stage2-input-package-candidate-20260701T010000Z\u002Fcandidate-data\u002Fskill-sources\u002Fskillsbench__docx\u002FSKILL.md",true,[],[48,54,61,68,75,82],{"skillNo":49,"name":50,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":51,"categories":52,"keywords":53,"publishedAt":19},"01M74HPD1Y2K0FZDH27KCC8TN4","songwriting-and-ai-music","https:\u002F\u002Fgithub.com\u002FRaidriar7170\u002Fhermes-skilleval\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fskills\u002Fcreative\u002Fsongwriting-and-ai-music\u002FSKILL.md",[],[],{"skillNo":55,"name":56,"nameZh":6,"description":57,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":58,"categories":59,"keywords":60,"publishedAt":19},"01M74HPANJ9S5FJF4ENQNGSKBH","test-driven-development","Use when implementing behavior that can be covered by automated tests.","https:\u002F\u002Fgithub.com\u002FRaidriar7170\u002Fhermes-skilleval\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fskills\u002Fcoding\u002Ftest-driven-development\u002FSKILL.md",[],[],{"skillNo":62,"name":63,"nameZh":6,"description":64,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":65,"categories":66,"keywords":67,"publishedAt":19},"01M74HP9BHCYRS5NX8K8A2SKQD","systematic-debugging","Use when diagnosing failing tests, runtime errors, or unexpected behavior.","https:\u002F\u002Fgithub.com\u002FRaidriar7170\u002Fhermes-skilleval\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fskills\u002Fcoding\u002Fsystematic-debugging\u002FSKILL.md",[],[],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":19},"01M74HP77TN9ZZMXVVXFKDTHQ3","workflow-evidence-audit","Use when auditing validation workflow evidence before a maintainer review or diagnostic handoff.","https:\u002F\u002Fgithub.com\u002FRaidriar7170\u002Fhermes-skilleval\u002Fblob\u002Fmain\u002Fexamples\u002Fgithub-action\u002Fskills\u002Fworkflow-evidence-audit\u002FSKILL.md",[],[],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":19},"01M74HP42HQ8KAJFT2HETRBPN6","release-note-review","Use when reviewing release notes for evidence boundaries, local validation summaries, and explicit non-goals.","https:\u002F\u002Fgithub.com\u002FRaidriar7170\u002Fhermes-skilleval\u002Fblob\u002Fmain\u002Fexamples\u002Fgithub-action\u002Fskills\u002Frelease-note-review\u002FSKILL.md",[],[],{"skillNo":83,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":84,"categories":85,"keywords":86,"publishedAt":19},"01M74HP191NV4NH4C2NRZK2GY0","https:\u002F\u002Fgithub.com\u002FRaidriar7170\u002Fhermes-skilleval\u002Fblob\u002Fmain\u002Fdocs\u002Fdemo\u002Fexternal-skill-library-validation\u002Fsource\u002Fmarkdown-skills\u002Freview\u002Fworkflow-evidence-audit\u002FSKILL.md",[],[]]