|
@@ -1,6 +1,6 @@ |
|
|
# -*- coding: utf-8 -*- |
|
|
# -*- coding: utf-8 -*- |
|
|
# |
|
|
# |
|
|
# Copyright (C) 2012-2016 Ben Kurtovic <ben.kurtovic@gmail.com> |
|
|
|
|
|
|
|
|
# Copyright (C) 2012-2017 Ben Kurtovic <ben.kurtovic@gmail.com> |
|
|
# |
|
|
# |
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy |
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy |
|
|
# of this software and associated documentation files (the "Software"), to deal |
|
|
# of this software and associated documentation files (the "Software"), to deal |
|
@@ -70,7 +70,8 @@ class Template(Node): |
|
|
get(param.value) |
|
|
get(param.value) |
|
|
write("}}") |
|
|
write("}}") |
|
|
|
|
|
|
|
|
def _surface_escape(self, code, char): |
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
|
|
def _surface_escape(code, char): |
|
|
"""Return *code* with *char* escaped as an HTML entity. |
|
|
"""Return *code* with *char* escaped as an HTML entity. |
|
|
|
|
|
|
|
|
The main use of this is to escape pipes (``|``) or equal signs (``=``) |
|
|
The main use of this is to escape pipes (``|``) or equal signs (``=``) |
|
@@ -82,7 +83,8 @@ class Template(Node): |
|
|
if char in node: |
|
|
if char in node: |
|
|
code.replace(node, node.replace(char, replacement), False) |
|
|
code.replace(node, node.replace(char, replacement), False) |
|
|
|
|
|
|
|
|
def _select_theory(self, theories): |
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
|
|
def _select_theory(theories): |
|
|
"""Return the most likely spacing convention given different options. |
|
|
"""Return the most likely spacing convention given different options. |
|
|
|
|
|
|
|
|
Given a dictionary of convention options as keys and their occurrence |
|
|
Given a dictionary of convention options as keys and their occurrence |
|
@@ -96,6 +98,22 @@ class Template(Node): |
|
|
if confidence >= 0.75: |
|
|
if confidence >= 0.75: |
|
|
return tuple(theories.keys())[values.index(best)] |
|
|
return tuple(theories.keys())[values.index(best)] |
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
|
|
def _blank_param_value(value): |
|
|
|
|
|
"""Remove the content from *value* while keeping its whitespace. |
|
|
|
|
|
|
|
|
|
|
|
Replace *value*\ 's nodes with two text nodes, the first containing |
|
|
|
|
|
whitespace from before its content and the second containing whitespace |
|
|
|
|
|
from after its content. |
|
|
|
|
|
""" |
|
|
|
|
|
sval = str(value) |
|
|
|
|
|
if sval.isspace(): |
|
|
|
|
|
before, after = "", sval |
|
|
|
|
|
else: |
|
|
|
|
|
match = re.search(r"^(\s*).*?(\s*)$", sval, FLAGS) |
|
|
|
|
|
before, after = match.group(1), match.group(2) |
|
|
|
|
|
value.nodes = [Text(before), Text(after)] |
|
|
|
|
|
|
|
|
def _get_spacing_conventions(self, use_names): |
|
|
def _get_spacing_conventions(self, use_names): |
|
|
"""Try to determine the whitespace conventions for parameters. |
|
|
"""Try to determine the whitespace conventions for parameters. |
|
|
|
|
|
|
|
@@ -119,16 +137,6 @@ class Template(Node): |
|
|
after = self._select_theory(after_theories) |
|
|
after = self._select_theory(after_theories) |
|
|
return before, after |
|
|
return before, after |
|
|
|
|
|
|
|
|
def _blank_param_value(self, value): |
|
|
|
|
|
"""Remove the content from *value* while keeping its whitespace. |
|
|
|
|
|
|
|
|
|
|
|
Replace *value*\ 's nodes with two text nodes, the first containing |
|
|
|
|
|
whitespace from before its content and the second containing whitespace |
|
|
|
|
|
from after its content. |
|
|
|
|
|
""" |
|
|
|
|
|
match = re.search(r"^(\s*).*?(\s*)$", str(value), FLAGS) |
|
|
|
|
|
value.nodes = [Text(match.group(1)), Text(match.group(2))] |
|
|
|
|
|
|
|
|
|
|
|
def _fix_dependendent_params(self, i): |
|
|
def _fix_dependendent_params(self, i): |
|
|
"""Unhide keys if necessary after removing the param at index *i*.""" |
|
|
"""Unhide keys if necessary after removing the param at index *i*.""" |
|
|
if not self.params[i].showkey: |
|
|
if not self.params[i].showkey: |
|
|