-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Adding textwrap.dedent
for allowing indented html blocks
#275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- write indented html string - but dedent it while generating html - textwrap.dedent is meant for this purpose
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i like it
A NoteThis PR is unrelated to the following: |
good point, they are unrelated |
for more information, see https://pre-commit.ci
@verhulstm I made a small indentation correction. 💡 Looks like you need to write the html block as follows to not let it look weird after linting is done. def create(self):
...
...
new_child._element.innerHTML = dedent(
f"""
<label for="flex items-center p-2 ">
<input class="mr-2" type="checkbox" class="task-check">
<p class="m-0 inline">{self.render_content()}</p>
</label>
"""
)
...
... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Thank you @sugatoray !
) * Adding textwrap.dedent for indented html blocks - write indented html string - but dedent it while generating html - textwrap.dedent is meant for this purpose * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fixed indentation * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fixed indentation Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Currently any html block, which ideally should be indented properly to enhance readability, cannot be written as is. Adding
textwrap.dedent
helps with this and allows one to write indented html blocks as strings and later properly render the html when it is generated.Example
pyscript/pyscriptjs/src/pyscript.py
Lines 254 to 265 in 22ffbcb
The update (via this PR) makes the following work.
https://github.com/sugatoray/pyscript/blob/1f076e76df426a90ed186e5d21dc0d3361c91a43/pyscriptjs/src/pyscript.py#L261-L266