mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
gen_help_html.py [ci skip]
This commit is contained in:
parent
127e13f53e
commit
281c011d44
@ -23,7 +23,11 @@
|
|||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
# SOFTWARE.
|
# SOFTWARE.
|
||||||
|
|
||||||
import re, urllib.parse
|
import os
|
||||||
|
import re
|
||||||
|
import urllib.parse
|
||||||
|
import datetime
|
||||||
|
import sys
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
HEAD = """\
|
HEAD = """\
|
||||||
@ -32,6 +36,17 @@ HEAD = """\
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-type" content="text/html; charset={encoding}"/>
|
<meta http-equiv="Content-type" content="text/html; charset={encoding}"/>
|
||||||
|
<style>
|
||||||
|
.h {{
|
||||||
|
font-weight: bold;
|
||||||
|
}}
|
||||||
|
h1 {{
|
||||||
|
font-family: sans-serif;
|
||||||
|
}}
|
||||||
|
pre {{
|
||||||
|
font-family: sans-serif;
|
||||||
|
}}
|
||||||
|
</style>
|
||||||
<title>Nvim: {filename}</title>
|
<title>Nvim: {filename}</title>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -39,22 +54,19 @@ HEAD_END = '</head>\n<body>\n'
|
|||||||
|
|
||||||
INTRO = """
|
INTRO = """
|
||||||
<h1>Nvim help files</h1>
|
<h1>Nvim help files</h1>
|
||||||
<p>HTML export of the <a href="https://neovim.io/">Nvim</a> help pages{vers-note}.
|
<p>
|
||||||
Updated <a href="https://github.com/neovim/bot-ci" class="d">automatically</a> from the <a
|
<a href="https://neovim.io/">Nvim</a> help pages{vers-note}.
|
||||||
href="https://github.com/vim/vim/tree/master/runtime/doc" class="d">Nvim source repository</a>.
|
Updated <a href="https://github.com/neovim/bot-ci" class="d">automatically</a>
|
||||||
Also includes the <a href="vim_faq.txt.html">Vim FAQ</a>, pulled from its
|
from the <a href="https://github.com/neovim/neovim" class="d">Nvim source</a>.
|
||||||
<a href="https://github.com/chrisbra/vim_faq" class="d">source repository</a>.</p>
|
</p>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
VERSION_NOTE = ", current as of Vim {version}"
|
VERSION_NOTE = ", current as of Nvim {version}"
|
||||||
|
|
||||||
SITENAVI_LINKS = """
|
SITENAVI_LINKS = """
|
||||||
Quick links:
|
<a href="quickref.txt.html">Quick reference</a> ·
|
||||||
<a href="/">help overview</a> ·
|
<a href="usr_toc.txt.html">User manual</a> ·
|
||||||
<a href="quickref.txt.html">quick reference</a> ·
|
<a href="{helptxt}#reference_toc">Reference manual</a> ·
|
||||||
<a href="usr_toc.txt.html">user manual toc</a> ·
|
|
||||||
<a href="{helptxt}#reference_toc">reference manual toc</a> ·
|
|
||||||
<a href="vim_faq.txt.html">faq</a>
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
SITENAVI_LINKS_PLAIN = SITENAVI_LINKS.format(helptxt='help.txt.html')
|
SITENAVI_LINKS_PLAIN = SITENAVI_LINKS.format(helptxt='help.txt.html')
|
||||||
@ -77,15 +89,14 @@ TEXTSTART = """
|
|||||||
FOOTER = '</pre>'
|
FOOTER = '</pre>'
|
||||||
|
|
||||||
FOOTER2 = """
|
FOOTER2 = """
|
||||||
<p id="footer">This site is maintained by Carlo Teubner (<i>(my first name) dot (my last name) at gmail dot com</i>).</p>
|
<p id="footer">Generated {generated_date} from <code>{commit}</code></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
"""
|
""".format(
|
||||||
|
generated_date='{0:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()),
|
||||||
VIM_FAQ_LINE = '<a href="vim_faq.txt.html#vim_faq.txt" class="l">' \
|
commit='?')
|
||||||
'vim_faq.txt</a> Frequently Asked Questions\n'
|
|
||||||
|
|
||||||
RE_TAGLINE = re.compile(r'(\S+)\s+(\S+)')
|
RE_TAGLINE = re.compile(r'(\S+)\s+(\S+)')
|
||||||
|
|
||||||
@ -127,6 +138,8 @@ RE_TAGWORD = re.compile(
|
|||||||
PAT_URL + '|' +
|
PAT_URL + '|' +
|
||||||
PAT_WORD)
|
PAT_WORD)
|
||||||
RE_NEWLINE = re.compile(r'[\r\n]')
|
RE_NEWLINE = re.compile(r'[\r\n]')
|
||||||
|
# H1 header "=====…"
|
||||||
|
# H2 header "-----…"
|
||||||
RE_HRULE = re.compile(r'[-=]{3,}.*[-=]{3,3}$')
|
RE_HRULE = re.compile(r'[-=]{3,}.*[-=]{3,3}$')
|
||||||
RE_EG_START = re.compile(r'(?:.* )?>$')
|
RE_EG_START = re.compile(r'(?:.* )?>$')
|
||||||
RE_EG_END = re.compile(r'\S')
|
RE_EG_END = re.compile(r'\S')
|
||||||
@ -211,13 +224,20 @@ class VimH2H(object):
|
|||||||
inexample = 0
|
inexample = 0
|
||||||
filename = str(filename)
|
filename = str(filename)
|
||||||
is_help_txt = (filename == 'help.txt')
|
is_help_txt = (filename == 'help.txt')
|
||||||
faq_line = False
|
last = ''
|
||||||
for line in RE_NEWLINE.split(contents):
|
for line in RE_NEWLINE.split(contents):
|
||||||
line = line.rstrip('\r\n')
|
line = line.rstrip('\r\n')
|
||||||
line_tabs = line
|
line_tabs = line
|
||||||
line = line.expandtabs()
|
line = line.expandtabs()
|
||||||
|
if last == 'h1':
|
||||||
|
out.extend(('</pre>')) # XXX
|
||||||
|
out.extend(('<h1>', line.rstrip(), '</h1>\n'))
|
||||||
|
out.extend(('<pre>'))
|
||||||
|
last = ''
|
||||||
|
continue
|
||||||
if RE_HRULE.match(line):
|
if RE_HRULE.match(line):
|
||||||
out.extend(('<span class="h">', line, '</span>\n'))
|
# out.extend(('<span class="h">', line, '</span>\n'))
|
||||||
|
last = 'h1'
|
||||||
continue
|
continue
|
||||||
if inexample == 2:
|
if inexample == 2:
|
||||||
if RE_EG_END.match(line):
|
if RE_EG_END.match(line):
|
||||||
@ -234,8 +254,6 @@ class VimH2H(object):
|
|||||||
m = RE_SECTION.match(line)
|
m = RE_SECTION.match(line)
|
||||||
out.extend((r'<span class="c">', m.group(0), r'</span>'))
|
out.extend((r'<span class="c">', m.group(0), r'</span>'))
|
||||||
line = line[m.end():]
|
line = line[m.end():]
|
||||||
if is_help_txt and RE_LOCAL_ADD.match(line_tabs):
|
|
||||||
faq_line = True
|
|
||||||
lastpos = 0
|
lastpos = 0
|
||||||
for match in RE_TAGWORD.finditer(line):
|
for match in RE_TAGWORD.finditer(line):
|
||||||
pos = match.start()
|
pos = match.start()
|
||||||
@ -278,9 +296,6 @@ class VimH2H(object):
|
|||||||
out.append(html_escape[line[lastpos:]])
|
out.append(html_escape[line[lastpos:]])
|
||||||
out.append('\n')
|
out.append('\n')
|
||||||
if inexample == 1: inexample = 2
|
if inexample == 1: inexample = 2
|
||||||
if faq_line:
|
|
||||||
out.append(VIM_FAQ_LINE)
|
|
||||||
faq_line = False
|
|
||||||
|
|
||||||
header = []
|
header = []
|
||||||
header.append(HEAD.format(encoding=encoding, filename=filename))
|
header.append(HEAD.format(encoding=encoding, filename=filename))
|
||||||
@ -310,9 +325,6 @@ html_escape = HtmlEscCache()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
import sys, os, os.path
|
|
||||||
#import cProfile
|
|
||||||
sys.path.append('.')
|
|
||||||
|
|
||||||
def slurp(filename):
|
def slurp(filename):
|
||||||
try:
|
try:
|
||||||
@ -352,4 +364,3 @@ def main():
|
|||||||
of.close()
|
of.close()
|
||||||
|
|
||||||
main()
|
main()
|
||||||
#cProfile.run('main()')
|
|
||||||
|
Loading…
Reference in New Issue
Block a user