edit_paragraph_text
Modify paragraph text content in HNPX documents by specifying file path, paragraph ID, and new text for narrative editing.
Instructions
Edit paragraph text content
Args: file_path (str): Path to the HNPX document node_id (str): ID of the paragraph node to modify new_text (str): New paragraph text content
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | ||
| paragraph_id | Yes | ||
| new_text | Yes |
Implementation Reference
- src/hnpx_sdk/tools.py:520-546 (handler)The handler function that implements the logic to edit the text content of a specific paragraph node in an HNPX document. It parses the document, finds the node, validates it is a paragraph, updates the text, saves the document, and returns a success message.def edit_paragraph_text(file_path: str, paragraph_id: str, new_text: str) -> str: """Edit paragraph text content Args: file_path (str): Path to the HNPX document node_id (str): ID of the paragraph node to modify new_text (str): New paragraph text content """ tree = hnpx.parse_document(file_path) paragraph = hnpx.find_node(tree, paragraph_id) if paragraph is None: raise NodeNotFoundError(paragraph_id) # Verify it's a paragraph element if paragraph.tag != "paragraph": raise InvalidOperationError( "edit_paragraph_text", f"Node {paragraph_id} is not a paragraph" ) # Update the paragraph text content paragraph.text = new_text hnpx.save_document(tree, file_path) return f"Updated text content for paragraph {paragraph_id}"
- src/hnpx_sdk/server.py:25-25 (registration)Registers the edit_paragraph_text tool with the FastMCP server using the app.tool() decorator.app.tool()(tools.edit_paragraph_text)