Description
First Check
- I added a very descriptive title here.
- This is not a Q&A. I am sure something is wrong with NiceGUI or its documentation.
- I used the GitHub search to find a similar issue and came up empty.
Example Code
#!/usr/bin/env python3
from router import Router
from nicegui import ui
@ui.page("/") # normal index page (e.g. the entry point of the app)
@ui.page(
"/{_:path}"
) # all other pages will be handled by the router but must be registered to also show the SPA index page
def main():
router = Router()
@router.add("/")
def show_one():
ui.label("Content One").classes("text-2xl")
@router.add("/two")
def show_two():
ui.label("Content Two").classes("text-2xl")
@router.add("/three")
def show_three():
ui.label("Content Three").classes("text-2xl")
ui.markdown("""
print("hello world")
""")
# adding some navigation buttons to switch between the different pages
with ui.row():
ui.button("One", on_click=lambda: router.open(show_one)).classes("w-32")
ui.button("Two", on_click=lambda: router.open(show_two)).classes("w-32")
ui.button("Three", on_click=lambda: router.open(show_three)).classes("w-32")
# this places the content which should be displayed
router.frame().classes("w-full p-4 bg-gray-100")
ui.run()
Description
Above is a small variation on the single_page_app example that uses the ui.markdown
element.
When you load the page "three", the code is not properly highlighted. The JS console shows an error:
The stylesheet http://localhost:8080/_nicegui/2.17.0/codehilite.css was not loaded because its MIME type, "text/html", is not "text/css".
At first sight, this only occurs for /codehilite.css
, not for /static/...
or /libraries/...
.
Is this due to the way how/when codehilite.css
is mounted?
NiceGUI Version
2.17.0
Python Version
3.11.9
Browser
Firefox
Operating System
Windows
Additional Context
If I add ui.markdown()
just after from nicegui import ui
, the issue is resolved. I guess that forces the codehilite.css route to be added before {_:path}
, thereby getting higher priority.
Can this be fixed in the source, so this workaround is not necessary? E.g. add markdown: bool
to ui.run()
which is default True
.