Closed w00tyd00d closed 6 months ago
def clear_indent(self, string: str, indent: str) -> str:
if not string:
return string
if string.startswith(indent):
return string[len(indent):]
raise JMCSyntaxException(
"Invalid indentation when trimming indentation",
self.raw_args["pythonCode"].token,
self.tokenizer, suggestion=string, col_length=False, display_col_length=False)
def call(self) -> str:
if not self.args["pythonCode"]:
return ""
python_lines = self.args["pythonCode"].split("\n")
indent = python_lines[0][:len(
python_lines[0]) - len(python_lines[0].lstrip())]
if not indent:
python_code = self.args["pythonCode"]
else:
python_code = "\n".join(self.clear_indent(line, indent)
for line in python_lines)
Ended up using different implementation
Description
The addition of a built-in python code string formatter for the
JMC.python
module would allow users to have an arbitrary amount of indentation whitespace when coding python in a JMC file. This would prevent always needing to format the python code to align directly with the left-most column.It should be noted that all subsequent indentation should still align with python's indentation protocol, but as long as each line is indented relative to the same uniform length, it should still work just fine.
Example of current implementation:
Example of desired implementation:
I've written up a mock-up example of how this formatting function could be written, although of course use your own discretion.