why Special characters apostrophe and others shows like this ’, in HTMl file

3.4k views Asked by At

I have a markdown file in UTF-8 without BOM encoding format[md file generated tool from word document] . Converted this markdown to HTML using jekyll tool. The following special characters available(apostrophe,hypen so on) in md file content .

1.example content in MD:

dont't, **ListView** control

Converted HTMl format like this:

<!DOCTYPE html>
    <html>
      <head>
      <meta charset="utf-8">      
    </head>
      <body> 
      <p>dont’t, <strong>ListView</strong> control</p>
        </body>
    </html>

We can get exact result dont’t, ListView control when open the html file. I want to use the same html file loaded in to ASP.NET MVC razor view through Html.Action. syntax given below

MVC Razor view access the html file via action method:

Html.Action("GetHtmlPage", "Products", new {path = "~/Views/Products/WhatsNew/" + Model.Platform + ".html"}))

Action code:

public ActionResult GetHtmlPage(string path)
        {
            return new FilePathResult(path, "text/html");
        }

Using the above MVC syntax , i can successfully loaded HTMl file into my View. But the output are show below like in browser and HTMl template like previous format.

dont’t, ListView control
  1. Apostrope viewed as', ’
  2. Â string added after bold element.

How to view the special characters in browser , when loaded html file into razor view.? I have sticking as long as today.

2

There are 2 answers

0
Waylan On

It appears that your HTML document is advertising itself as UTF-8. However, it if is not actually in UTF-8 format, or if the Markdown file is not in UTF-8, either could be causing the characters to not actually be UTF-8 encoded characters. So check the encodings of your files.

If that doesn't resolve the problem, then you need to use HTML Entities. Or you need to use ASCII text only for punctuation.

For example, look at the apostrophe in your sample HTML, note that it is slanted at an angle (a single right quote, unicode character U+2019) as opposed to the strait apostrophe (unicode character U+0027 - which is also an ASCII character).

Note that for those characters to display reliably in HTML documents, it is best to use the HTML Entities for those characters. Therefore, the markdown document should look this this:

Don&rsquo;t, **ListView** control

The HTML entity &rsquo; tells the browser to display a single right quote, unicode character U+2019.

Note that Markdown does not convert such characters to HTML entities for you. You have to do it yourself. You could use SmartyPants to do conversions, but it converts the ASCII characters to the richer characters as HTML entities. In that case, your Markdown should look like this:

Don't, **ListView** control

Of course, you could just use the ASCII characters and not bother with SmartPants if you want.

However, be aware that if you are using MS Word, that program is configured by default to replace the ASCII character you type (using the apostrophe key on you keyboard) with the fancy character automatically. It is generally recommended that a word processor (like MS Word) not be used for editing Markdown documents for this reason. Use a plain text editor instead.

If you really must use MS Word there are a few ways to disable the auto-replace behavior. See this for more info about how word processors act with these types of characters and how to disable that behavior.

0
Richard Nienaber On

I was having this same problem with a markdown to html converter (pandoc) and I found the solution here. Just adding the following header solved my issue:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">