Repository: netbox-community/netbox

Issue:
Unable to Align Markdown Tables Values
### NetBox version

3.5.1 (also tested on 3.5.4)

### Python version

3.10

### Steps to Reproduce

1. Edit any object that supports the Comments field
2. Add a table with colons on one or both sides of the hyphens in header row, thus indicating desired alignment, such as:

```
| Left Alignment| Center Alignment | Right Aligment     |
| :---        |    :----:   |          ---: |
| Words     | Title       | Here's this   |
| Values   | Text        | And more      |
```

3. Either preview the table on the Edit page, or save the object and view the Comments field

### Expected Behavior

I expected the table to be aligned per [the documentation on markdown support](https://docs.netbox.dev/en/stable/reference/markdown/), which would involve it appearing like below:

| Left Alignment| Center Alignment | Right Aligment     |
| :---        |    :----:   |          ---: |
| Words     | Title       | Here's this   |
| Values   | Text        | And more      |

### Observed Behavior

The colons seem to be totally ignored, as shown in the screenshots below (using the same markdown syntax as above):

![image](https://github.com/netbox-community/netbox/assets/16410007/33b7ce9e-851a-4de3-971f-912cf2f0bf18)

![image](https://github.com/netbox-community/netbox/assets/16410007/05d2ef73-fd87-4a49-8a24-02a0dbbf66e1)



Discussion:
I wanted to fix this, but there's really no good solution right now because of python dependency hell.

It's easily fixable by adding:

```
        "th": ["align"],
        "td": ["align"],
```

https://github.com/netbox-community/netbox/blob/0f0cf683c44f058a72a50fa90b889ab3fc6bea08/netbox/utilities/utils.py#L521

Here, but this doesn't fix th as boostrap has some css that sets the text-align property, and it's not possible to unset.

The Markdown library extension for tables does support setting a css class instead of the align attribute, but that was added in 3.4.x. We can't use 3.4.x because of:

```
The conflict is caused by:
    The user requested Markdown==3.4.3
    mkdocs-material 9.1.18 depends on markdown>=3.2
    mkdocstrings[python-legacy] 0.22.0 depends on Markdown>=3.3
    mkdocs 1.4.3 depends on markdown<3.4 and >=3.2.1
    The user requested Markdown==3.4.3
    mkdocs-material 9.1.18 depends on markdown>=3.2
    mkdocstrings[python-legacy] 0.22.0 depends on Markdown>=3.3
    mkdocs 1.4.2 depends on markdown<3.4 and >=3.2.1
```

This is caused by the maintainer of mkdocs that limited the max version of markdown for years:

https://github.com/mkdocs/mkdocs/pull/3222 (not part of a release yet)

It's still not in a realease, so we can't update the Markdown package past 3.3.x and as such we cannot get the updated tables extension. So we would have to hack a fix on our own.

If anyone wants to figure this out, feel free to. We could copy the upstream table extension and just vendor it I guess or maybe there's some hack in CSS that I don't know about where you can unset a css property. Anyway I'm done trying to work around pythons insane packaging rules.

Resolving patch:
diff --git a/netbox/utilities/utils.py b/netbox/utilities/utils.py
--- a/netbox/utilities/utils.py
+++ b/netbox/utilities/utils.py
@@ -519,6 +519,8 @@ def clean_html(html, schemes):
         "h1": ["id"], "h2": ["id"], "h3": ["id"], "h4": ["id"], "h5": ["id"], "h6": ["id"],
         "a": ["href", "title"],
         "img": ["src", "title", "alt"],
+        "th": ["align"],
+        "td": ["align"],
     }
 
     return bleach.clean(


Test patch: