Skip to content

Commit e8e9bf6

Browse files
committed
Squashed 'vimhelp/' changes from 2e601f5..ee82db4
ee82db4 Sidebar has level-2 headings if ∄ level-1 headings b947d9b Tweak HTML 76015e2 Upgrade to Flask 2.3 git-subtree-dir: vimhelp git-subtree-split: ee82db4ce6012d9c10529ce469ca892ee831d2e2
1 parent 3909224 commit e8e9bf6

File tree

4 files changed

+36
-11
lines changed

4 files changed

+36
-11
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Flask ~= 2.2
1+
Flask ~= 2.3
22
gevent ~= 22.10
33
geventhttpclient ~= 2.0
44
google-cloud-ndb ~= 2.1

templates/page.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
<script defer src="{{static_dir}}tom-select-2.2.2.base.min.js"></script>
1313
{% endif %}
1414

15-
<link rel="stylesheet" href="{{static_dir}}vimhelp-v5.css" type="text/css">
16-
<noscript><link rel="stylesheet" href="{{static_dir}}noscript.css" type="text/css"></noscript>
15+
<link rel="stylesheet" href="{{static_dir}}vimhelp-v5.css">
16+
<noscript><link rel="stylesheet" href="{{static_dir}}noscript.css"></noscript>
1717
<script defer src="{{static_dir}}vimhelp-v5.js"></script>
1818
</head>
1919
<body>

vimhelp/vimh2h.py

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# Translates Vim documentation to HTML
22

3-
import flask
43
import functools
54
import html
65
import re
76
import urllib.parse
87

8+
import flask
9+
import markupsafe
10+
911

1012
class VimProject:
1113
name = "Vim"
@@ -86,7 +88,10 @@ class NeovimProject:
8688
)
8789
RE_EG_START = re.compile(r"(.* )?>(?:vim|lua)?$")
8890
RE_EG_END = re.compile(r"[^ \t]")
89-
RE_SECTION = re.compile(r"(?!NOTE$|CTRL-|\.\.\.$)([A-Z.][-A-Z0-9 .,()_?]*)(?:\s+\*|$)")
91+
RE_SECTION = re.compile(
92+
r"(?!NOTE$|UTF-8.$|VALID.$|OLE.$|CTRL-|\.\.\.$)"
93+
r"([A-Z.][-A-Z0-9 .,()_?]*?)\s*(?:\s\*|$)"
94+
)
9095
RE_STARTAG = re.compile(r'\*([^ \t"*]+)\*(?:\s|$)')
9196
RE_LOCAL_ADD = re.compile(r"LOCAL ADDITIONS:\s+\*local-additions\*$")
9297

@@ -226,11 +231,13 @@ def to_html(self, filename, contents):
226231

227232
out = []
228233
sidebar_headings = []
234+
sidebar_lvl = 2
229235
in_example = False
230236
for idx, line in enumerate(lines):
231237
prev_line = "" if idx == 0 else lines[idx - 1]
232238
if prev_line == "" and idx > 1:
233239
prev_line = lines[idx - 2]
240+
234241
if in_example:
235242
if RE_EG_END.match(line):
236243
in_example = False
@@ -239,18 +246,31 @@ def to_html(self, filename, contents):
239246
else:
240247
out.extend(('<span class="e">', html_escape(line), "</span>\n"))
241248
continue
249+
242250
if RE_HRULE.match(line):
243251
out.extend(('<span class="h">', html_escape(line), "</span>\n"))
244252
continue
253+
245254
if m := RE_EG_START.match(line):
246255
in_example = True
247256
line = m.group(1) or ""
248-
span_opened = False
257+
258+
heading = None
259+
skip_to_col = None
249260
if m := RE_SECTION.match(line):
250-
out.extend(('<span class="c">', m.group(1), "</span>"))
251-
line = line[m.end(1) :]
261+
heading = m.group(1)
262+
heading_lvl = 2
263+
out.extend(('<span class="c">', heading, "</span>"))
264+
skip_to_col = m.end(1)
252265
elif RE_HRULE1.match(prev_line) and (m := RE_HEADING.match(line)):
253266
heading = m.group(1)
267+
heading_lvl = 1
268+
269+
span_opened = False
270+
if heading is not None and sidebar_lvl >= heading_lvl:
271+
if sidebar_lvl > heading_lvl:
272+
sidebar_lvl = heading_lvl
273+
sidebar_headings = []
254274
if m := RE_STARTAG.search(line):
255275
tag = m.group(1)
256276
else:
@@ -259,8 +279,14 @@ def to_html(self, filename, contents):
259279
span_opened = True
260280
tag_escaped = urllib.parse.quote_plus(tag)
261281
sidebar_headings.append(
262-
flask.Markup(f'<a href="#{tag_escaped}">{html_escape(heading)}</a>')
282+
markupsafe.Markup(
283+
f'<a href="#{tag_escaped}">{html_escape(heading)}</a>'
284+
)
263285
)
286+
287+
if skip_to_col is not None:
288+
line = line[skip_to_col:]
289+
264290
is_faq_line = (
265291
self._project is VimProject and is_help_txt and RE_LOCAL_ADD.match(line)
266292
)
@@ -335,7 +361,7 @@ def to_html(self, filename, contents):
335361
filename=filename,
336362
static_dir=static_dir,
337363
helptxt=helptxt,
338-
content=flask.Markup("".join(out)),
364+
content=markupsafe.Markup("".join(out)),
339365
sidebar_headings=sidebar_headings,
340366
)
341367

vimhelp/vimhelp.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ def handle_vimhelp(filename, cache):
5353

5454
def prepare_response(req, head, theme):
5555
resp = flask.Response(mimetype="text/html")
56-
resp.charset = head.encoding
5756
resp.last_modified = head.modified
5857
resp.cache_control.max_age = 15 * 60
5958
resp.vary.add("Cookie")

0 commit comments

Comments
 (0)