-
-
Notifications
You must be signed in to change notification settings - Fork 759
codehilite.css not loaded in single_page_app example #4774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for reporting this issue, @platinops! I just mentioned a related observation a few hours ago: #4539 (review). For whatever reason codehilite.css is served under an unusual route which seems to be handled by the |
Hmm interesting. I have to ask: Why was codehilite CSS dynamically generated on-the-fly for every NiceGUI app launch? It has always been like this since 6d67e9c I'd imagine we can pre-generate the CSS and then toss it to lib/codehilite/codehilite.css in the distribution, and use the normal |
@evnchn I can't remember the exact reasoning behind 6d67e9c, but dynamic generation
Therefore I would keep generating the CSS dynamically, but serve it via |
I was contemplating that too, but it isn't a perfect solution. Check if you agree:
|
I mostly agree. Some more thoughts: Option 1: Writing to lib/codehilite/codehilite.css at runtime could also be difficult due to missing permissions. Thinking about codehilite.css more broadly: I just noticed it defines a line height for <pre> tags globally: ui.add_css('pre { line-height: 5.0; }')
ui.html('''
<pre>
Foo
Bar
</pre>
''')
ui.markdown('Hello') # Removing this line has impact on the distance between "Foo" and "Bar". I wonder if we could convert markdown.js into a SFC markdown.vue inlining codehilite.css and scoping its style defitions. But as outlined above, it would be better to generate the CSS at runtime to guarantee compatibility with the HTML code. |
I guess we can agree that we eliinate option 1 and 2, and establish that the HTML is best to be generated dynamically to avoid any mismatch possibilities (since it cheap anyways) I think
|
@falkoschindler https://github.com/evnchn/nicegui/tree/dynamic-resources Works on my machine. PR coming later. Supermarket 5pm has discount, let me grab that first! |
Actually, this issue boils down to the match-all
This code breaks on main but works on #4778 @ui.page("/")
@ui.page("/{_:path}")
def main():
ui.markdown("""```python
print("hello world")
```""") |
Uh oh!
There was an error while loading. Please reload this page.
First Check
Example Code
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 afterfrom 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
toui.run()
which is defaultTrue
.The text was updated successfully, but these errors were encountered: