-
Notifications
You must be signed in to change notification settings - Fork 136
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
capture newline as the code fence content #730
capture newline as the code fence content #730
Conversation
@BartoszGrajdek here is the PR for Expensify/App#43750 |
Testing today! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me - please attach some test videos for other platforms, because these changes affect all of them 🙏🏻
Done 👍 |
__tests__/ExpensiMark-HTML-test.js
Outdated
@@ -2220,7 +2220,7 @@ describe('room mentions', () => { | |||
|
|||
test('room mention inside code block should not be rendered', () => { | |||
const testString = '```\n#room\n```'; | |||
const resultString = '<pre>#room<br /></pre>'; | |||
const resultString = '<pre><br />#room<br /></pre>'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is unwanted. HTML BR collapsing works for <br /></pre>
but not for <pre><br />
https://codesandbox.io/s/silly-brattain-dz3rrw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. The App PreRenderer works fine though, but I think we may want to avoid this. Maybe we can put the new line info on the <pre>
tag like:
<pre data-newline="\r\n">
and live markdown can get the new line from data-newline
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would work but it won't work if we have mixed newlines. Technically the live markdown works correctly and the console error is a false positive. Maybe we can ignore the error if the difference between the original text and the reconstructed one is only the new lines? Though ultimately we want the reconstructed message to be the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would work but it won't work if we have mixed newlines
Hmm, you're right.
Maybe we can ignore the error if the difference between the original text and the reconstructed one is only the new lines?
I think we can replace all the new lines to \n only when doing the comparison. This way, we don't alter the user input at all, but we need @BartoszGrajdek thoughts on this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we added the line break just in rawInputReplacement
? The returned value of it is coming only into react-native-live-markdown
input, so it won't affect how we treat code blocks in the chat itself, just the input.
We could just treat the linebreak before code block content as a separate group and use it only in rawInputReplacement
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that works.
@s77rt do you agree with the above suggestion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me but can you please test this against react-native-live-markdown
and verify that we don't get extra newlines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's go with that then 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated!
@@ -129,21 +129,21 @@ export default class ExpensiMark { | |||
name: 'codeFence', | |||
|
|||
// ` is a backtick symbol we are matching on three of them before then after a new line character | |||
regex: /(```(?:\r\n|\n))((?:\s*?(?!(?:\r\n|\n)?```(?!`))[\S])+\s*?(?:\r\n|\n))(```)/g, | |||
regex: /(```(\r\n|\n))((?:\s*?(?!(?:\r\n|\n)?```(?!`))[\S])+\s*?(?:\r\n|\n))(```)/g, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NAB. This has 4 capturing groups but we only need 2. Can you make the other two non-capturing groups?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is 6 groups in total including the negative lookahead and we use 3, but I will leave it as it is.
lib/ExpensiMark.ts
Outdated
const group = textWithinFences.replace(/(?:(?![\n\r])\s)/g, ' '); | ||
return `<pre>${group}</pre>`; | ||
}, | ||
rawInputReplacement: (_extras, _match, _g1, textWithinFences) => { | ||
rawInputReplacement: (_extras, _match, _g1, g2, textWithinFences) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename the group variable that has the newline to something more fitting / explaining what the groups holds e.g. newLineCharacter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, updated!
@BartoszGrajdek @marcochavezf Can you please review/approve if the changes looks good to you |
Hi! Code changes look good to me, I'll just try testing it inside I'm currently working on an issue with higher priority, hence the delay 🙏🏻 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - Works well in react-native-live-markdown
✅
🚀Published to npm in v2.0.35 |
Will prepare the App PR tomorrow! |
Fixed Issues
$ Expensify/App#43750
Tests
What unit/integration tests cover your change? What autoQA tests cover your change?
Updated existing unit test for codefence.
What tests did you perform that validates your changed worked?
To test this in App,
cd parser && npm run build
parser/react-native-live-markdown-parser
to Appnode_modules/@expensify/react-native-live-markdown/lib/parser/react-native-live-markdown-parser.js
.Web
Screen.Recording.2024-06-25.at.13.32.56.mov
Desktop
Screen.Recording.2024-06-25.at.19.59.10.mov
iOS mWeb
Screen.Recording.2024-06-25.at.20.02.21.mov
iOS Native
Screen.Recording.2024-06-25.at.20.06.46.mov
Android mWeb
Screen.Recording.2024-06-25.at.20.08.08.mov
Android Native
Screen.Recording.2024-06-25.at.20.12.54.mov
QA
Same as Tests above