Convert HTML ( Tables etc) to display in GoogleDocs

I am using code node.

Using AI I have tried various methods but keep getting errors.

Python

from html.parser import HTMLParser

# Define the GoogleDocsHTMLConverter class
class GoogleDocsHTMLConverter(HTMLParser):
    def __init__(self):
        super().__init__()
        self.requests = []
        self.current_list_type = None

    def handle_starttag(self, tag, attrs):
        if tag == 'p':
            self.requests.append({"insertText": {"location": {"index": len(self.requests) + 1}, "text": ""}})
        elif tag in ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']:
            self.requests.append({
                "insertText": {
                    "location": {"index": len(self.requests) + 1},
                    "text": ""
                },
                "updateTextStyle": {
                    "range": {"startIndex": len(self.requests), "endIndex": len(self.requests) + 1},
                    "textStyle": {"bold": True, "fontSize": {"magnitude": 28 - int(tag[1]) * 4, "unit": "PT"}},
                    "fields": "bold,fontSize"
                }
            })
        elif tag == 'ul':
            self.current_list_type = 'unordered'
        elif tag == 'ol':
            self.current_list_type = 'ordered'
        elif tag == 'li' and self.current_list_type == 'unordered':
            self.requests.append({
                "insertText": {
                    "location": {"index": len(self.requests) + 1},
                    "text": "• "
                }
            })
        elif tag == 'li' and self.current_list_type == 'ordered':
            self.requests.append({
                "insertText": {
                    "location": {"index": len(self.requests) + 1},
                    "text": f"{len(self.requests) + 1}. "
                }
            })
        elif tag == 'table':
            self.requests.append({
                "insertTable": {
                    "rows": 0,
                    "columns": 0,
                    "location": {"index": len(self.requests) + 1}
                }
            })
        elif tag == 'tr':
            self.requests.append({"tableRow": []})
        elif tag == 'td':
            self.requests.append({"tableCell": []})

    def handle_endtag(self, tag):
        if tag == 'ul' or tag == 'ol':
            self.current_list_type = None
        elif tag == 'table':
            self.requests.append({
                "insertTable": {
                    "rows": len(self.requests),
                    "columns": len(self.requests[0]),
                    "location": {"index": len(self.requests) + 1}
                }
            })

    def handle_data(self, data):
        # Append text to the most recent insertText
        if len(self.requests) > 0 and 'insertText' in self.requests[-1]:
            self.requests[-1]['insertText']['text'] += data.strip() + "\n"

    def convert_html_to_google_docs(self, html_content):
        self.feed(html_content)
        return self.requests


# Access the output from the "HTML" node
html_content = input().get('HTML', {}).get('json', '')

# Ensure that HTML content is available
if not html_content:
    raise ValueError("No HTML content found from the 'HTML' node")

# Run the converter and get the formatted data for Google Docs
converter = GoogleDocsHTMLConverter()
google_docs_requests = converter.convert_html_to_google_docs(html_content)

# Properly return the result wrapped in a list of dictionaries for n8n
return [{"requests": google_docs_requests}]

error is EOFError: EOF when reading a line

anyone have either python or javascript script or another method.
I set google docs prefs to Enable Markdown
I tried markdown node and pushed the data to the document.

But if I send the mark down output

[
  {
    "output": "Based on the information extracted from the documents, I will create the required risk assessment, licenses, qualifications, regulations, and insurances table, and the method statement table. Here is the structured HTML document:\n\n```html\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>Risk Assessment Document</title>\n    <style>\n        table {\n            width: 100%;\n            border-collapse: collapse;\n            margin-bottom: 20px;\n        }\n        th, td {\n            border: 1px solid #000;\n            padding: 8px;\n            text-align: left;\n        }\n        th {\n            background-color: #f2f2f2;\n        }\n        h1, h2 {\n            color: #333;\n        }\n    </style>\n</head>\n<body>\n\n<h1>Risk Assessment Document</h1>\n\n<h2>Risk Assessment</h2>\n<table>\n    <caption>Risk Assessment</caption>\n    <thead>\n        <tr>\n            <th>ACTIVITY</th>\n            <th>PERSON AT RISK</th>\n            <th>SIGNIFICANT HAZARDS</th>\n            <th>RISK L</th>\n            <th>RISK S</th>\n            <th>RISK DR</th>\n            <th>RISK CONTROL MEASURES</th>\n            <th>RESIDUAL RISK L</th>\n            <th>RESIDUAL RISK S</th>\n            <th>RESIDUAL RISK DR</th>\n        </tr>\n    </thead>\n    <tbody>\n        <tr>\n            <td>Erecting a tower scaffold</td>\n            <td>Operative</td>\n            <td>Falls from height, electric shocks</td>\n            <td>3</td>\n            <td>4</td>\n            <td>12</td>\n            <td>\n                <ul>\n                    <li>Tower should be erected as per the “Through the trap” or “3T” method as recommended by the HSE.</li>\n                    <li>Tower scaffolds to be erected by trained personnel only, i.e. those who have been on a course approved by PASMA.</li>\n                    <li>Operatives should not climb on the outside of the tower at any time.</li>\n                    <li>Towers should only be erected on solid secure standing.</li>\n                    <li>Towers should not be erected underneath power lines.</li>\n                    <li>Guard rails edge protection and stabilisers to be used where necessary.</li>\n                </ul>\n            </td>\n            <td>2</td>\n            <td>4</td>\n            <td>8</td>\n        </tr>\n        <!-- Repeat for each possible activity -->\n    </tbody>\n</table>\n\n<h2>Licences, Qualifications, Regulations, and Insurances</h2>\n<table>\n    <caption>Licences, Qualifications, Regulations, and Insurances</caption>\n    <thead>\n        <tr>\n            <th>Trade</th>\n            <th>Licences & Cards</th>\n            <th>Qualifications</th>\n            <th>Regulations</th>\n            <th>Insurances</th>\n        </tr>\n    </thead>\n    <tbody>\n        <tr>\n            <td>Scaffold Erector</td>\n            <td>PASMA Card</td>\n            <td>PASMA Training Certificate</td>\n            <td>Work at Height Regulations 2005</td>\n            <td>Public Liability Insurance</td>\n        </tr>\n        <!-- Repeat for each trade -->\n    </tbody>\n</table>\n\n<h2>Method Statement</h2>\n<table>\n    <caption>Method Statement</caption>\n    <thead>\n        <tr>\n            <th>Activity</th>\n            <th>Method Statement</th>\n        </tr>\n    </thead>\n    <tbody>\n        <tr>\n            <td>Erecting a tower scaffold</td>\n            <td>\n                <ul>\n                    <li>Project: [Project Name]</li>\n                    <li>Location: [Location]</li>\n                    <li>Date of issue, revision number and approval sign off</li>\n                    <li>Equipment and load description</li>\n                    <li>Load stability before, during and after the lifting operation, including checks to be undertaken</li>\n                    <li>Pick-up and delivery points</li>\n                    <li>Sequence of operations</li>\n                    <li>Ground and operational area assessed and passed as suitable for the lifting and travelling operations to be undertaken</li>\n                    <li>Requirements for Exclusion Zones and any sequencing of other activities to maintain safe areas</li>\n                    <li>Arrangements for adequate supervision of operations</li>\n                    <li>Names of personnel involved in the lifting operation</li>\n                    <li>Training for operator, banksman and supervisor</li>\n                    <li>Authorisation of operator and supervisor</li>\n                    <li>Communicate safe method of work</li>\n                    <li>Contingency planning</li>\n                    <li>Arrangements for ensuring that equipment provided is maintained and fit for purpose</li>\n                    <li>Arrangements for ensuring that equipment (including lifting attachments) is thoroughly examined and tested at appropriate intervals</li>\n                </ul>\n            </td>\n        </tr>\n        <!-- Repeat for each activity -->\n    </tbody>\n</table>\n\n<p>Would you like to add any further activities, risks, or methods? If so, please provide the details, and I will update the risk assessment accordingly.</p>\n\n</body>\n</html>\n```\n\nThis HTML document is well-organized and visually appealing, with headings, subheadings, bullet points, and tables to enhance readability. The content is logically organized and easy to navigate. If you have any additional activities, risks, or methods to add, please provide the details, and I will update the risk assessment accordingly.",
    "data": "Based on the information extracted from the documents, I will create the required risk assessment, licenses, qualifications, regulations, and insurances table, and the method statement table. Here is the structured HTML document: \\`\\`\\`html <!DOCTYPE html>\n\n# Risk Assessment Document\n\n## Risk Assessment\n\n__Risk Assessment__\n| ACTIVITY                  | PERSON AT RISK | SIGNIFICANT HAZARDS                | RISK L | RISK S | RISK DR | RISK CONTROL MEASURES                                                                                                                                                                                                                                                                                                                                                                                                                                                      | RESIDUAL RISK L | RESIDUAL RISK S | RESIDUAL RISK DR |\n| ------------------------- | -------------- | ---------------------------------- | ------ | ------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------- | --------------- | ---------------- |\n| Erecting a tower scaffold | Operative      | Falls from height, electric shocks | 3      | 4      | 12      | Tower should be erected as per the “Through the trap” or “3T” method as recommended by the HSE. Tower scaffolds to be erected by trained personnel only, i.e. those who have been on a course approved by PASMA. Operatives should not climb on the outside of the tower at any time. Towers should only be erected on solid secure standing. Towers should not be erected underneath power lines. Guard rails edge protection and stabilisers to be used where necessary. | 2               | 4               | 8                |\n\n## Licences, Qualifications, Regulations, and Insurances\n\n__Licences, Qualifications, Regulations, and Insurances__\n| Trade            | Licences & Cards | Qualifications             | Regulations                     | Insurances                 |\n| ---------------- | ---------------- | -------------------------- | ------------------------------- | -------------------------- |\n| Scaffold Erector | PASMA Card       | PASMA Training Certificate | Work at Height Regulations 2005 | Public Liability Insurance |\n\n## Method Statement\n\n__Method Statement__\n| Activity                  | Method Statement                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |\n| ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| Erecting a tower scaffold | Project: \\[Project Name\\] Location: \\[Location\\] Date of issue, revision number and approval sign off Equipment and load description Load stability before, during and after the lifting operation, including checks to be undertaken Pick-up and delivery points Sequence of operations Ground and operational area assessed and passed as suitable for the lifting and travelling operations to be undertaken Requirements for Exclusion Zones and any sequencing of other activities to maintain safe areas Arrangements for adequate supervision of operations Names of personnel involved in the lifting operation Training for operator, banksman and supervisor Authorisation of operator and supervisor Communicate safe method of work Contingency planning Arrangements for ensuring that equipment provided is maintained and fit for purpose Arrangements for ensuring that equipment (including lifting attachments) is thoroughly examined and tested at appropriate intervals |\n\nWould you like to add any further activities, risks, or methods? If so, please provide the details, and I will update the risk assessment accordingly.\n\n\\`\\`\\` This HTML document is well-organized and visually appealing, with headings, subheadings, bullet points, and tables to enhance readability. The content is logically organized and easy to navigate. If you have any additional activities, risks, or methods to add, please provide the details, and I will update the risk assessment accordingly."
  }
]

I get

Based on the information extracted from the documents, I will create the required risk assessment, licenses, qualifications, regulations, and insurances table, and the method statement table. Here is the structured HTML document:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Risk Assessment Document</title>
    <style>
        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
        }
        th, td {
etc etc

any ideas please?

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hi @Steve_Warburton

What exactly are you trying to achieve? Can you share your workflow?