This topic was automatically generated from Slack. You can find the original thread here.
I want to post some HTML into a form.
The HTML will look like this:
<!-- wp:paragraph -->
<p>When the police searched the car, they found nearly $75,000 in cash and a small clear bag containing 31 white oxycodone tablets. According to the <a href="https://www.cdc.gov/opioids/basics/prescribed.html" target="_blank" rel="noreferrer noopener">CDC</a>, oxycodone is an opioid drug that treats pain and can be highly addictive. Overdosing on prescription opioids can stop breathing and lead to death.</p>
<!-- /wp:paragraph -->
Can you write me a code where I can pass the variable and format the HTML so I don’t get errors?
Sure, I can provide you with a Pipedream component code that takes the HTML content as input and returns the formatted content. Here’s an example: import { html } from "js-beautify"; export default defineComponent({ props: { content: { type: "string", label: "Content", description: "Input your HTML content here", }, }, async run({ steps, $ }) { const formatted_content = html(this.content, { unformatted: ['p', 'a'], indent_size: 2 }); return { formatted_content }; }, }); In this code, we’re using the js-beautify package to format the HTML content. The content prop is used to take the HTML content as input. The run method formats the HTML content and returns it as formatted_content. Please replace this.content with your actual HTML content. The formatted HTML content will be returned in the formatted_content field.
I apologize for the confusion. The error message indicates that the ‘js-beautify’ module does not have an export named ‘html’. This could be due to the way the module is structured or how it’s being imported. In Pipedream, you should use ESM (ECMAScript modules) for imports. However, not all npm packages support ESM. If ‘js-beautify’ does not support ESM, you might encounter issues when trying to import it using ESM syntax. Unfortunately, Pipedream does not currently support the ‘require’ syntax for importing modules, which is typically used for CommonJS modules. As an alternative, you can use a built-in Node.js module like ‘util’ to format your HTML content. Here’s an example: ```
import { inspect } from “util”; export default defineComponent({ props: { content: { type: “string”, label: “Content”, description: “Input your HTML content here”, }, }, async run({ steps, $ }) { const formatted_content = inspect(this.content, { depth: null, colors: true }); return { formatted_content }; }, });