Skip to content
Closed
Changes from all commits
Commits
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
23 changes: 15 additions & 8 deletions packages/text/src/markdown/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,20 @@ export function calcSørensenDiceCoefficient (a: string, b: string): number {
* Perform markdown diff/comparison to understand do we have a major differences.
*/
export function isMarkdownsEquals (source1: string, source2: string): boolean {
const lines1 = source1
.split('\n')
.map((it) => it.trimEnd())
.join('\n')
const lines2 = source2
.split('\n')
.map((it) => it.trimEnd())
.join('\n')
const normalizeLineEndings = (str: string) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

If comments will not be supported we will potentially break description on github, let's support html/comments first and then add a trim of lines >2 into 1 into comparison, but not allow without line and with line be the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just fyi: even with this change description with comment and without comment will not be equal.

str.replace(/\r?\n/g, '\n');

const excludeBlankLines = (str: string) =>
str.split('\n')
.map((it) => it.trimEnd())
.filter(it => it.length > 0)
.join('\n')

const norm1 = normalizeLineEndings(source1)
const lines1 = excludeBlankLines(norm1)

const norm2 = normalizeLineEndings(source2)
const lines2 = excludeBlankLines(norm2)

return lines1 === lines2
}