matteodf / html-to-slack

A module to convert HTML strings to Slack blocks
GNU General Public License v3.0
6 stars 1 forks source link

Ordered List create invalid `rich_text_list` #5

Closed FredericEspiau closed 3 months ago

FredericEspiau commented 3 months ago

Describe the bug

Generated block has a indent value of null

To Reproduce

Input file

<ul>
  <li>
    name of pr
    <a href="https://github.com/reponame/reponame/pull/1605"
      >https://github.com/reponame/reponame/pull/1605</a
    >
  </li>
</ul>

Will give

[
  {
    "type": "rich_text",
    "elements": [
      {
        "type": "rich_text_list",
        "style": "bullet",
        "elements": [
          {
            "type": "rich_text_section",
            "elements": [
              {
                "type": "text",
                "text": "name of pr"
              },
              {
                "type": "link",
                "url": "https://github.com/reponame/reponame/pull/1605",
                "text": "https://github.com/reponame/reponame/pull/1605"
              }
            ]
          }
        ],
        "indent": null
      }
    ]
  }
]

ident is null

This is because here: https://github.com/matteodf/html-to-slack/blob/main/src/utils/index.ts#L68

The first parameter for the replace is not indented like the input so it can't match and the second parameter isn't inserted

input is

<ul><li>name of pr<a href="https://github.com/reponame/reponame/pull/1605"
      >https://github.com/reponame/reponame/pull/1605</a></li></ul>

The first parameter is

<ul><li>name of pr<a href="https://github.com/reponame/reponame/pull/1605">https://github.com/reponame/reponame/pull/1605</a></li></ul>

Expected behavior

Having 0 for the indent

matteodf commented 3 months ago

Hi @FredericEspiau , thanks for the report! I have included a fix to ensure the HTML strings are properly formatted before processing them. Let me know if this fixes the problem!

If you have any suggestions or other reports, please feel free to open new issues or PRs, and if you think my work was helpful in any way, a star on the repo is always welcome!