Skip to content

feat(inner content): allow passing content as a function, as a custom parser#13

Merged
DavidVujic merged 4 commits intomainfrom
allow-custom-rendering-of-content
Sep 7, 2025
Merged

feat(inner content): allow passing content as a function, as a custom parser#13
DavidVujic merged 4 commits intomainfrom
allow-custom-rendering-of-content

Conversation

@DavidVujic
Copy link
Copy Markdown
Owner

@DavidVujic DavidVujic commented Sep 6, 2025

Description

To allow passing in inner html as a string, without escaping the content.

Example: adding © as inner html, it is now possible to pass the content as a function (or a custom render function for that particular content).

from python_hiccup.html import raw

data = ["div", raw("&copy; this should <strong>not</strong> be escaped!")]

the rendered output:

<div>&copy; this should <strong>not</strong> be escaped!</div>

Motivation and Context

Idea and feature request coming from #12

This Pull Request is an alternative to the proposed solution.

How Has This Been Tested?

✅ CI
✅ Added unit test

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

@DavidVujic DavidVujic marked this pull request as ready for review September 6, 2025 22:41
codescene-delta-analysis[bot]

This comment was marked as outdated.

@lukal-x
Copy link
Copy Markdown

lukal-x commented Sep 7, 2025

Much nicer than my approach.

My 2 cents is: hiccup signifies with the function name raw https://weavejester.github.io/hiccup/hiccup2.core.html#var-raw that the string will be injected as-is which is potentially dangerous, reminding the programmer using it to consider the risks.

codescene-delta-analysis[bot]

This comment was marked as outdated.

@DavidVujic
Copy link
Copy Markdown
Owner Author

Much nicer than my approach.

My 2 cents is: hiccup signifies with the function name raw https://weavejester.github.io/hiccup/hiccup2.core.html#var-raw that the string will be injected as-is which is potentially dangerous, reminding the programmer using it to consider the risks.

Good idea! I have added a helper function that can be used for this purpose.

codescene-delta-analysis[bot]

This comment was marked as outdated.

codescene-delta-analysis[bot]

This comment was marked as outdated.

@DavidVujic DavidVujic force-pushed the allow-custom-rendering-of-content branch from 2425729 to 4393acf Compare September 7, 2025 15:56
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Sep 7, 2025

@DavidVujic DavidVujic merged commit 73092cd into main Sep 7, 2025
4 checks passed
@DavidVujic DavidVujic deleted the allow-custom-rendering-of-content branch September 7, 2025 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants