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

Add support for markdown -> XAML parsing #17585

Open
wants to merge 49 commits into
base: main
Choose a base branch
from

Conversation

zadjii-msft
Copy link
Member

@zadjii-msft zadjii-msft commented Jul 18, 2024

This adds support to the Terminal for parsing Markdown to XAML. We're using https://github.com/github/cmark-gfm as our parser, so that we can support the fullness of github-flavored markdown.

The parser parses the markdown to produce a RichTextBlock, which covers just about all the scenarios we need. Since we're initially just targeting using this for "Release notes", I didn't implement everything in markdown1. But headers, bold & italic, unordered lists, images, links, code spans & blocks - all that works. We can work on additional elements as we need them. The parser is encapsulated into Microsoft.Terminal.UI.Markdown.dll, so that we won't load it on startup, only when the pane is actually made the first time.

To test this out, I've added a MarkdownPaneContent pane type on x-markdown (the x- is "experimental"). Go ahead and add that with:

{ "command": { "action": "splitPane", "type": "x-markdown" } }

That's got the ability to load arbitrary MD files and render them. I wouldn't call that experience finished though23(and it probably won't be in 1.22 timeframe). However, it is an excellent testbed for validating what we do and do not support.

We'll use the markdown parser SoonTM for the What's New panes.

Footnotes

  1. the most notable gap being "block quotes" with >. I don't think I can draw a vertical line in a rich text block easily. Footnotes are also missing, as well as tables.

  2. I say it's not finished because the aforementioned MD gaps. Also the UX there is not polished at all.

  3. I don't believe we'll have time to polish out the pure markdown pane for 1.22, but what the parser covers now is more than enough for the release notes pane in time for 1.22

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check-spelling found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

src/cascadia/UIMarkdown/MarkdownToXaml.cpp Fixed Show fixed Hide fixed
src/cascadia/UIMarkdown/MarkdownToXaml.cpp Fixed Show fixed Hide fixed
src/cascadia/UIMarkdown/MarkdownToXaml.cpp Fixed Show fixed Hide fixed
src/cascadia/UIMarkdown/MarkdownToXaml.cpp Fixed Show fixed Hide fixed
src/cascadia/UIMarkdown/MarkdownToXaml.cpp Fixed Show fixed Hide fixed
NOTICE.md Fixed Show fixed Hide fixed
NOTICE.md Fixed Show fixed Hide fixed
NOTICE.md Fixed Show fixed Hide fixed
NOTICE.md Fixed Show fixed Hide fixed
NOTICE.md Fixed Show fixed Hide fixed

This comment has been minimized.

This comment has been minimized.

src/cascadia/TerminalApp/TerminalPage.cpp Outdated Show resolved Hide resolved

namespace winrt::Microsoft::Terminal::UI::Markdown::factory_implementation
{
BASIC_FACTORY(Builder);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't be created, doesn't need a factory.

Consider finding a way to do away with this. There's something fully static classes can do to not need a factory at all.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that I can? Converters in MTUI does the same thing, and it's got a ctor. I couldn't find anything this morning that talked about disabling factory_implementation for a pure static class.

KeyChordSerialization.h also has this ominous comment in it:

// C++/WinRT generates a constructor even though one is not specified in the IDL

src/cascadia/UIMarkdown/CodeBlock.cpp Outdated Show resolved Hide resolved
src/cascadia/UIMarkdown/UIMarkdown.vcxproj Outdated Show resolved Hide resolved
src/cascadia/UIMarkdown/CodeBlock.xaml Outdated Show resolved Hide resolved
break;

case CMARK_NODE_THEMATIC_BREAK:
// A <hr>. Not currently supported.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭inline UI element with a Border?

src/cascadia/UIMarkdown/MarkdownToXaml.cpp Outdated Show resolved Hide resolved
src/cascadia/UIMarkdown/MarkdownToXaml.cpp Outdated Show resolved Hide resolved
src/cascadia/UIMarkdown/MarkdownToXaml.cpp Outdated Show resolved Hide resolved
src/cascadia/UIMarkdown/MarkdownToXaml.cpp Outdated Show resolved Hide resolved
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jul 23, 2024
src/cascadia/UIMarkdown/MarkdownToXaml.cpp Outdated Show resolved Hide resolved
src/cascadia/UIMarkdown/MarkdownToXaml.cpp Outdated Show resolved Hide resolved
src/cascadia/UIMarkdown/MarkdownToXaml.cpp Outdated Show resolved Hide resolved
src/cascadia/UIMarkdown/MarkdownToXaml.cpp Outdated Show resolved Hide resolved
src/cascadia/UIMarkdown/MarkdownToXaml.cpp Outdated Show resolved Hide resolved
@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jul 24, 2024
src/cascadia/UIMarkdown/CodeBlock.xaml Outdated Show resolved Hide resolved
src/cascadia/UIMarkdown/MarkdownToXaml.cpp Outdated Show resolved Hide resolved
@zadjii-msft zadjii-msft assigned DHowett and unassigned DHowett Oct 24, 2024
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.

4 participants