Quellcode durchsuchen

Handle template parameter key dependents more intelligently.

tags/v0.1
Ben Kurtovic vor 12 Jahren
Ursprung
Commit
69b236ee8d
2 geänderte Dateien mit 16 neuen und 5 gelöschten Zeilen
  1. +13
    -2
      mwparserfromhell/nodes/template.py
  2. +3
    -3
      mwparserfromhell/parser/builder.py

+ 13
- 2
mwparserfromhell/nodes/template.py Datei anzeigen

@@ -143,10 +143,21 @@ class Template(Node):

if showkey is None:
try:
int(unicode(name))
showkey = False # DEPENDENTS?
int_name = int(unicode(name))
except ValueError:
showkey = True
else:
int_keys = set()
for param in self.params:
try:
int_keys.add(int(unicode(param.name)))
except ValueError:
pass
expected = min(set(range(1, len(int_keys) + 2)) - int_keys)
if expected == int_name:
showkey = False
else:
showkey = True
if not showkey:
self._surface_escape(value, "=")
if not force_nonconformity:


+ 3
- 3
mwparserfromhell/parser/builder.py Datei anzeigen

@@ -20,8 +20,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import re

from . import tokens
from ..nodes import Heading, HTMLEntity, Tag, Template, Text
from ..nodes.extras import Attribute, Parameter
@@ -78,9 +76,11 @@ class Builder(object):
name = self._pop()
default = self._wrap(unicode(min(int_key_range - int_keys)))
param = self._handle_parameter(default)
if re.match(r"[1-9][0-9]*$", param.name.strip()):
try:
int_keys.add(int(unicode(param.name)))
int_key_range.add(len(int_keys) + 1)
except ValueError:
pass
params.append(param)
elif isinstance(token, tokens.TemplateClose):
if not params:


Laden…
Abbrechen
Speichern