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 h1 markdown #468

Merged
merged 10 commits into from
Oct 12, 2022
Merged

Add h1 markdown #468

merged 10 commits into from
Oct 12, 2022

Conversation

cristipaval
Copy link
Contributor

Part of this DesignDoc.
Adds support for heading markdown. A line which starts with # and a space (# ) is wrapped with <h1></h1> tag.

Fixed Issues

https://github.com/Expensify/Expensify/issues/225615

Tests

  1. What unit/integration tests cover your change? What autoQA tests cover your change?
  • there are 2 new automated tests added which checks that markdown is replaced with html tags and vice versa.
  1. What tests did you perform that validates your changes worked?
  • Link the expensify-common local repository by following these steps
  • Run the app
  • Open any chat and send a text message containing lines starting with a # and a space and then text.
  • Check that the lines from the previous step are rendered as headings
  • copy the message to the clipboard and paste it into the composer (input text area)
  • check that the message is parsed correctly and that the headings are pasted as lines starting with # and space

QA

  1. What does QA need to do to validate your changes?
  • Run the app
  • Open any chat and send a text message containing lines starting with a # and a space and then text.
  • Check that the lines from the previous step are rendered as headings
  • copy the message to the clipboard and paste it into the composer (input text area)
  • check that the message is parsed correctly and that the headings are pasted as lines starting with # and space
  1. What areas to they need to test for regressions?
  • Sending messages with all the markdowns should be tested to check that the markdown rules are applied correctly in different markdown combinations
  • Copy-Paste the above messages to check that they are correctly converted back from html to markdown

@cristipaval cristipaval requested a review from a team as a code owner October 10, 2022 22:06
@cristipaval cristipaval self-assigned this Oct 10, 2022
@github-actions
Copy link

github-actions bot commented Oct 10, 2022

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@melvin-bot melvin-bot bot requested review from arosiclair and removed request for a team October 10, 2022 22:07
@cristipaval
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

lib/ExpensiMark.js Outdated Show resolved Hide resolved
@@ -452,3 +452,35 @@ test('map real message with quotes', () => {
const resultString = '\n> hi\n\n\n> hi\n\n';
expect(parser.htmlToMarkdown(testString)).toBe(resultString);
});

test('Test heading1 markdown replacement', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should split these tests up. For example this one is testing

  • normal # Heading case
  • cases with multiple spaces (# Heading)
  • cases with none (#Heading).

You can split this into 3 small and simple tests that'll be easier to read. Also this way there's no need for the long message in the test string that explains everything 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I like your suggestion 👍

Copy link
Contributor

@arosiclair arosiclair left a comment

Choose a reason for hiding this comment

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

Thanks for the changes!

@Gonals
Copy link
Contributor

Gonals commented Mar 6, 2023

Heyhey! Heads up that this PR caused this issue. We basically forgot to handle a case where the # was followed by two spaces and a new line

@@ -223,6 +228,11 @@ export default class ExpensiMark {
regex: /<br(?:"[^"]*"|'[^']*'|[^'"><])*>\n?/gi,
replacement: '\n',
},
{
name: 'heading1',
regex: /\s*<(h1)(?:"[^"]*"|'[^']*'|[^'">])*>(.*?)<\/\1>(?![^<]*(<\/pre>|<\/code>))\s*/gi,
Copy link
Contributor

Choose a reason for hiding this comment

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

👋
This has caused a regression in Expensify/App#17998.
We were removing all of the new line breaks before <h1> tag, (\s), but should remove whitespaces ([^\S\r\n]).
More details here

Comment on lines +165 to +169
{
name: 'heading1',
regex: /^#(?!#) +(.+)$/gm,
replacement: '<h1>$1</h1>',
},
Copy link
Contributor

Choose a reason for hiding this comment

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

This rule was misplaced. It should have been placed before quote rule, because the quote rule consumes the newlines chars i.e. \n. This made such markdown fail > a\n# b. (Coming from Expensify/App#21846)

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.

5 participants