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 157 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 110 commits
Commits
Show all changes
157 commits
Select commit Hold shift + click to select a range
f853061
Add refactor changes
Skalakid Jun 25, 2024
c4108c1
Fix parserUtils
Skalakid Jun 25, 2024
38693c4
Add tree building when creating markdown HTML structure
Skalakid Jun 26, 2024
6a1eaf1
Refactor function and type names
Skalakid Jun 26, 2024
75d6afd
Fix TS errors
Skalakid Jun 26, 2024
db68b78
Update parser structure
Skalakid Jun 26, 2024
31711ab
Move BrowserUtils into an object
Skalakid Jun 26, 2024
cab8ca7
Move utils to separate folder
Skalakid Jun 26, 2024
2f829cc
Add block utils
Skalakid Jun 26, 2024
b9b2984
Move functions from above the web component to utils
Skalakid Jun 26, 2024
3fbc456
Fix unit tests
Skalakid Jun 27, 2024
d74e0e4
Fix cursor positioning bugs
Skalakid Jun 28, 2024
220395b
Remove scrollCursorIntoView function
Skalakid Jun 28, 2024
4d95382
Rename variable names
Skalakid Jun 28, 2024
907c73b
Replace textContent with ref value
Skalakid Jun 28, 2024
1017ebc
Merge branch 'main' into @Skalakid/web-parser-refactor
Skalakid Jun 28, 2024
1f1fefd
Merge branch 'main' into @Skalakid/web-parser-refactor
Skalakid Jul 1, 2024
ff41dd7
Fix crashes and cursor positioning in E/App
Skalakid Jul 1, 2024
d1d8a49
Fix copying and pasting text with markdown
Skalakid Jul 1, 2024
153ead8
Fix pasting text starting with newlines
Skalakid Jul 1, 2024
ea6aad8
Fix errors when replacing text
Skalakid Jul 2, 2024
87953bb
Fix HTML injestions and pasted text parsing
Skalakid Jul 2, 2024
3d30621
Fix paste text trimming condiftion
Skalakid Jul 2, 2024
471f53a
Fix cutting text
Skalakid Jul 2, 2024
92a224c
Change handlePaste logic to fix newlines in pasted text
Skalakid Jul 2, 2024
c14add4
Fix cursor positioning when undoing/redoing previously pasted text
Skalakid Jul 2, 2024
e9d8ec3
Fix text coloring
Skalakid Jul 2, 2024
e24d259
Add review changes
Skalakid Jul 3, 2024
092775d
Move updateTextColor function
Skalakid Jul 3, 2024
a0c1dfa
Fix cursor positioning when changing text and styles at the same time
Skalakid Jul 3, 2024
d04ad32
Fix newlines on FireFox
Skalakid Jul 3, 2024
63de148
Fix cursor position value update when entering newline inside codeblock
Skalakid Jul 3, 2024
f06d10f
Fix removing characters when cursor is at the beginning of the line o…
Skalakid Jul 3, 2024
34eabe2
Fix writing in empty line on Firefox
Skalakid Jul 3, 2024
a52e3f5
Fix cursor position value on Cmd+A on FireFox
Skalakid Jul 3, 2024
b5515cf
Fix getting value in e2e tests
Skalakid Jul 4, 2024
5a043a3
Fix input e2e tests
Skalakid Jul 4, 2024
5a1dae2
Fix style e2e tests
Skalakid Jul 4, 2024
60f4f4b
Fix text manipulation e2e tests
Skalakid Jul 4, 2024
55e78b4
Update checkCursorPosition function in e2e tests
Skalakid Jul 4, 2024
8a0a7be
Update checkCursorPosition function in e2e tests
Skalakid Jul 4, 2024
96a9b5c
Fix cursor position after redoing pasted text
Skalakid Jul 5, 2024
8c85473
Merge branch '@Skalakid/web-parser-refactor' of github.com:Expensify/…
Skalakid Jul 5, 2024
401febe
Merge branch 'main' into @Skalakid/web-parser-refactor
Skalakid Jul 5, 2024
862e74a
Fix e2e tests on CI/CD
Skalakid Jul 5, 2024
0580f45
Uncomment undo test
Skalakid Jul 5, 2024
6682c9d
Fix TS errors
Skalakid Jul 5, 2024
8165fb9
Change line merging funciton
Skalakid Jul 5, 2024
9e2b943
Fix selection event sending on paste
Skalakid Jul 5, 2024
0f5b86a
Merge branch 'main' into @Skalakid/web-parser-refactor
Skalakid Jul 8, 2024
5f369ec
Fix scrolling cursor into view on Safari browser
Skalakid Jul 8, 2024
7cdaf9a
Merge branch 'main' into @Skalakid/web-parser-refactor
Skalakid Jul 9, 2024
6bada78
Enhance cursor positioning on input
Skalakid Jul 9, 2024
d9c097d
Merge branch 'main' into @Skalakid/web-parser-refactor
Skalakid Jul 10, 2024
309bccf
Fix diacritics after CMD+A
Skalakid Jul 10, 2024
90d2ea3
Fix autocorrect cursor positioning
Skalakid Jul 10, 2024
111fd6b
Fix deleting codeBlock lines with CMD+backspace
Skalakid Jul 10, 2024
d14f4ba
Fix text color on undo/redo
Skalakid Jul 10, 2024
82d58ca
Fix removing last letter from the line
Skalakid Jul 10, 2024
2b9e56a
Fix cursor position when replacing text with the same text
Skalakid Jul 11, 2024
5861a21
Change parseInnerHTMLToText function
Skalakid Jul 15, 2024
68ae9be
Fix input behavior when interracting with display: block element
Skalakid Jul 15, 2024
0bc882a
Fix getTreeNodeByIndex function
Skalakid Jul 16, 2024
cc8e307
Fix replacing whole content of the input
Skalakid Jul 16, 2024
3da3989
Fix set cursor position when content changes
Skalakid Jul 16, 2024
ccb251e
Fix removing selection on paste
Skalakid Jul 16, 2024
e759170
Fix set cursor position on paste
Skalakid Jul 16, 2024
4db4441
Fix dissapearing cursor bug
Skalakid Jul 16, 2024
0480cb8
Fix pasting text into empty input
Skalakid Jul 16, 2024
5faac50
Fix newline deletion
Skalakid Jul 17, 2024
14d0eed
Improve parseInnerHTMLToText function and fix pasted text correct val…
Skalakid Jul 18, 2024
0c204f5
Remove buildTree function
Skalakid Jul 18, 2024
de12aca
Fix tests
Skalakid Jul 18, 2024
8648205
Replacing text by text cursor position
Skalakid Jul 19, 2024
eb1502a
Fix cursor positioning on custom text pasting (E/App)
Skalakid Jul 19, 2024
3486303
Add function comments
Skalakid Jul 19, 2024
fd2be10
feat: code block background with proper handling
BartoszGrajdek Jul 25, 2024
df04ba0
feat: adjust styles for background width
BartoszGrajdek Jul 25, 2024
3958bc3
feat: support for custom styles
BartoszGrajdek Jul 29, 2024
c57b91f
fix: refactor stylesheet handling
BartoszGrajdek Aug 21, 2024
07ce864
chore: resolve merge conflicts
BartoszGrajdek Sep 12, 2024
9485690
feat: improve styling
BartoszGrajdek Sep 19, 2024
b5a09d6
chore: resolve merge conflicts
BartoszGrajdek Sep 19, 2024
5bea3f1
fix: paddings & autocorrect
BartoszGrajdek Oct 1, 2024
5eb25b3
chore: resolve merge conflicts
BartoszGrajdek Oct 1, 2024
457ea25
feat: add support for vertical & horizontal padding
BartoszGrajdek Oct 1, 2024
561e0ec
fix: jumping background
BartoszGrajdek Oct 14, 2024
6f1c32f
chore: merge main
BartoszGrajdek Oct 14, 2024
e54929e
fix: background issues
BartoszGrajdek Oct 17, 2024
6379bb5
fix: cursor positioning
BartoszGrajdek Oct 28, 2024
a7fc650
fix: background sizing
BartoszGrajdek Oct 30, 2024
3fa6fba
chore: resolve merge conflicts
BartoszGrajdek Nov 29, 2024
bb46ce0
fix: insufficient line-height in large code blocks
BartoszGrajdek Dec 9, 2024
cddf8a0
chore: resolve merge conflicts
BartoszGrajdek Dec 9, 2024
7bc4ef0
fix: inline code parser problems
BartoszGrajdek Dec 11, 2024
4aa355b
fix: performance & line-height
BartoszGrajdek Feb 23, 2025
830b866
chore: resolve merge conflicts
BartoszGrajdek Feb 23, 2025
1097a16
fix: resizing & styles not loading
BartoszGrajdek Feb 28, 2025
32f1a1d
refactor: cleanup
BartoszGrajdek Mar 3, 2025
351c32a
fix: code markdown fontSize in h1 tag
Skalakid Mar 11, 2025
b035335
chore: resolve merge conflicts
Skalakid Mar 11, 2025
c858c96
chore: merge main
Skalakid Apr 9, 2025
1f2e93f
fix: tests
Skalakid Apr 9, 2025
e8b5e80
Mock RNweb funtions
Skalakid Apr 11, 2025
89018dc
Remove unneccesary type export
Skalakid Apr 11, 2025
ee0609b
Merge branch 'main' into @BartoszGrajdek/web-parser-refactor-code-blocks
Skalakid Apr 15, 2025
2d3fcf9
Add review changes
Skalakid Apr 15, 2025
ee67a71
Fix InputHistory after merge
Skalakid Apr 15, 2025
e2c2993
Move getPropertyValue
Skalakid Apr 15, 2025
46818b0
Merge branch 'main' into @BartoszGrajdek/web-parser-refactor-code-blocks
Skalakid Apr 28, 2025
c0ff1ba
Merge branch 'main' into @BartoszGrajdek/web-parser-refactor-code-blocks
Skalakid May 13, 2025
0a95808
Fix removing last new line in code block on Firefox
Skalakid May 14, 2025
a8b249b
Fix codeblock height when enetring different markdown in the same line
Skalakid May 15, 2025
3b5161d
Make input parser fix only for Firefox
Skalakid May 15, 2025
6775991
Fix flickering spellcheck
Skalakid May 16, 2025
4c22b9d
Rename function
Skalakid May 16, 2025
3b02ffe
Fix JS errors when value prop isn't passed
Skalakid May 19, 2025
edab956
Remove stylesheet when component is unmounted
Skalakid May 19, 2025
884722a
Unify inline-code and pre styles2
Skalakid May 19, 2025
6212c9c
Make border styles optional
Skalakid May 19, 2025
0aff26d
Enhance style tests for codeblock
Skalakid May 20, 2025
d091bc9
Change codeblock HTML structure
Skalakid May 23, 2025
7072394
Fix tests
Skalakid May 23, 2025
3fbe395
Fix issue with multiple codeblocks in one input
Skalakid May 23, 2025
5297311
Fix scrolling to the proper line inside codeblock when focusing an input
Skalakid May 26, 2025
c771ca7
Fix placing cursor at the end of first codeblock syntax
Skalakid May 27, 2025
0924fb3
Fix selectable area inside codeblock on FireFox
Skalakid May 27, 2025
26c82b3
Fix writing outside of codeblock borders
Skalakid May 27, 2025
a15826a
Add codeblock e2e tests
Skalakid May 27, 2025
ddbceed
Add codeblock content wrapping test
Skalakid May 27, 2025
f84890c
Add codeblock input resizing test
Skalakid May 27, 2025
d2d8c54
Fix codeblock dimensions test
Skalakid May 27, 2025
6f8d873
Add test for scrolling codeblock into view
Skalakid May 27, 2025
e4efbdf
Fix scrolling to BR inside the codeblock
Skalakid May 27, 2025
39740ad
Add delay after resizing the input
Skalakid May 27, 2025
51d1d59
Fix display in global css file
Skalakid May 27, 2025
cab5ca6
Fix placing and focusing to the cursor at the end of the codeblock op…
Skalakid May 28, 2025
5a5a2e9
Move isChildOfMarkdownElementTypes function to inputUtils
Skalakid May 28, 2025
7512207
Fix newline generation after clearing the input
Skalakid May 30, 2025
c3af8d3
Fix breaking codeblock when removing first newline
Skalakid Jun 2, 2025
ac0bee5
Fix breaking codeblock when removing last newline
Skalakid Jun 2, 2025
0d1b6d5
Move codeblock element styles to css file
Skalakid Jun 2, 2025
5b6bab9
Fix breaking codeblock structure when deleting text before the closin…
Skalakid Jun 3, 2025
44b59a7
Fix breaking codeblock when removing first newline
Skalakid Jun 3, 2025
c59982b
Update test names
Skalakid Jun 3, 2025
35785eb
Add newline removal tests
Skalakid Jun 3, 2025
e343025
Fix codeblock tests structure
Skalakid Jun 4, 2025
53050a4
Add content modification tests
Skalakid Jun 4, 2025
8cdb8c3
Update code comments
Skalakid Jun 4, 2025
db4ab11
Fix removing newline at the end of codeblock on all platforms
Skalakid Jun 4, 2025
5d2c50d
Fix problems with multiple codeblock merging together
Skalakid Jun 4, 2025
34dbda2
Add codeblock styling checks
Skalakid Jun 4, 2025
382ba4b
Add testCodeblock function to playwright tests
Skalakid Jun 4, 2025
733115c
Merge branch 'main' into @BartoszGrajdek/web-parser-refactor-code-blocks
Skalakid Jun 4, 2025
1ff2515
Add codeblock markdown count check
Skalakid Jun 5, 2025
3aba838
Add newlines
Skalakid Jun 5, 2025
67b97b5
Clean up code
Skalakid Jun 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions WebExample/__tests__/styles.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,20 @@ test.describe('markdown content styling', () => {
});

test('inline code', async ({page}) => {
await testMarkdownContentStyle({testContent: 'inline code', style: 'font-family: monospace; font-size: 20px; color: black; background-color: lightgray;', page});
await testMarkdownContentStyle({
testContent: 'inline code',
style:
'font-family: monospace; font-size: 20px; color: black; background-color: lightgray; border-color: gray; border-width: 1px; border-radius: 4px; border-style: solid; padding: 0px; line-height: 1.5;',
page,
});
});

test('codeblock', async ({page}) => {
await testMarkdownContentStyle({testContent: 'codeblock', style: 'font-family: monospace; font-size: 20px; color: black; background-color: lightgray;', page});
await testMarkdownContentStyle({
testContent: 'codeblock',
style: 'border-color: gray; border-radius: 4px; padding: 0px; font-family: monospace; font-size: 20px; color: black; background-color: transparent;',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we also add some tests for missing styles like border-width: 1px;, border-style: solid; and background-color: lightgray;?

Also, why do we need border-radius: 4px; and background-color: transparent; here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We need border-radius: 4px; to specify the border radius of the codeblock. But background-color: transparent; can be safely removed

page,
});
});

test('mention-here', async ({page}) => {
Expand Down
38 changes: 34 additions & 4 deletions src/MarkdownTextInput.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
TextInputContentSizeChangeEventData,
GestureResponderEvent,
} from 'react-native';
import React, {useEffect, useRef, useCallback, useMemo, useLayoutEffect} from 'react';
import React, {useEffect, useRef, useCallback, useMemo, useLayoutEffect, useState} from 'react';
import type {CSSProperties, MutableRefObject, ReactEventHandler, FocusEventHandler, MouseEvent, KeyboardEvent, SyntheticEvent, ClipboardEventHandler, TouchEvent} from 'react';
import {StyleSheet} from 'react-native';
import {updateInputStructure} from './web/utils/parserUtils';
Expand All @@ -21,9 +21,11 @@ import {getCurrentCursorPosition, removeSelection, setCursorPosition} from './we
import './web/MarkdownTextInput.css';
import type {MarkdownStyle} from './MarkdownTextInputDecoratorViewNativeComponent';
import {getElementHeight, getPlaceholderValue, isEventComposing, normalizeValue, parseInnerHTMLToText} from './web/utils/inputUtils';
import {idGenerator, parseToReactDOMStyle, processMarkdownStyle} from './web/utils/webStyleUtils';
import {parseToReactDOMStyle, configureCustomWebStylesheet, idGenerator, processMarkdownStyle} from './web/utils/webStyleUtils';
import {forceRefreshAllImages} from './web/inputElements/inlineImage';
import type {PartialMarkdownStyle} from './styleUtils';
import type {MarkdownRange, InlineImagesInputProps} from './commonTypes';
import {handleCustomStyles} from './web/inputElements/codeblock';

const useClientEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;

Expand Down Expand Up @@ -70,6 +72,7 @@ type MarkdownTextInputElement = HTMLDivElement &
HTMLInputElement & {
tree: TreeNode;
uniqueId: string;
styleSheet: CSSStyleSheet;
selection: Selection;
imageElements: HTMLImageElement[];
};
Expand Down Expand Up @@ -132,7 +135,7 @@ const MarkdownTextInput = React.forwardRef<MarkdownTextInput, MarkdownTextInputP
const divRef = useRef<MarkdownTextInputElement | null>(null);
const currentlyFocusedField = useRef<HTMLDivElement | null>(null);
const contentSelection = useRef<Selection | null>(null);
const className = `react-native-live-markdown-input-${multiline ? 'multiline' : 'singleline'}`;
const [className, setClassName] = useState(`react-native-live-markdown-input-${multiline ? 'multiline' : 'singleline'}`);
const history = useRef<InputHistory | null>(null);
const dimensions = useRef<Dimensions | null>(null);
const pasteContent = useRef<string | null>(null);
Expand Down Expand Up @@ -379,6 +382,14 @@ const MarkdownTextInput = React.forwardRef<MarkdownTextInput, MarkdownTextInputP
if (onChangeText) {
onChangeText(parsedText);
}
if (processedMarkdownStyle) {
const preBlocks = [...divRef.current.querySelectorAll('*[data-type="pre"]')];
while (preBlocks.length > 0) {
const preBlock = preBlocks.pop() as HTMLElement;
preBlock.setAttribute('data-content', parseInnerHTMLToText(preBlock, 0));
}
handleCustomStyles(divRef.current, processedMarkdownStyle);
}
return;
}
let newInputUpdate: ParseTextResult;
Expand Down Expand Up @@ -729,15 +740,22 @@ const MarkdownTextInput = React.forwardRef<MarkdownTextInput, MarkdownTextInputP
[numberOfLines],
);

useEffect(() => {
useClientEffect(() => {
if (!divRef.current) {
return;
}
// focus the input on mount if autoFocus is set
if (autoFocus) {
divRef.current.focus();
}

const styleSheet = configureCustomWebStylesheet();
if (styleSheet) {
divRef.current.styleSheet = styleSheet;
}
divRef.current.uniqueId = idGenerator.next().value as string;
setClassName(`${className} ${divRef.current.uniqueId}`);
handleCustomStyles(divRef.current, markdownStyle as PartialMarkdownStyle);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Expand All @@ -761,9 +779,21 @@ const MarkdownTextInput = React.forwardRef<MarkdownTextInput, MarkdownTextInputP
forceRefreshAllImages(divRef.current as MarkdownTextInputElement, processedMarkdownStyle);
};

const handleStyles = () => {
if (!divRef.current) {
return;
}
handleCustomStyles(divRef.current, processedMarkdownStyle);
};

const resizeObserver = new ResizeObserver(handleStyles);
if (divRef.current) {
resizeObserver.observe(divRef.current);
}
window.addEventListener('online', handleReconnect);
return () => {
window.removeEventListener('online', handleReconnect);
resizeObserver.disconnect();
};
}, [processedMarkdownStyle]);

Expand Down
13 changes: 13 additions & 0 deletions src/MarkdownTextInputDecoratorViewNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,27 @@ interface MarkdownStyle {
code: {
fontFamily: string;
fontSize: Float;
h1NestedFontSize?: Float;
color: ColorValue;
backgroundColor: ColorValue;
borderColor: ColorValue;
borderWidth: Float;
borderRadius: Float;
borderStyle: string;
padding?: Float;
paddingVertical?: Float;
paddingHorizontal?: Float;
};
pre: {
fontFamily: string;
fontSize: Float;
color: ColorValue;
backgroundColor: ColorValue;
borderColor: string;
borderRadius: Float;
padding: Float;
paddingVertical?: Float;
paddingHorizontal?: Float;
};
mentionHere: {
color: ColorValue;
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/parseExpensiMark.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ test('inline code', () => {

test('codeblock', () => {
expect('```\nHello world!\n```').toBeParsedAs([
{type: 'syntax', start: 0, length: 3},
{type: 'pre', start: 3, length: 14},
{type: 'syntax', start: 0, length: 4},
{type: 'pre', start: 4, length: 13},
{type: 'syntax', start: 17, length: 3},
]);
});
Expand Down
17 changes: 16 additions & 1 deletion src/__tests__/webParser.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ import {expect} from '@jest/globals';
import {parseRangesToHTMLNodes} from '../web/utils/parserUtils';
import parseExpensiMark from '../parseExpensiMark';

jest.mock('react-native-web/dist/exports/StyleSheet/compiler/createReactDOMStyle', () => ({
__esModule: true,
default: jest.fn((style) => style),
}));

jest.mock('react-native-web/dist/exports/StyleSheet/preprocess', () => ({
__esModule: true,
default: jest.fn((style) => style),
}));

jest.mock('react-native-web/dist/modules/setValueForStyles/dangerousStyleValue', () => ({
__esModule: true,
default: jest.fn(() => null),
}));

declare module 'expect' {
interface Matchers<R> {
toBeParsedAsHTML(expectedHTML: string): R;
Expand Down Expand Up @@ -175,7 +190,7 @@ test('inline code', () => {

test('codeblock', () => {
expect('```\nHello world!\n```').toBeParsedAsHTML(
'<p data-type="line" data-id="0"><span data-type="syntax" data-id="0,0"><span data-type="text" data-id="0,0,0">```</span></span><span data-type="pre" data-id="0,1"><span data-type="br" data-id="0,1,0"><br data-id="0,1,0,0"></span><span data-type="text" data-id="0,1,1">Hello world!</span><span data-type="br" data-id="0,1,2"><br data-id="0,1,2,0"></span></span><span data-type="syntax" data-id="0,2"><span data-type="text" data-id="0,2,0">```</span></span></p>',
'<p data-type="line" data-id="0"><span data-type="syntax" data-id="0,0"><span data-type="text" data-id="0,0,0">```</span><span data-type="br" data-id="0,0,1"><br data-id="0,0,1,0"></span></span><span data-type="pre" data-id="0,1"><span data-type="text" data-id="0,1,0">Hello world!</span><span data-type="br" data-id="0,1,1"><br data-id="0,1,1,0"></span></span><span data-type="syntax" data-id="0,2"><span data-type="text" data-id="0,2,0">```</span></span></p>',
);
});

Expand Down
7 changes: 4 additions & 3 deletions src/parseExpensiMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,10 @@ function parseTreeToTextAndRanges(tree: StackItem): [string, MarkdownRange[]] {
} else if (node.tag === '<br />') {
text += '\n';
} else if (node.tag.startsWith('<pre')) {
appendSyntax('```');
const content = node.children.join('');
addChildrenWithStyle(content, 'pre');
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [_, lb, content] = node.children.join('').match(/^(\r?\n)([\s\S]*)$/) as RegExpMatchArray;
appendSyntax(`\`\`\`${lb}`);
addChildrenWithStyle(`${content}`, 'pre');
appendSyntax('```');
} else if (node.tag.startsWith('<a href="')) {
const rawHref = node.tag.match(/href="([^"]*)"/)![1]!; // always present
Expand Down
13 changes: 12 additions & 1 deletion src/styleUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,16 @@ function makeDefaultMarkdownStyle(): MarkdownStyle {
fontSize: 20,
color: 'black',
backgroundColor: 'lightgray',
borderColor: 'gray',
borderWidth: 1,
borderRadius: 4,
borderStyle: 'solid',
padding: 0,
},
pre: {
borderColor: 'gray',
borderRadius: 4,
padding: 2,
fontFamily: FONT_FAMILY_MONOSPACE,
fontSize: 20,
color: 'black',
Expand Down Expand Up @@ -89,7 +97,10 @@ function mergeMarkdownStyleWithDefault(input: PartialMarkdownStyle | undefined):
return output;
}

function parseStringWithUnitToNumber(value: string | null): number {
function parseStringWithUnitToNumber(value: string | number | null): number {
if (typeof value === 'number') {
return value;
}
return value ? parseInt(value.replace('px', ''), 10) : 0;
}

Expand Down
41 changes: 41 additions & 0 deletions src/web/MarkdownTextInput.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,47 @@
content: attr(placeholder);
}

.react-native-live-markdown-input-multiline *[data-type='pre']::before {
margin: 0;
display: block;
color: transparent;
border: 1px solid grey;
content: attr(data-content);
position: absolute;
z-index: -1;
left: 0;
box-sizing: border-box;
}

.react-native-live-markdown-input-multiline *[data-type='pre'] {
line-height: 1.3;
}

.react-native-live-markdown-input-singleline *[data-type='code'] > *[data-type='emoji'],
.react-native-live-markdown-input-multiline *[data-type='code'] > *[data-type='emoji'] {
font-size: inherit !important;
line-height: inherit !important;
vertical-align: unset !important;
}

.react-native-live-markdown-input-multiline *[data-type='line'] *[data-type='pre'] + *[data-type='syntax'] + *[data-type='text'] {
max-width: 100%;
}

.react-native-live-markdown-input-multiline *[data-type='line'] *[data-type='syntax']:has(+ *[data-type='pre']) {
display: grid;
line-height: 1.3;
}

.react-native-live-markdown-input-multiline *[data-type='line'] *[data-type='syntax']:has(+ *[data-type='pre']) > *:last-child {
display: none;
}

.react-native-live-markdown-input-multiline *[data-type='line'] *[data-type='pre'] + *[data-type='syntax'] {
display: grid;
line-height: 1.3;
}

@keyframes react-native-live-markdown-spin {
0% {
transform: rotate(0deg);
Expand Down
Loading