aboutsummaryrefslogtreecommitdiff
path: root/scripts/gen_vimdoc.py
diff options
context:
space:
mode:
authorGregory Anders <8965202+gpanders@users.noreply.github.com>2023-09-13 08:38:28 -0500
committerGitHub <noreply@github.com>2023-09-13 08:38:28 -0500
commit27a566f3f8e07a4cebb426674800bdf9a7f4f222 (patch)
tree3212fd672bdf21e10766580d61f107d51f69d659 /scripts/gen_vimdoc.py
parent4607807f9fcb83d4e183f6f67e705ffd7f451077 (diff)
downloadrneovim-27a566f3f8e07a4cebb426674800bdf9a7f4f222.tar.gz
rneovim-27a566f3f8e07a4cebb426674800bdf9a7f4f222.tar.bz2
rneovim-27a566f3f8e07a4cebb426674800bdf9a7f4f222.zip
feat(vimdoc): support Markdown code blocks (#25127)
Support Markdown code blocks in addition to <pre> blocks in Doxygen doc comments. Update doc comments in iter.lua as a test.
Diffstat (limited to 'scripts/gen_vimdoc.py')
-rwxr-xr-xscripts/gen_vimdoc.py28
1 files changed, 25 insertions, 3 deletions
diff --git a/scripts/gen_vimdoc.py b/scripts/gen_vimdoc.py
index dfad1f000c..d485e68e2f 100755
--- a/scripts/gen_vimdoc.py
+++ b/scripts/gen_vimdoc.py
@@ -440,7 +440,7 @@ def is_blank(text):
return '' == clean_lines(text)
-def get_text(n, preformatted=False):
+def get_text(n):
"""Recursively concatenates all text in a node tree."""
text = ''
if n.nodeType == n.TEXT_NODE:
@@ -449,11 +449,13 @@ def get_text(n, preformatted=False):
for node in n.childNodes:
text += get_text(node)
return '`{}`'.format(text)
+ if n.nodeName == 'sp': # space, used in "programlisting" nodes
+ return ' '
for node in n.childNodes:
if node.nodeType == node.TEXT_NODE:
text += node.data
elif node.nodeType == node.ELEMENT_NODE:
- text += get_text(node, preformatted)
+ text += get_text(node)
return text
@@ -571,7 +573,7 @@ def render_node(n, text, prefix='', indent='', width=text_width - indentation,
# text += (int(not space_preceding) * ' ')
if n.nodeName == 'preformatted':
- o = get_text(n, preformatted=True)
+ o = get_text(n)
ensure_nl = '' if o[-1] == '\n' else '\n'
if o[0:4] == 'lua\n':
text += '>lua{}{}\n<'.format(ensure_nl, o[3:-1])
@@ -581,7 +583,15 @@ def render_node(n, text, prefix='', indent='', width=text_width - indentation,
text += o[4:-1]
else:
text += '>{}{}\n<'.format(ensure_nl, o)
+ elif n.nodeName == 'programlisting': # codeblock (```)
+ o = get_text(n)
+ filename = n.attributes['filename'].value
+ if filename:
+ text += '>{}'.format(filename.lstrip('.'))
+ else:
+ text += '>'
+ text += '\n\n{}\n<'.format(textwrap.indent(o, ' ' * 4))
elif is_inline(n):
text = doc_wrap(get_text(n), prefix=prefix, indent=indent, width=width)
elif n.nodeName == 'verbatim':
@@ -786,6 +796,18 @@ def fmt_node_as_vimhelp(parent: Element, width=text_width - indentation, indent=
for child in parent.childNodes:
para, _ = para_as_map(child, indent, width, fmt_vimhelp)
+ # 'programlisting' blocks are Markdown code blocks. Do not include
+ # these as a separate paragraph, but append to the last non-empty line
+ # in the text
+ if (
+ len(child.childNodes) == 1
+ and child.childNodes[0].nodeName == 'programlisting'
+ ):
+ while rendered_blocks and rendered_blocks[-1] == '':
+ rendered_blocks.pop()
+ rendered_blocks[-1] += ' ' + para['text']
+ continue
+
# Generate text from the gathered items.
chunks = [para['text']]
if len(para['note']) > 0: