Skip to content

Commit 52c9548

Browse files
Fix required/optional function args syntax
1 parent af9f3e3 commit 52c9548

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

web/resources/function.html

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,29 @@ <h2>Syntax</h2>
2222
{% else %}
2323
{% set return_type = 'void' %}
2424
{% endif %}
25+
2526
{% if function[type_name].parameters %}
26-
<pre><code class="language-lua">{{ return_type }} {{ function[type_name].name }} ( {% for item in function[type_name].parameters %}{{ item.type }} {{ item.name }}{% if not loop.last %}, {% endif %}{% endfor %} )</code></pre>
27-
<ul>
28-
{% for item in function[type_name].parameters %}
29-
<li>{{ item.type }} <strong>{{ item.name }}</strong> : {{ item.description_html }}</li>
30-
{% endfor %}
31-
</ul>
32-
{% else %}
33-
<pre><code class="language-lua">{{ return_type }} {{ function[type_name].name }} ( )</code></pre>
27+
<pre><code class="language-lua">{{ return_type }} {{ function[type_name].name }} ( {% set first_optional = true %}{% for item in function[type_name].parameters %}{% if item.default is defined %}{% if first_optional %}[ {% set first_optional = false %}{% endif %}{{ item.type }} {{ item.name }}{% if item.default is defined %} = {{ item.default }}{% endif %}{% if not loop.last %}, {% endif %}{% if loop.last %} ]{% endif %}{% else %}{{ item.type }} {{ item.name }}{% if not loop.last %}, {% endif %}{% endif %}{% endfor %} )</code></pre>
28+
{% set required_arguments = function[type_name].parameters | selectattr('default', 'equalto', undefined) | list %}
29+
{% set optional_arguments = function[type_name].parameters | selectattr('default', 'ne', undefined) | list %}
30+
31+
{% if required_arguments %}
32+
<h3>Required arguments:</h3>
33+
<ul>
34+
{% for item in required_arguments %}
35+
<li>{{ item.type }} <strong>{{ item.name }}</strong> : {{ item.description_html }}</li>
36+
{% endfor %}
37+
</ul>
38+
{% endif %}
39+
40+
{% if optional_arguments %}
41+
<h3>Optional arguments:</h3>
42+
<ul>
43+
{% for item in optional_arguments %}
44+
<li>{{ item.type }} <strong>{{ item.name }}</strong> (default: <em>{{ item.default }}</em>) : {{ item.description_html }}</li>
45+
{% endfor %}
46+
</ul>
47+
{% endif %}
3448
{% endif %}
3549

3650
{% endif %}

web/scripts/utils.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,4 @@ def to_html(markdown_text, single_paragraph=False):
1818
html = markdown.markdown(markdown_text)
1919
if single_paragraph:
2020
html = re.sub(r'<p>(.*?)</p>', r'\1', html)
21-
22-
# Custom link syntax
23-
# Replace all [[string|text]] with <a href="/string_with_underscores">text</a>
24-
html = re.sub(r'\[\[(.*?)\|(.*?)\]\]', lambda m: f'<a href="/{m.group(1).replace(" ", "_")}">{m.group(2)}</a>', html)
25-
# Replace all [[string]] with <a href="/string_with_underscores">string</a>
26-
html = re.sub(r'\[\[(.*?)\]\]', lambda m: f'<a href="/{m.group(1).replace(" ", "_")}">{m.group(1)}</a>', html)
27-
2821
return html

0 commit comments

Comments
 (0)