Skip to content
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

feat: make it possible to create a custom Markdown code theme #4343

Merged
merged 3 commits into from
Nov 13, 2024

Conversation

ndonkoHenri
Copy link
Contributor

@ndonkoHenri ndonkoHenri commented Nov 9, 2024

Fixes #4342

Code

import flet as ft

def main(page: ft.Page):
    data = """
## Code blocks

```python
class MyClass(object):
    def __init__(self):
        pass
        
    def greet(self):
        print("Hello World")
    """

    page.add(
        ft.Markdown(
            data,
            extension_set=ft.MarkdownExtensionSet.GITHUB_WEB,
            # code_theme=ft.MarkdownCodeTheme.ATOM_ONE_DARK,
            code_theme=ft.MarkdownCustomCodeTheme(
                keyword=ft.TextStyle(color=ft.colors.RED),
                comment=ft.TextStyle(color=ft.colors.GREY_300),
                class_name=ft.TextStyle(
                    size=17,
                    color=ft.colors.BLUE,
                    weight=ft.FontWeight.BOLD,
                ),
                function=ft.TextStyle(color=ft.colors.YELLOW),
                string=ft.TextStyle(color=ft.colors.GREEN),
                variable=ft.TextStyle(color=ft.colors.PINK),
            ),
        )
    )


ft.app(main)

Summary by Sourcery

Add support for custom Markdown code themes, allowing users to define their own styles for code elements. Update the Markdown control to accept both predefined and custom themes, and enhance the theme parsing logic to handle custom theme definitions.

New Features:

  • Introduce the ability to create a custom Markdown code theme by adding a new class MarkdownCustomCodeTheme that allows users to define custom styles for various code elements.

Enhancements:

  • Enhance the Markdown control to support both predefined and custom code themes by updating the code_theme parameter to accept either MarkdownCodeTheme or MarkdownCustomCodeTheme.
  • Improve the parsing of Markdown code themes by adding a new function parseMarkdownCodeTheme to handle both string and JSON inputs, allowing for more flexible theme definitions.

@FeodorFitsner FeodorFitsner merged commit 5fb877b into main Nov 13, 2024
2 checks passed
@FeodorFitsner FeodorFitsner deleted the ndonkoHenri/markdown-custom-theme branch November 13, 2024 00:19
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.

Create a custom Markdown code theme
2 participants