bsherin / tactic

5 stars 1 forks source link

create some good way of applying styles to notebooks or at least keeping them local #1204

Open bsherin opened 1 month ago

bsherin commented 1 month ago

create some good way of applying styles to notebooks or at least keeping them local

bsherin commented 2 weeks ago

I created a code resource that makes it possible to keep them local.

def insert_styles(the_styles):
    script = f"""
        <div id="my-output"></div>
        <script id='myScript'>
            function getEnclosingDivId() {{
                var scriptTag = document.getElementById('myScript');
                var enclosingDiv = scriptTag.closest('.main-root');
                var divId = enclosingDiv ? enclosingDiv.id : null;
                return divId
            }}
            var divId = getEnclosingDivId();
            var div = document.getElementById('my-output');
            div.innerHTML = `
                <style> 
                    #${{divId}} {{
                        {the_styles}
                }}
                </style>`
        </script>
    """
    print(script)