-
Notifications
You must be signed in to change notification settings - Fork 59
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
Fix layout of nested blockquotes #202
Conversation
float shift = (marginLeft + borderWidth + paddingLeft) * level; | ||
float left = x + dir * marginLeft + shift; | ||
float right = x + dir * (marginLeft + borderWidth) + shift; |
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.
Since we multiply marginLeft
by dir
, shouldn't we also multiply shift
by dir
?
const groupedRanges = groupRanges(sortedRanges); | ||
return groupedRanges; |
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.
Can we add some unit tests for nested blockquotes to verify that groupRanges
indeed works correctly?
src/web/parserUtils.ts
Outdated
if (!range.depth) { | ||
ungroupedRanges.push(range); | ||
} | ||
Array.from({length: range.depth!}).forEach(() => ungroupedRanges.push(range)); |
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.
Shouldn't we remove depth
from pushed ranges here?
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.
Since we are doing it before parsing, there is no need to do so, the main loop of the parser is not using the info about depth
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 understand, it's just that it could be confusing to still see depth
in there, like:
[
{style: "blockquote", start: 0, end: 10, depth: 3},
{style: "blockquote", start: 0, end: 10, depth: 3},
{style: "blockquote", start: 0, end: 10, depth: 3},
]
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.
You're right, I'll add removing it
src/web/parserUtils.ts
Outdated
@@ -87,7 +98,7 @@ function parseRangesToHTMLNodes(text: string, ranges: MarkdownRange[], markdownS | |||
return root; | |||
} | |||
|
|||
const stack = [...ranges]; | |||
const stack = [...ungroupRanges(ranges)]; |
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.
Why do we need to make an additional copy here?
const stack = [...ungroupRanges(ranges)]; | |
const stack = ungroupRanges(ranges); |
b558d45
to
37b4ae0
Compare
parser/__tests__/index.test.js
Outdated
@@ -332,4 +332,42 @@ describe('trailing whitespace', () => { | |||
]); | |||
}); | |||
}); | |||
|
|||
describe('nested quotes', () => { |
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.
We use "blockquote" instead of "quote" consistently across this file, let's stick to that
describe('nested quotes', () => { | |
describe('nested blockquotes', () => { |
parser/__tests__/index.test.js
Outdated
]); | ||
}); | ||
|
||
test('two separate quote depths', () => { |
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.
test('two separate quote depths', () => { | |
test('different blockquote depths', () => { |
parser/__tests__/index.test.js
Outdated
}); | ||
|
||
test('two separate quote depths', () => { | ||
expect('>> Hello 1 \n > Hello 2').toBeParsedAs([ |
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.
expect('>> Hello 1 \n > Hello 2').toBeParsedAs([ | |
expect('>> Hello 1\n> Hello 2').toBeParsedAs([ |
parser/__tests__/index.test.js
Outdated
]); | ||
}); | ||
|
||
test('with diffrent markdown inside', () => { |
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.
test('with diffrent markdown inside', () => { | |
test('with another style inside', () => { |
parser/__tests__/index.test.js
Outdated
expect('>> Hello world').toBeParsedAs([ | ||
{type: 'blockquote', start: 0, length: 14, depth: 2}, |
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.
expect('>> Hello world').toBeParsedAs([ | |
{type: 'blockquote', start: 0, length: 14, depth: 2}, | |
expect('>>> Hello world').toBeParsedAs([ | |
{type: 'blockquote', start: 0, length: 14, depth: 3}, |
parser/__tests__/index.test.js
Outdated
@@ -332,4 +332,42 @@ describe('trailing whitespace', () => { | |||
]); | |||
}); | |||
}); | |||
|
|||
describe('nested quotes', () => { | |||
test('simple example', () => { |
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 make this test consistent to the following one
test('simple example', () => { | |
test('without whitespace between syntax', () => { |
android/src/main/java/com/expensify/livemarkdown/MarkdownBlockquoteSpan.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Tomek Zawadzki <[email protected]>
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.
Tested on Android, iOS and web. Thanks a lot for your efforts on it! ❤️
Details
Related Issues
GH_LINK
Manual Tests
Linked PRs