将markdown(md)嵌入到HTML中 [英] Embed markdown (md) into HTML

查看:1544
本文介绍了将markdown(md)嵌入到HTML中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助在HTML索引文件中嵌入标记或* .md文件。我发现我可以在标记中嵌入HTML,但反之亦然。这将有助于提高我的编辑速度,因为降价格式非常易于使用(正如我现在使用的那样),而且我不必更改其余站点的格式。我知道这样做是为了嵌入另一个带有< iframe src =path / to / html> html-name< / iframe> 的HTML文件。使用javascript解释页面加载时的md格式。提前感谢。

解决方案

这是我早已忘记的解决方案about:





忘记我问了这个问题并没有得到答案,我创建了自己的解决方案,作为Chris Jeffrey的 marked.js 的扩展。



我称之为 tagdown.js



这里是: http://spikespaz.com/tagdownjs/



以防链接或我的域名过期: https: //spikespaz.github.io/tagdownjs/



Github: https://github.com/spikespaz/tagdownjs



这可以将标记直接添加到网站中,并在类 markdown 的标记集内进行添加。查看网站上的示例。



更新



该项目TagdownJS,已从Github中删除。它的代码看起来很简单,它不应该拥有自己的存储库。



在找到一个新家之前,只需要找到Christopher Jeffery的Marked.js,然后使用这下面的代码。

  document.body.style.display =none; //隐藏页面直到完成渲染。 

document.createElement(markdown);
var md_tags = document.getElementsByTagName(markdown); //返回所有markdown标签的数组。

for(var i = 0; i< md_tags.length; i ++){//遍历所有标签,并生成HTML。
var md_text = md_tags [i] .textContent.replace(/ ^ [^ \S\\\
] + / mg,); //我喜欢正则表达式,所以拍摄我。

var md_div = document.createElement(div); //创建一个新的div来替换伪造的标签。
md_div.id =content;
md_div.innerHTML =标记(md_text);

md_tags [i] .parentNode.appendChild(md_div); //添加删除旧的原始降价。
md_tags [i] .parentNode.removeChild(md_tags [i]);
}

document.body.style.display =; //显示呈现的页面。


I need help embedding a markdown, or *.md, file inside of an HTML index file. I have found that I can embed HTML inside of markdown, but not vice-versa. This would help to increase the speed of my editing because markdown format is extremely easy to use, (as I'm using it now) and I don't have to change the format of the rest of my site. I know that something like this is done to embed another HTML file with <iframe src="path/to/html>html-name</iframe>. I could also use javascript to interpret the md format on page load. Thanks ahead of time.

解决方案

Here's the solution that I have long since forgotten about:

Forgetting that I asked this question and getting no answers, I created my own solution as an extension off of Chris Jeffrey's marked.js.

I call it tagdown.js.

Here it is: http://spikespaz.com/tagdownjs/

Just in case that link, or my domain, expires: https://spikespaz.github.io/tagdownjs/

Github: https://github.com/spikespaz/tagdownjs

This allows markdown to be added directly to the site, within a tag set with the class markdown. See the example on the site. There is no theme system in it, it's just the markdown parser.

Update

The project, TagdownJS, has been deleted from Github. The code for it seems so simple that it doesn't deserve its own repository.

Until it finds a new home, just go find Christopher Jeffery's Marked.js, and use this following code with it.

document.body.style.display = "none"; // Hide the page until it's finished rendering.

document.createElement("markdown");
var md_tags = document.getElementsByTagName("markdown"); // Returns array of all markdown tags.

for (var i = 0; i < md_tags.length; i++) { // Iterate through all the tags, and generate the HTML.
    var md_text = md_tags[i].textContent.replace(/^[^\S\n]+/mg, ""); // I love regex, so shoot me.

    var md_div = document.createElement("div"); // Make a new div to replace the fake tag.
    md_div.id = "content";
    md_div.innerHTML = marked(md_text);

    md_tags[i].parentNode.appendChild(md_div); // Add remove the old raw markdown.
    md_tags[i].parentNode.removeChild(md_tags[i]);
}

document.body.style.display = ""; // Show the rendered page.

这篇关于将markdown(md)嵌入到HTML中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆