How to write markdown language in HTML language?

泄露秘密 提交于 2021-02-10 19:19:36

问题


# (and ## and ###) in md files has the meaning of header 1 (2, 3).

This md (markdown) header is used by a table of content widget I developed.

I want to use a md header (written as #) that is defined in ejs (template engine) html layout file. How to write # in ejs (html) language so that it is also used by TOC widget same way as # in markdown md file?

To be more clear:

The # in markdown md file language is the same as <%= header %> when written in ejs (html) language? I am looking how to write # in EJS (html) language. For example, it could be something like this maybe (I do not know, but just to illustrate my question): # in markdown language equals <%= header %> in ejs (html) ?????

Apparently, my question is still not clear. It is simple: How to write # (markdown language) in ejs (html) language so that the code from the ejs (html) file is parsed the same way as # in markdown? It


回答1:


You can use marked package for that. Example:

$(document).ready(function(){
  var content = $('.my-md').html();
  $('.my-md').html(marked(content));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.6/marked.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="container">
 <div class="my-md">
# Hello world
This is ** a simple test ** .
  </div>
</div>
 


来源:https://stackoverflow.com/questions/46511240/how-to-write-markdown-language-in-html-language

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!