I'm using hexo to create post pages with code snippets, I'm doing it via node cause I'm writing a module to create style guides and I'd like to mantain a customizable HTML instead to use an article generated by markdown code only.
hexo = new Hexo(process.cwd(), {
debug: false,
config: fromModule('_config.yml')
});
hexo.init().then(function(){
var postData;
for (var i = 0; i < widgetFiles.length; i += 1) {
postData = formatter.toHexo(widgetFiles[i]);
postData.content = widget.toMarkdown(widgetFiles[i], conf);
// tracing HTML snippet
console.log(postData.docs[0].htmlSnippet);
hexo.post.create(postData, true);
}
});
My only problem is the htmlSnippet var which goes into hexo.post.create method well formatted as the example below but comes badly formatted on the ejs template, where I'd like to use hexo markdown plugin.
Before hexo.post.create(postData, true); using console.log(postData[i][0].htmlSnippet); as the upper example
Then after the post is created, on ejs template, using <% console.log(post.docs[0].htmlSnippet) %> give these strange additional new lines in the code:
I'm using hexo to create post pages with code snippets, I'm doing it via node cause I'm writing a module to create style guides and I'd like to mantain a customizable HTML instead to use an article generated by markdown code only.
My only problem is the
htmlSnippet
var which goes intohexo.post.create
method well formatted as the example below but comes badly formatted on theejs
template, where I'd like to use hexo markdown plugin.Before
hexo.post.create(postData, true);
usingconsole.log(postData[i][0].htmlSnippet);
as the upper exampleThen after the post is created, on
ejs
template, using<% console.log(post.docs[0].htmlSnippet) %>
give these strange additional new lines in the code:I also noticed that if I use
<%- markdown(post.docs[0].htmlSnippet) %>
from the ejs template it doesn't show code line numbers: https://github.com/vitto/a-pollo/blob/master/hexo/themes/a-pollo/layout/_partial/widget-body.ejs#L22If I use
<%- markdown(post.content) %>
it renders the block with also line number and everything well formatted as I expected: https://github.com/vitto/a-pollo/blob/master/lib/markdown.js#L49How can I solve the wrong code snippet indentation problem?
If you'd like to test it by your own:
First time installation:
Then, just:
To switch the configurations, in
a-pollo.yml
just change the boolean value