flet-dev / flet

Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.
https://flet.dev
Apache License 2.0
10.85k stars 417 forks source link

jump in markdown content #3794

Open BrentHuang opened 1 month ago

BrentHuang commented 1 month ago

Duplicate Check

Describe the requested feature

I extracted the toc of a markdown file and placed it on the side, each directory being a textbutton. When I click the textbutton, I want the central markdown document (flet.Markdown) to jump to the corresponding chapter.

BrentHuang commented 1 month ago

just like this

image

BrentHuang commented 1 month ago

https://github.com/executablebooks/mdit-py-plugins https://github.com/bjoernricks/mdit-py-toc

If flet supports rendering html+css documents, let's say there is such a control as HtmlControl, then I can put the result of markdown-it-py render in this control html_content, put the TOC part of it in another control html_toc:

html_toc

<nav>
  <ul>
    <li>
      <a href="#a-flet_docs-flet-app">A flet_docs Flet app </a>
      <ul>
        <li><a href="#todo">todo </a></li>
      </ul>
    </li>
  </ul>
</nav>

html_content

<h1 id="a-flet_docs-flet-app">A flet_docs Flet app <a class="header-anchor" href="#a-flet_docs-flet-app">¶</a></h1>
<p>xxxxxxxxxxxxxxx</p>
<p>xxxxxxxxxxxxxxxxx</p>
<p>To run the app:</p>
<pre><code class="language-python">flet run --web -d -r --port 8080 [app_directory]
</code></pre>
<h2 id="todo">todo <a class="header-anchor" href="#todo">¶</a></h2>
<ol>
  <li>xxxxxxxxxxxxxxxxx</li>
  <li>xxxxxxxxxxxxxxxxxxxx</li>
</ol>

Click the anchor point in html_toc to trigger a jump inside html_content.

BrentHuang commented 1 month ago

OR ft.Markdown has a method scroll_to_head, like this:

self.__ref_markdown.current.scroll_to_head('## head2-6')
baseplate-admin commented 1 month ago

If flet supports rendering html+css documents

Flet currently doesn't support it.

There's an issue for it:

BrentHuang commented 3 weeks ago

image It would be perfect if we could click on a TOC item and the content of the markdown document would scroll to the corresponding title!

BrentHuang commented 3 weeks ago

also need search in markdown

image

and markdown editor.