agentsclimarketplace

Run3 Process Conditional Sections in Word Documents

Skill cxcscmu/SkillLearnBench/skills/b3-teacher-feedback-claude-haiku-4-5/offer-letter-generator/run3_Process-Conditional-Sections-in-Word-Documents

Use this skill to handle conditional content blocks marked with {{IF_CONDITION}}...{{END_IF_CONDITION}} in Word documents. Keep or remove the entire block based on a condition, and clean up the marker text. Apply this during paragraph processing, not as a separate pass, to avoid structural issues with modified paragraphs.From its SKILL.md

Install
npx -y skills add cxcscmu/SkillLearnBench --skill run3_Process-Conditional-Sections-in-Word-Documents

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

SKILL.md

2.1 KB, 362 tokens by cl100k_base, as published. Nobody here has run it

Key Principles

  1. Process conditionals inline: Handle {{IF_*}} and {{END_IF_*}} markers during the same pass as placeholder replacement, not in a separate preprocessing step
  2. Track state across paragraphs: Use a flag to track whether you're inside a conditional block
  3. Clean marker text properly: Use regex-based replacement on runs to completely remove markers, not just .replace() on paragraph text
  4. Process all locations: Check paragraphs in doc.paragraphs, tables, headers, and footers

Algorithm

inside_conditional = False
condition_keep = None
paragraphs_to_delete = []

for each paragraph in all_locations (doc.paragraphs, tables, headers, footers):
    if paragraph contains {{IF_*}}:
        inside_conditional = True
        condition_name = extract_condition_name()
        condition_keep = evaluate_condition(condition_name)
        remove_marker_from_paragraph(paragraph, regex-based)
    
    elif paragraph contains {{END_IF_*}}:
        inside_conditional = False
        remove_marker_from_paragraph(paragraph, regex-based)
    
    else:
        if inside_conditional and not condition_keep:
            paragraphs_to_delete.append(paragraph)
        else:
            process_placeholder_replacements(paragraph)

delete_all_marked_paragraphs(paragraphs_to_delete)

Implementation Notes

  • Extract condition name with regex: r'{{IF_(\w+)}}'
  • Use paragraph._element.getparent().remove(paragraph._element) to delete paragraphs safely
  • Remove markers with the same regex-based replace_placeholders_in_text() function used for other placeholders
  • Collect paragraphs to delete first, then delete them after iteration (never modify a list while iterating)

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.