66__all__ = ['marked_imp' , 'npmcdn' , 'light_media' , 'dark_media' , 'MarkdownJS' , 'KatexMarkdownJS' , 'HighlightJS' , 'SortableJS' ,
77 'MermaidJS' ]
88
9- # %% ../nbs/api/03_js.ipynb #ddc8b61a
9+ # %% ../nbs/api/03_js.ipynb #cd3eb2a3
1010import re
1111from fastcore .utils import *
1212from fasthtml .components import *
1313from fasthtml .xtend import *
1414
15- # %% ../nbs/api/03_js.ipynb #4c8d1272
15+ # %% ../nbs/api/03_js.ipynb #f7792683
1616def light_media (
1717 css : str # CSS to be included in the light media query
1818 ):
1919 "Render light media for day mode views"
2020 return Style ('@media (prefers-color-scheme: light) {%s}' % css )
2121
22- # %% ../nbs/api/03_js.ipynb #26cd2ccc
22+ # %% ../nbs/api/03_js.ipynb #0a2307c3
2323def dark_media (
2424 css : str # CSS to be included in the dark media query
2525 ):
2626 "Render dark media for night mode views"
2727 return Style ('@media (prefers-color-scheme: dark) {%s}' % css )
2828
29- # %% ../nbs/api/03_js.ipynb #c7cd64ef
29+ # %% ../nbs/api/03_js.ipynb #f60ca53b
3030marked_imp = """import { marked } from "https://cdn.jsdelivr.net/npm/marked/lib/marked.esm.js";
3131"""
3232npmcdn = 'https://cdn.jsdelivr.net/npm/'
3333
34- # %% ../nbs/api/03_js.ipynb #857e3fe6
34+ # %% ../nbs/api/03_js.ipynb #3e318ccd
3535def MarkdownJS (
3636 sel = '.marked' # CSS selector for markdown elements
3737 ):
3838 "Implements browser-based markdown rendering."
3939 src = "proc_htmx('%s', e => e.innerHTML = marked.parse(e.textContent));" % sel
4040 return Script (marked_imp + src , type = 'module' )
4141
42- # %% ../nbs/api/03_js.ipynb #fa5b6642
42+ # %% ../nbs/api/03_js.ipynb #595d4e8f
4343def KatexMarkdownJS (
4444 sel = '.marked' , # CSS selector for markdown elements
4545 inline_delim = '$' , # Delimiter for inline math
@@ -54,7 +54,7 @@ def KatexMarkdownJS(
5454 css = Link (
rel = "stylesheet" ,
href = npmcdn + "[email protected] /dist/katex.min.css" )
5555 return scr ,css
5656
57- # %% ../nbs/api/03_js.ipynb #c8144d89
57+ # %% ../nbs/api/03_js.ipynb #7a2a45ef
5858def HighlightJS (
5959 sel = 'pre code:not([data-highlighted="yes"])' , # CSS selector for code elements. Default is industry standard, be careful before adjusting it
6060 langs :str | list | tuple = 'python' , # Language(s) to highlight
@@ -77,7 +77,7 @@ def HighlightJS(
7777 jsd (* hjc , 'highlightjs-copy.min.css' , typ = 'css' ),
7878 * langjs , Script (src , type = 'module' )]
7979
80- # %% ../nbs/api/03_js.ipynb #9004c11b
80+ # %% ../nbs/api/03_js.ipynb #59c00b7d
8181def SortableJS (
8282 sel = '.sortable' , # CSS selector for sortable elements
8383 ghost_class = 'blue-background-class' # When an element is being dragged, this is the class used to distinguish it from the rest
@@ -88,7 +88,7 @@ def SortableJS(
8888""" % sel
8989 return Script (src , type = 'module' )
9090
91- # %% ../nbs/api/03_js.ipynb #0e060ddb
91+ # %% ../nbs/api/03_js.ipynb #3518340d
9292def MermaidJS (
9393 sel = '.language-mermaid' , # CSS selector for mermaid elements
9494 theme = 'base' , # Mermaid theme to use
0 commit comments