# Ansi to ascii or html

**URL:** <https://discourse.nodered.org/t/ansi-to-ascii-or-html/80364>\
**Category:** Dashboard\
**Tags:** node-red-dashboard\
**Created:** [7 August 2023 07:50 UTC](https://discourse.nodered.org/t/ansi-to-ascii-or-html/80364 "2023-08-07T07:50:21Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![nelgin](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@nelgin](https://discourse.nodered.org/u/nelgin)\
**Post date:** [7 August 2023 07:50 UTC](https://discourse.nodered.org/t/ansi-to-ascii-or-html/80364/1 "2023-08-07T07:50:21Z")

</div>

Hi all,

I receive data that has ansi color coding and graphics and would like to translate it to make it somewhat more readable. Any suggestions on how I can do that without having to write my own function to translate all the codes to html text and some sort of graphic representation?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/c/ac863241a8c5a0c9ae2f2d7048bbffa26dac4807.png)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [7 August 2023 08:05 UTC](https://discourse.nodered.org/t/ansi-to-ascii-or-html/80364/2 "2023-08-07T08:05:44Z")

</div>

How are you getting this data?

---

<div class="post-metadata">

**Author:** ![nelgin](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@nelgin](https://discourse.nodered.org/u/nelgin)\
**Post date:** [7 August 2023 08:07 UTC](https://discourse.nodered.org/t/ansi-to-ascii-or-html/80364/3 "2023-08-07T08:07:31Z")

</div>

Using the mqtt-in node.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [7 August 2023 08:12 UTC](https://discourse.nodered.org/t/ansi-to-ascii-or-html/80364/4 "2023-08-07T08:12:08Z")

</div>

I should have been clearer.where does the data originate from?

---

<div class="post-metadata">

**Author:** ![nelgin](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@nelgin](https://discourse.nodered.org/u/nelgin)\
**Post date:** [7 August 2023 08:14 UTC](https://discourse.nodered.org/t/ansi-to-ascii-or-html/80364/5 "2023-08-07T08:14:16Z")

</div>

Does it make a difference as to where it comes from? It comes from my bulletin board.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [7 August 2023 08:27 UTC](https://discourse.nodered.org/t/ansi-to-ascii-or-html/80364/6 "2023-08-07T08:27:08Z")

</div>

What you are seeing are ANSI terminal formatting codes. You would have to either make the originator of the msg stop sending them (normally telling it that it isn't using a color terminal should do the trick if it is well programmed), or by adding a node or two to strip them out in Node-RED. There might be an npm package that would do this - check on [npmjs.org](http://npmjs.org) and if there is, you could use it with a function node.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [7 August 2023 08:30 UTC](https://discourse.nodered.org/t/ansi-to-ascii-or-html/80364/7 "2023-08-07T08:30:09Z")

</div>

Knowing the origin of data helps to understand the format its format. If you got it from a bulletin board, it was sent by something or someone. If you have control of that, you should format it in a more user friendly way. If you don't have control of it then you will have to format it yourself.

Is the format of the data always the same?

Not knowing what information you need from that data makes it hard to even begin to make suggestions.

---

<div class="post-metadata">

**Author:** ![nelgin](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@nelgin](https://discourse.nodered.org/u/nelgin)\
**Post date:** [7 August 2023 08:33 UTC](https://discourse.nodered.org/t/ansi-to-ascii-or-html/80364/8 "2023-08-07T08:33:45Z")

</div>

Not at all, it could be anything that is received, nothing standard. This is why I was asking whether anyone knows a way to either strip or convert it without me having to do it manually. If I could have stripped it first, I would have and we wouldn't be having this conversation 🙂

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [7 August 2023 08:39 UTC](https://discourse.nodered.org/t/ansi-to-ascii-or-html/80364/9 "2023-08-07T08:39:01Z")

</div>

You might want to use google and search for `how to strip out ANSI terminal formatting codes`  
Better yet use `remove ansi color codes javascript` in the search

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [7 August 2023 08:40 UTC](https://discourse.nodered.org/t/ansi-to-ascii-or-html/80364/10 "2023-08-07T08:40:12Z")

</div>

There are quite a few libs on npm that you can import in a function node (setup tab, imports). There are libs to strip the colour codes, or even convert the garbled strings into colourful HTML.

> **[ansi html - npm search](https://www.npmjs.com/search?q=ansi%20html)**

---

<div class="post-metadata">

**Author:** ![nelgin](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@nelgin](https://discourse.nodered.org/u/nelgin)\
**Post date:** [7 August 2023 08:45 UTC](https://discourse.nodered.org/t/ansi-to-ascii-or-html/80364/11 "2023-08-07T08:45:40Z")

</div>

Thanks Steve, I'm really not familiar with npm so this is useful. I'm not sure how to incorporate that into a module but I'm sure a Google search will help.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [7 August 2023 08:46 UTC](https://discourse.nodered.org/t/ansi-to-ascii-or-html/80364/12 "2023-08-07T08:46:27Z")

</div>

This site might help [How to strip ansi codes from a string in JavaScript - QuickRef.ME](https://quickref.me/strip-ansi-codes-from-a-string.html)

---

<div class="post-metadata">

**Author:** ![nelgin](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@nelgin](https://discourse.nodered.org/u/nelgin)\
**Post date:** [7 August 2023 08:46 UTC](https://discourse.nodered.org/t/ansi-to-ascii-or-html/80364/13 "2023-08-07T08:46:45Z")

</div>

I don't want to appear rude or anything, but I do know how to strip characters. I have already said I don't want to have to do it manually. It looks like Steve has provided a viable answer.

Answer, what I wanted to do is try and preserve the output but in html to keep the overall look of the page, however yes, if it comes to the last resort I'll strip it.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [7 August 2023 08:47 UTC](https://discourse.nodered.org/t/ansi-to-ascii-or-html/80364/14 "2023-08-07T08:47:43Z")

</div>

This might help you...

> **[Use any npm module in Node-RED • FlowForge](https://flowforge.com/blog/2023/06/import-modules/)**
>
> Node-RED has an incredibly rich resource of integrations available, but sometimes you need that little extra. This shows you how.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [6 September 2023 08:48 UTC](https://discourse.nodered.org/t/ansi-to-ascii-or-html/80364/15 "2023-09-06T08:48:33Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
