mity / md4c

C Markdown parser. Fast. SAX-like interface. Compliant to CommonMark specification.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

md2html not outputing <meta charset="UTF-8">

luntik2012 opened this issue · comments

Hi,
I'm a complete noob in html and web, I'm trying to serve single page generated by md2html using nginx.

The problem is that my file is utf8-encoded and browsers show garbage instead of expected symbols. I've resolved this problem by adding <meta charset="UTF-8"> to the beginning of the md2html output.

Is it possible to add this tag automatically using md2html? Am I doing something wrong?

My nginx config:

	server {
	  listen [::]:80;
	  server_name example.com;

	  charset utf-8;
          try_files $uri /example.html;
          root /usr/share/webapps/example;
	}

Sorry, md2c is not our thing.

This project only provides Markdown parser lib (libmd4c.so), Markdown-to-HTML lib (libmd4c-html.so) and simple line wrapper tool md2html. So you're quite possibly on the wrong place unless someone wrote md2c atop MD4C without our knowledge (but even then you should likely start with that person/team.)

Sorry, it was a typo (md4c + md2html -> md2c, but should be md2html)

Yes, md2html should likely add that into the output. It' sort of legacy of being primarily written as a test tool for MD4C lib and sort of only created as a tool of its own as afterthought.

As a workaround, you may use it without --full-html and create the complete HTML head/footer on your own. The --full-html will ever be likely useful only to users with very basic needs.

Thanks, this works fine for me

echo '<meta charset="UTF-8">' > example.html && md2html example.md >> example.html

It may more-or-less work (with some browsers) but strictly speaking you generate invalid HTML that way.

See https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML/The_head_metadata_in_HTML#what_is_the_html_head

md2html without the flag --full-html generates only that contents stuff between <body> and </body> so you should prepend the whole head

<html>
<head>
.....  <!-- custom stuff whatever your needs here are, including all the <meta charset="UTF-8"> -->
</head>
<body>

and respective footer

</body>
</html>