render_node
Extract and format paragraph content from HNPX fiction documents to display narrative text with optional IDs and structural markers.
Instructions
Render text representation of the node (only descendent paragraphs)
Args: file_path (str): Path to the HNPX document node_id (str): ID of the node to render show_ids (bool): Whether to show paragraph IDs in square brackets show_markers (bool): Whether to mark chapter/sequence beginnings
Returns: str: Formatted text representation the node
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | ||
| node_id | Yes | ||
| show_ids | No | ||
| show_markers | No |
Implementation Reference
- src/hnpx_sdk/tools.py:654-675 (handler)The main handler function for the 'render_node' tool. Parses the HNPX document, finds the specified node, and recursively renders its descendant paragraphs as formatted text, with optional IDs and markers.def render_node( file_path: str, node_id: str, show_ids: bool = False, show_markers: bool = True ) -> str: """Render text representation of the node (only descendent paragraphs) Args: file_path (str): Path to the HNPX document node_id (str): ID of the node to render show_ids (bool): Whether to show paragraph IDs in square brackets show_markers (bool): Whether to mark chapter/sequence beginnings Returns: str: Formatted text representation the node """ tree = hnpx.parse_document(file_path) node = hnpx.find_node(tree, node_id) if node is None: raise NodeNotFoundError(node_id) return _render_paragraphs_recursive(node, show_ids, show_markers).strip()
- src/hnpx_sdk/server.py:35-35 (registration)Registers the render_node tool with the FastMCP application using app.tool() decorator.app.tool()(tools.render_node)
- src/hnpx_sdk/tools.py:621-652 (helper)Helper function that recursively traverses the node subtree to render paragraphs, adding chapter titles and sequence markers as specified.def _render_paragraphs_recursive( node: etree.Element, show_ids: bool, show_markers: bool, is_first_child: bool = False, ) -> str: """Recursively print all paragraphs""" result = "" if node.tag == "paragraph": node_id = node.get("id") rendered_text = (node.text or "").strip() if rendered_text: if show_ids: result += f"[{node_id}] {rendered_text}\n\n" else: result += rendered_text + "\n\n" else: if node.tag == "chapter": result += f"=== {node.get('title')} ===\n\n" elif node.tag == "sequence" and not is_first_child: result += "***\n\n" is_first_child = True for child in node: if child.tag != "summary": result += _render_paragraphs_recursive( child, show_ids, show_markers, is_first_child ) is_first_child = False return result