<jupyter_start><jupyter_text>[Getting started | Less.js](http://lesscss.org/)http://lesscss.org/usage/programmatic-usage<jupyter_code>from IPython.display import HTML, display, clear_output
import uuid

import jinja2
from jinja2 import Template


LESS_URL = "https://cdnjs.cloudflare.com/ajax/libs/less.js/2.5.3/less"


div_id = 'i' + str(uuid.uuid4())

JS = u"""
<script type="text/javascript">

    // load css if it's not already there: http://stackoverflow.com/a/4724676/7782
    function loadcss(url) {
        if (!$("link[href='" + url + "']").length)
            $('<link href="' + url + '" rel="stylesheet">').appendTo("head");
    }

    require.config({
      paths: {
        less: "{{less_url}}"
      }
    });

     
    require(["less"], function(less) {
    
        less_text = '#header {\
          color: black;\
          .navigation {\
            font-size: 12px;\
          }\
          .logo {\
            width: 300px;\
          }\
        }';
        
        less.render(less_text, function (e, output) {
          console.log(output.css);
        });
    
    });

</script>
"""

# demonstrates interference from .rendered_html CSS

CSS = """
<style type="text/css">
    #{{div_id}} { }
</style>
"""

HTML_ = """
<div id="{{div_id}}">
  <span>hello</span>
</div>
"""

template = Template(CSS + JS + HTML_)
HTML(template.render(div_id = div_id,
                     less_url=LESS_URL
                      ))<jupyter_output><empty_output><jupyter_text>Python less library[lesscpy/lesscpy](https://github.com/lesscpy/lesscpy)<jupyter_code>css = u"""
#header {
  color: black;
  .navigation {
    font-size: 12px;
  }
  .logo {
    width: 300px;
  }
}
"""

import lesscpy
from six import StringIO

print(lesscpy.compile(StringIO(css), minify=True))<jupyter_output>#header{color:black;}
#header .navigation{font-size:12px;}
#header .logo{width:300px;}
{'fraction_non_alphanumeric': 0.17465388711395102, 'fraction_numerical': 0.01703940362087327, 'mean_word_length': 2.58587786259542, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '648590', 'license': 'Apache-2.0', 'n_tokens_mistral': 682, 'n_tokens_neox': 644, 'n_words': 112, 'path': 'notebooks/less_js.ipynb', 'repo_name': 'rdhyee/webtech-learning', 'size': '1878'}