Julie20
Julie20

Reputation: 228

Displaying bullet formatting in html using c#

An example that I have that could direct me into the right direction is this:

String Text = Text.Replace(Environment.NewLine, "<br />");

I understand what this is going to do. But the issue is this: I have a memo box on my website a user types in a bulleted list in this memo box and then it appears as html on my webpage.

Example of Bulleted list:

• Item 1

  • List item 1.1
  • List item 1.2

When it displays in the website as HTML the Bulleted list looks like this:

• Item1

o List item 1.1

o List item 1.2

It loses its indentation. Code that i have found and tried only gave indentation once

String Text = Text .Replace("\t\t", "&nbsp; &nbsp; &nbsp; &nbsp;");

This does work, but it does not give indentation to the second level of the bulleted list. I have also no idea how to find it when a bullet is on the second level and then just double the spaces if it is like that.

Any insight will be very helpfull as I have hit a wall with this. I am using C# to replace characters with html

Upvotes: 1

Views: 2176

Answers (2)

Julie20
Julie20

Reputation: 228

After alot of research i found a way that sort of fit my needs.

What i had to do was use this plugin instead. That way the user can add bulleted list and the indentation would be the same on the webpage. I however ran into another problem while using this plugin where i got the error "A potentially dangerous Request.Form value was detected from the client". I found an answer here that solved my problem for that too. It is now working as it should.

Upvotes: 1

Ryan McDonough
Ryan McDonough

Reputation: 10012

You will need to replace the breaks with <li></li> tags if you are planning to render a list on a website.

A list of items on a website usually follows the following syntax:

<ol>
    <li>Item 1</li>
    <li>Item 2</li>
</ol>

You can also have sublists e.g:

<ol>
    <li>Item 1    
<ol>
    <li>Sub Of Item 1</li>
    <li>Sub Of Item 1</li>
</ol>
</li>
    <li>Item 2</li>
</ol>

I would suggest having the memobox on the website work as a HTML editor rather than save rich text and then trying to convert that to HTML.

Upvotes: 0

Related Questions