Skip to content

Implement code and pre blocks support on web #456

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

Open
wants to merge 110 commits into
base: main
Choose a base branch
from

Conversation

BartoszGrajdek
Copy link
Collaborator

@BartoszGrajdek BartoszGrajdek commented Aug 21, 2024

Details

Related Issues

GH_LINK

Manual Tests

Change codeFance rule in /node_modules/expensify-common/dist/ExpensiMark.js to code below

             {
                name: 'codeFence',
                // ` is a backtick symbol we are matching on three of them before then after a new line character
                regex: /(?<![^^\r\n])(&#x60;&#x60;&#x60;(\r\n|\n))((?:\s*?(?!(?:\r\n|\n)?&#x60;&#x60;&#x60;(?!&#x60;))[\S])+\s*?(?:\r\n|\n))(&#x60;&#x60;&#x60;)/g,
                // We're using a function here to perform an additional replace on the content
                // inside the backticks because Android is not able to use <pre> tags and does
                // not respect whitespace characters at all like HTML does. We do not want to mess
                // with the new lines here since they need to be converted into <br>. And we don't
                // want to do this anywhere else since that would break HTML.
                // &nbsp; will create styling issues so use &#32;
                replacement: (_extras, _match, _g1, _g2, textWithinFences) => {
                    const group = textWithinFences.replace(/(?:(?![\n\r])\s)/g, '&#32;');
                    return `<pre>${group}</pre>`;
                },
                rawInputReplacement: (_extras, _match, _g1, newLineCharacter, textWithinFences) => {
                    const group = textWithinFences.replace(/(?:(?![\n\r])\s)/g, '&#32;').replace(/<emoji>|<\/emoji>/g, '');
                    return `<pre>${newLineCharacter}${group}</pre>`;
                },
            },

Linked PRs

@BartoszGrajdek
Copy link
Collaborator Author

Fixed! @Skalakid

@Skalakid
Copy link
Collaborator

Found couple of new bugs:

bug.1.mov
bug.2.mov

@Skalakid
Copy link
Collaborator

Found two smaller issues:

  1. When typing in the codeblock and pressing enter, the view is scrolled to the top of the component instead of scrolling to the text cursor
Screen.Recording.2024-12-12.at.12.40.34.mov
  1. The codeblock isn't responsive. When the text input width changes the layout breaks
Screen.Recording.2024-12-12.at.12.45.15.mov

@BartoszGrajdek BartoszGrajdek force-pushed the @BartoszGrajdek/web-parser-refactor-code-blocks branch from 3b823bc to 4aa355b Compare February 23, 2025 18:38
Comment on lines 169 to 170
'min-width': `min(calc(100% + 2.5px), ${preBlockWidth + horizontalPadding * 2 + 1}px)`,
'max-width': `min(${preBlockWidth + horizontalPadding * 2 + 2}px, ${contentWidth}px)`,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We could potentially remove these lines, set before's content: "" and width: 100%.

I've tried making it work and it seems promising it's just that you'd need to force a linebreak whenever user tries to write something directly after closing backticks and that's something I didn't manage to implement cleanily @Skalakid

@Skalakid Skalakid force-pushed the @BartoszGrajdek/web-parser-refactor-code-blocks branch from 6047954 to 1f2e93f Compare April 9, 2025 14:24
Copy link
Collaborator

@Skalakid Skalakid left a comment

Choose a reason for hiding this comment

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

Left some small comments


const lineHeight = line.getBoundingClientRect()?.height;
const preStyles = markdownStyle.pre;
const padding = preStyles?.padding ?? 2;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why 2? Shouldn't we use the default style value from makeDefaultMarkdownStyle here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Pretty sure this is to account for border adding 1px on each side, but you can try to change this to see 👀

@Skalakid Skalakid requested a review from tomekzaw April 15, 2025 08:57
@Skalakid
Copy link
Collaborator

@tomekzaw bump :D

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.

2 participants