Skip to content

Add integrated emoji parsing into markdown rendering - #2423

Closed
samcoe wants to merge 3 commits into
trunkfrom
fix-glamour
Closed

samcoe wants to merge 3 commits into
trunkfrom
fix-glamour

Conversation

@samcoe

@samcoe samcoe commented Nov 17, 2020

Copy link
Copy Markdown
Contributor

This PR does a couple things:

  1. Internalize glamour package (necessary for number 2)
  2. Adds integrated emoji parsing into markdown rendering
  3. Adds RenderWith functions to handle rendering customization

closes #2352

@samcoe samcoe self-assigned this Nov 17, 2020
@samcoe samcoe mentioned this pull request Nov 17, 2020
@@ -0,0 +1,137 @@
package glamour

@samcoe samcoe Nov 17, 2020 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It looks like these tests are failing on Windows only, and in the glamour repo they are explicitly not running the tests on Windows. Does anyone have an ideas on why these tests are only failing on Windows? My naive guess is that it has to do with carriage returns.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Haven't looked at test failures, but unless we are going to maintain this internal fork of glamour and its tests (and I suggest that we don't), let's instead delete all the tests and trust the github.com/yuin/goldmark/renderer package instead.

@mislav mislav left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for taking this on! It looks like the goldmark-emoji plugin parses emoji correctly, but does the glamour terminal renderer actually render those emoji visibly? That is not my experience if I build this branch and run:

gh repo view muan/emoji

I can see that numerous emoji such as :heart: in the repo's README are simply swallowed— nothing is being rendered.

@@ -0,0 +1,245 @@
package glamour

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of copying over the whole glamour.go intact, since we don't need most of these APIs (and since they were not enough for us to inject emoji handling), we could try trimming down this file to a bare minimum that allows us to render GitHub-flavored markdown. I imagine that most of what this file would be doing is interfacing with github.com/yuin/goldmark/renderer.

@@ -0,0 +1,137 @@
package glamour

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Haven't looked at test failures, but unless we are going to maintain this internal fork of glamour and its tests (and I suggest that we don't), let's instead delete all the tests and trust the github.com/yuin/goldmark/renderer package instead.

Comment thread pkg/markdown/markdown.go
"github.com/cli/cli/internal/glamour"
)

func Render(text, style string, baseURL string) (string, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For the sake of minimal diff, I would suggest that this method stays the same as before.

I don't see value in splitting it into several RenderWith* methods, especially since that required changing all the current call sites, but there was no gain in functionality. We pass down all the same arguments (style and base URL) like before, and we hardcode the wrap margin to 80 like before.

In the future we can expose setting wrap margin to something else other than 80 (ideally the width of the user's terminal), but let's do that in a separate PR rather than in the one that is about emoji.

@samcoe

samcoe commented Nov 22, 2020

Copy link
Copy Markdown
Contributor Author

Going to close this PR as I have opened a PR to add emoji support directly to glamour charmbracelet/glamour#92

@samcoe samcoe closed this Nov 22, 2020
@samcoe
samcoe deleted the fix-glamour branch November 22, 2020 08:08
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.

Emoji parser does not discriminate

2 participants