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

Markdown: Sections missing in the rendering #2781

Closed
nkh opened this issue Jun 14, 2023 · 8 comments · Fixed by #2803
Closed

Markdown: Sections missing in the rendering #2781

nkh opened this issue Jun 14, 2023 · 8 comments · Fixed by #2803
Assignees
Labels
bug Something isn't working Task

Comments

@nkh
Copy link

nkh commented Jun 14, 2023

50% of this file is missing in the rendering https://github.com/nkh/ftl/blob/main/config/ftl/man/ftl.md, all the other renderes I use renders the missing sections, the link above also shows a rendering.

@davep davep transferred this issue from Textualize/frogmouth Jun 14, 2023
@Textualize Textualize deleted a comment from github-actions bot Jun 14, 2023
@davep
Copy link
Contributor

davep commented Jun 14, 2023

Thanks; given that this really comes down to how the Textual Markdown widget sees the file you point to, I've moved the issue to here.

@davep davep added bug Something isn't working Task labels Jun 14, 2023
@davep
Copy link
Contributor

davep commented Jun 14, 2023

It's worth noting that if I drop the document linked above into the markdown-it online demo it appears to render fine. Initially this would suggest a bug in our Markdown handling.

@nkh
Copy link
Author

nkh commented Jun 14, 2023

here's a minimum markdown that doesn't work:

## General *ftl* Commands

        «?»             Show this man page 

@davep
Copy link
Contributor

davep commented Jun 14, 2023

Nice job! Thanks. As minimal examples go it doesn't get better than that! 👍

@TomJGooding
Copy link
Contributor

It looks like Textual parses fenced code blocks, but not code blocks created with indentation which have a different Token type.

Might be worth also taking issue #2676 into consideration for any changes to how the code blocks are parsed?

(Apologies for the broken up code below caused by the triple backticks!)

from markdown_it import MarkdownIt
from textual.app import App, ComposeResult
from textual.containers import Container
from textual.widgets import Footer, Markdown, TextLog

MARKDOWN_V1 = """
## General *ftl* Commands

        «?»             Show this man page
"""

MARKDOWN_V2 = """
## General *ftl* Commands
    «?»             Show this man page
"""


PARSER = MarkdownIt("gfm-like")


class MarkdownExampleApp(App):
    BINDINGS = [("space", "switch_markdown", "Switch Markdown")]
    CSS = """
    #sidebar {
        dock: left;
        width: 40;
    }

    TextLog {
        border: double $accent;
        height: 1fr;
    }
    """

    markdown_vers = MARKDOWN_V1

    def compose(self) -> ComposeResult:
        yield Markdown(self.markdown_vers)
        with Container(id="sidebar"):
            yield TextLog(id="markdown-it")
            yield TextLog(id="textual-md")
        yield Footer()

    def on_mount(self) -> None:
        self.update_logs()

    def action_switch_markdown(self) -> None:
        if self.markdown_vers == MARKDOWN_V1:
            self.markdown_vers = MARKDOWN_V2
        else:
            self.markdown_vers = MARKDOWN_V1

        markdown = self.query_one(Markdown)
        markdown.update(self.markdown_vers)

        self.update_logs()

    def update_logs(self) -> None:
        markdown_it_log = self.query_one("#markdown-it", TextLog)
        markdown_it_log.border_title = "markdown-it tokens"
        markdown_it_log.clear()
        markdown_it_log.write(PARSER.parse(self.markdown_vers))

        textual_md_log = self.query_one("#textual-md", TextLog)
        textual_md_log.border_title = "Textual markdown"
        textual_md_log.clear()
        markdown = self.query_one(Markdown)
        for child in markdown.walk_children():
            textual_md_log.write(child)


if __name__ == "__main__":
    app = MarkdownExampleApp()
    app.run()

@davep
Copy link
Contributor

davep commented Jun 15, 2023

Thanks for diving in and checking this @TomJGooding, very helpful (good recollection of the other issue too). Looking like Markdown does need a bit more love soon (there's a couple or so Frogmouth issues that would benefit from Markdown being extended).

@willmcgugan
Copy link
Collaborator

Going to put this on the ToDo for next week.

@davep davep self-assigned this Jun 19, 2023
@davep davep changed the title Sections missing in the rendering Markdown: Sections missing in the rendering Jun 19, 2023
davep added a commit to davep/textual that referenced this issue Jun 19, 2023
I believe this should be a fine way to solve this. I don't see anything that
means that a `code_block` is in any way different than a fenced block that
has no syntax specified.

See Textualize#2781.
@davep davep linked a pull request Jun 19, 2023 that will close this issue
willmcgugan pushed a commit that referenced this issue Jun 20, 2023
* Initial set of Markdown widget unit tests

Noting too crazy or clever to start with, initially something to just test
the basics and to ensure that the resulting Textual node list is what we'd
expect.

Really just the start of a testing framework for Markdown.

* Allow handling of an unknown token

This allow for a couple of things:

1. First and foremost this will let me test for unhandled tokens in testing.
2. This will also let applications support other token types.

* Update the Markdown testing to get upset about unknown token types

* Treat a code_block markdown token the same as a fence

I believe this should be a fine way to solve this. I don't see anything that
means that a `code_block` is in any way different than a fenced block that
has no syntax specified.

See #2781.

* Add a test for a code_block within Markdown

* Allow for inline fenced code and code blocks

See #2676

Co-authored-by: TomJGooding <101601846+TomJGooding@users.noreply.github.com>

* Update the ChangeLog

* Improve the external Markdown elements are added to the document

* Improve the testing of Markdown

Also add a test for the list inline code block

* Remove the unnecessary pause

* Stop list items in Markdown being added to the focus chain

See #2380

* Remove hint to pyright/pylance/pylint that it's okay to ignore the arg

---------

Co-authored-by: TomJGooding <101601846+TomJGooding@users.noreply.github.com>
@github-actions
Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants