joakin / markdown-folder-to-html

Convert a folder with files and markdown documents to an HTML site
122 stars 35 forks source link

Add code highlighting in the default template #14

Open joakin opened 6 years ago

joakin commented 5 years ago

See #20:

To enable syntax highlighting in very easy way, you can add to the template or to the documentation the following lines:

<script>
    (function() {
      var codeTags = document.querySelectorAll('code[class^="language-"]');
      for (var tag of codeTags) {
        tag.className = tag.className.replace("language-", "prettyprint lang-");
      }
    })();
  </script>
  <script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>

Suggestion to use code-prettify. There is also https://highlightjs.org which is also very widely used.

joakin commented 5 years ago

See #30 , the inevitable suggestion to use highlight.js came in 🙃

Maybe a good middle ground would be making it easier to extend the default template and documenting how to enhance it with things like code highlighting.

Then there would be a good way to do it without making a prescriptive choice in the tool and bloating the default template with all kinds of use cases.

valentinbdv commented 5 years ago

Indeed it works fine using the script in the template so thanks a lot for that.

I just feel like it would be more simple and clean to have it made directly when creating the html. But I understand as you said that this is not that simple.