mity / md4c

C Markdown parser. Fast. SAX-like interface. Compliant to CommonMark specification.
MIT License
755 stars 138 forks source link

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

Closed luntik2012 closed 5 months ago

luntik2012 commented 5 months ago

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;
    }
mity commented 5 months ago

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.)

luntik2012 commented 5 months ago

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

mity commented 5 months ago

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.

luntik2012 commented 5 months ago

Thanks, this works fine for me

echo '<meta charset="UTF-8">' > example.html && md2html example.md >> example.html
mity commented 5 months ago

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>