File size: 2,120 Bytes
9d8008e
0760113
9d8008e
 
 
 
 
 
 
 
 
 
 
0760113
9d8008e
 
 
 
 
0760113
9d8008e
 
 
 
 
 
 
0760113
 
 
9d8008e
 
 
 
 
 
0760113
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9d8008e
 
 
 
 
 
 
073cfb5
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import fasthtml.common as fh
from fasthtml.js import Script, jsd


def HighlightJS(
    sel="pre code",  # CSS selector for code elements. Default is industry standard, be careful before adjusting it
    langs: str | list | tuple = "python",  # Language(s) to highlight
    light="atom-one-light",  # Light theme
    dark="atom-one-dark",  # Dark theme
):
    "Implements browser-based syntax highlighting. Usage example [here](/tutorials/quickstart_for_web_devs.html#code-highlighting)."
    src = (
        """
// hljs.addPlugin(new CopyButtonPlugin());
hljs.configure({'cssSelector': '%s'});
htmx.onLoad(hljs.highlightAll);"""
        % sel
    )
    hjs = "highlightjs", "cdn-release", "build"
    # hjc = "arronhunt", "highlightjs-copy", "dist"
    if isinstance(langs, str):
        langs = [langs]
    langjs = [jsd(*hjs, f"languages/{lang}.min.js") for lang in langs]
    return [
        jsd(*hjs, f"styles/{dark}.css", typ="css", **{"x-bind:disabled": "darkMode !== 'dark'"}),
        jsd(*hjs, f"styles/{light}.css", typ="css", **{"x-bind:disabled": "darkMode !== 'light'"}),
        jsd(*hjs, "highlight.min.js"),
        # jsd(*hjc, "highlightjs-copy.min.js"),
        # jsd(*hjc, "highlightjs-copy.min.css", typ="css"),
        # fh.Style(".hljs-copy-button {background-color: #2d2b57;}", **{"x-bind:disabled": "darkMode !== 'light'"}),
        *langjs,
        Script(src, type="module"),
    ]


def alpine():
    return (
        fh.Script(src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn.min.js", defer=True),
        fh.Style("[x-cloak] {\n display: none !important; \n}"),
    )


def social_card():
    return fh.Socials(
        title="HTMX examples with FastHTML",
        description="Reproduction of HTMX official examples with Python FastHTML",
        site_name="phihung-htmx-examples.hf.space",
        twitter_site="@hunglp",
        image="/social.png",
        url="https://phihung-htmx-examples.hf.space",
    )


def concat(*elts, sep=" | "):
    out = [elts[0]]
    for elt in elts[1:]:
        out += [sep, elt]
    return out


def piwik():
    return Script(src="piwik.js")