Skip to content

Add h1 markdown - #468

Merged
arosiclair merged 10 commits into
mainfrom
cristi_add-h1-markdown
Oct 12, 2022
Merged

arosiclair merged 10 commits into
mainfrom
cristi_add-h1-markdown

Conversation

@cristipaval

Copy link
Copy Markdown
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

github-actions Bot commented Oct 10, 2022 •

Copy link
Copy Markdown

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
Copy Markdown
Contributor Author

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

Comment thread lib/ExpensiMark.js Resolved
expect(parser.htmlToMarkdown(testString)).toBe(resultString);
});

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

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.

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
Copy Markdown
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 👍

@arosiclair arosiclair 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 the changes!

@Gonals

Gonals commented Mar 6, 2023

Copy link
Copy Markdown
Contributor

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

Comment thread lib/ExpensiMark.js
},
{
name: 'heading1',
regex: /\s*<(h1)(?:"[^"]*"|'[^']*'|[^'">])*>(.*?)<\/\1>(?![^<]*(<\/pre>|<\/code>))\s*/gi,

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 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 thread lib/ExpensiMark.js
Comment on lines +165 to +169
{
name: 'heading1',
regex: /^#(?!#) +(.+)$/gm,
replacement: '<h1>$1</h1>',
},

Copy link
Copy Markdown
Member

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