本文介绍了将一个较小的字符串传递给less.js并接收css?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在less.js中有一个函数来传递一个较少代码的字符串并返回css代码?我希望能创建一个更少的编辑环境,所以用户可以编辑较少的字符串,我可以重新编译它,并显示CSS。我看到有一个php解决方案:,但想留在js如果它是一种可能性。谢谢!

Is there a function in less.js to pass a string of less code and return css code? I'm hoping to make a live less editing environment, so the user could edit the less string and I can recompile it and display the css. I see there is a php solution: http://leafo.net/lessphp/ but would like to stay in js if it's a possibility. Thanks!

推荐答案

您可以实例化less.Parser。查看它实际上变得很容易:

You can instantiate the less.Parser. Looking at the browser.js source it actually turned out to be quite easy:

var cssString = '@color: #FFFF00; body { color: @color; }';
new(less.Parser)().parse(cssString, function (e, tree) {
    var css = tree.toCSS();
    alert(css);
});

这篇关于将一个较小的字符串传递给less.js并接收css?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 23:24