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

Allow rendering messages as plaintext #805

Merged
merged 28 commits into from
Sep 14, 2022
Merged

Conversation

ginnyTheCat
Copy link
Collaborator

@ginnyTheCat ginnyTheCat commented Sep 2, 2022

Description

This refactors the way sending messages (with edits and replies) is handled in RoomsInput.js and adds plaintext rendering of messages (plain and markdown). This allows for hiding spoilers in plain messages in the future. For now this moves mention and emoji to be parsing over to simple-markdown.

Fixes #770
Fixes #746

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

Preview: https://805--pr-cinny.netlify.app
⚠️ Exercise caution. Use test accounts. ⚠️

@ginnyTheCat ginnyTheCat force-pushed the markdown-emojis branch 4 times, most recently from ab14056 to 4929c61 Compare September 11, 2022 03:16
@ginnyTheCat ginnyTheCat marked this pull request as ready for review September 11, 2022 03:31
@ginnyTheCat ginnyTheCat force-pushed the markdown-emojis branch 2 times, most recently from da0fd69 to de98770 Compare September 11, 2022 13:29
Copy link
Member

@ajbura ajbura left a comment

Choose a reason for hiding this comment

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

Overall looks great 🚀 .

Btw what docs I can use to review markdown.js in more detail.

src/util/markdown.js Outdated Show resolved Hide resolved
src/client/state/RoomsInput.js Outdated Show resolved Hide resolved
src/util/markdown.js Outdated Show resolved Hide resolved
@ginnyTheCat
Copy link
Collaborator Author

ginnyTheCat commented Sep 12, 2022

I usually look at the way the other markdown rules are implemented here while the readme does a good job at explaining the concept of how simple-markdown works.

Not sure if that's what your question was.

src/util/markdown.js Outdated Show resolved Hide resolved
src/util/markdown.js Outdated Show resolved Hide resolved
Comment on lines +208 to +212
shrug: {
order: defaultRules.escape.order - 0.1,
match: inlineRegex(/^¯\\_\(ツ\)_\/¯/),
parse: (capture) => ({ type: 'text', content: capture[0] }),
},
Copy link
Member

Choose a reason for hiding this comment

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

Wondering why we have a shrug rule?

Copy link
Collaborator Author

@ginnyTheCat ginnyTheCat Sep 13, 2022

Choose a reason for hiding this comment

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

this allows the shrug to no loose his left arm due to it parsing it as markdown (the first \ disappearing as it escapes the _ after it). now smb can just paste in a shrug in or use the /shrug command without having to worry about markdown behaving weirdly.

Comment on lines +123 to +126
fence: {
...defaultRules.fence,
match: blockRegex(/^ *(`{3,}|~{3,}) *(?:(\S+) *)?\n([\s\S]+?)\n?\1 *(?:\n *)*\n/),
},
Copy link
Member

Choose a reason for hiding this comment

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

What is fence?

Copy link
Collaborator Author

@ginnyTheCat ginnyTheCat Sep 13, 2022

Choose a reason for hiding this comment

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

this is a code fence which is a codeblock surrounded by ```. this gets converted into a codeBlock after parsing.

Copy link
Member

@ajbura ajbura left a comment

Choose a reason for hiding this comment

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

Thanks. This works great now 🚀

@ajbura ajbura merged commit 15c1f6d into cinnyapp:dev Sep 14, 2022
@ginnyTheCat ginnyTheCat deleted the markdown-emojis branch September 14, 2022 09:00
NovaAndrom3da pushed a commit to NovaAndrom3da/neocinny that referenced this pull request Nov 23, 2023
* Parse room input from user id and emoji

* Add more plain outputs

* Add reply support

* Always include formatted reply

* Add room mention parser

* Allow single linebreak after codeblock

* Remove margin from math display blocks

* Escape shrug

* Rewrite HTML tag function

* Normalize def keys

* Fix embedding replies into replies

* Don't add margin to file name

* Collapse spaces in HTML message body

* Don't crash with no plaintext rendering

* Add blockquote support

* Remove ref support

* Fix image html rendering

* Remove debug output

* Remove duplicate default option value

* Add table plain rendering support

* Correctly handle paragraph padding when mixed with block content

* Simplify links if possible

* Make blockquote plain rendering better

* Don't error when emojis are matching but not found

* Allow plain only messages with newlines

* Set user id as user mention fallback

* Fix mixed up variable name

* Replace replaceAll with replace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants