Skip to content
This repository was archived by the owner on Jul 29, 2026. It is now read-only.

Emoji in code block, fix issue #329 - #335

Merged
samtstern merged 4 commits into
google:mainfrom
jollypolly123:main
Feb 10, 2022
Merged

samtstern merged 4 commits into
google:mainfrom
jollypolly123:main

Conversation

@jollypolly123

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread functions/src/content.ts Outdated
const withColons = `:${k}:`;
const asEmoji = emojis[k];
content = content.replace(new RegExp(withColons, "g"), asEmoji);
const contentList = content.split("```");

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.

This is a good start but I think it might be a bit too simple? I'd probably go for something like this:

  • Split the content into a list of lines
  • Loop through lines and keep a isInCodeBlock boolean
  • Whenever we encounter a line containing "```" we flip the boolean
  • For each line when isInCodeBlock is true, do the emoji replacement
  • Join the lines back together

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.

Got it—just wondering, why wouldn't we want to do the first change?

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.

@jollypolly123 based on my reading of the spec I think the triple backticks have to be the start of a line or preceded only by whitespace on the line in order to fence off a code block. So it is possible (although unlikely) that you could have a "```" in the middle of content. Therefore just splitting on that character group is not enough.

Simple:

Hello

Triple backticks at end of line:

Hello```

Indented

Ok

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.

Gotcha thanks!

@samtstern samtstern 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.

Just one more change, thanks!

Comment thread functions/src/content.ts Resolved
Co-authored-by: Sam Stern <samstern@google.com>
@samtstern
samtstern enabled auto-merge (squash) February 10, 2022 09:52
@samtstern
samtstern merged commit d090cb4 into google:main Feb 10, 2022
@samtstern

Copy link
Copy Markdown
Contributor

@jollypolly123 thank you! This should be fixed the next time @techtrailhead deploys the site.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants