Skip to content

Commit 2c016e9

Browse files
committed
Fix codeview behavior
1 parent cedc63c commit 2c016e9

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

poetry.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pypi_browser/app.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,16 +290,19 @@ async def transfer_file():
290290

291291
if is_text:
292292
if entry.size <= TEXT_RENDER_FILESIZE_LIMIT:
293+
text = first_chunk.decode('utf8', errors='replace')
294+
293295
# Case 1: render syntax-highlighted.
294296
style_config = fluffy_code.prebuilt_styles.default_style()
295297

296298
try:
297299
lexer = pygments.lexers.guess_lexer_for_filename(
298300
archive_path,
299-
first_chunk,
301+
text,
302+
stripnl=False,
300303
)
301304
except pygments.lexers.ClassNotFound:
302-
lexer = pygments.lexers.special.TextLexer()
305+
lexer = pygments.lexers.special.TextLexer(stripnl=False)
303306

304307
return templates.TemplateResponse(
305308
'package_file_archive_path.html',
@@ -309,7 +312,7 @@ async def transfer_file():
309312
'filename': file_name,
310313
'archive_path': archive_path,
311314
'rendered_text': fluffy_code.code.render(
312-
first_chunk,
315+
text,
313316
style_config=style_config,
314317
highlight_config=fluffy_code.code.HighlightConfig(
315318
lexer=lexer,

pypi_browser/static/site.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
html {
2+
/* Disable smooth scrolling set by Bootstrap */
3+
scroll-behavior: auto !important;
4+
}
5+
16
.breadcrumb {
27
--bs-breadcrumb-divider: '>';
38
}
@@ -8,4 +13,9 @@
813

914
.page-package-file-archive-path .codeview {
1015
border: solid 1px #ddd;
16+
font-size: 14px !important;
17+
}
18+
19+
.page-package-file-archive-path .codeview pre {
20+
font-size: 14px;
1121
}

pypi_browser/templates/package_file_archive_path.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ <h1 class="font-monospace">{{archive_path}}</h1>
4040
</ol>
4141
</nav>
4242

43-
<div class="row">
44-
<div class="col">
43+
<div class="row mb-6">
44+
<div class="col col-sm-9">
4545
{% if cannot_render_error %}
4646
<div class="card">
4747
<div class="card-body text-center">

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ packages = [{include = "pypi_browser"}]
1010
[tool.poetry.dependencies]
1111
python = "^3.9"
1212
starlette = "*"
13-
fluffy-code = "^0.0.1"
13+
fluffy-code = "^0.0.2"
1414
Jinja2 = "^3.1.2"
1515
httpx = "^0.23.0"
1616
aiofiles = "^22.1.0"

0 commit comments

Comments
 (0)