# Copyright (c) 2018-2020, NVIDIA CORPORATION.  All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto.  Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION is strictly prohibited.
#
import omni.ui as ui

from .styles import get_style


class MarkdownText:
    def __init__(self, content):
        with ui.VStack(height=0, style=get_style(self)):

            def consume_heading(s):
                heading = 0
                while s.startswith("#"):
                    s = s[1:]
                    heading += 1
                return heading, s.lstrip()

            for line in content.splitlines():
                line = line.lstrip()
                heading, line = consume_heading(line)

                style_name = "text"
                if heading > 0:
                    style_name = f"H{heading}"

                ui.Label(line, name=style_name, height=0, word_wrap=True)
