Skip to content

Fix diff stringification issues and optimized formatting - #602

Merged
apple502j merged 6 commits into
scratchblocks:mainfrom
LuYifei2011:fix-588-diff-stringify
Jun 23, 2026
Merged

Fix diff stringification issues and optimized formatting#602
apple502j merged 6 commits into
scratchblocks:mainfrom
LuYifei2011:fix-588-diff-stringify

Conversation

@LuYifei2011

@LuYifei2011 LuYifei2011 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Resolves #588
Resolves #601

Changes

  • Fix duplicate +
  • Fix - not stringified.
  • Fix +- not at the beginning of the line when stringifying.
  • Fix +- escaping
  • Fix :: - rendering
  • Optimize diff format
  • and maybe more?

Known Issues

  1. If we directly call the stringify function of the script and block, we will get a string with DIFF_MARK.
    Do we need to handle this situation, or at least export prettyPrintDiff?
  2. The - diff of the embedded block still cannot be rendered: say (size :: -) image
    (I'm not familiar with rendering, but I might fix it later.)

Details

Fix duplicate +

original code & stringify (fixed):

+ forever
+   show
+ end

stringify (before):

+ forever
+   + show
+ end

Fix - not stringified

original code & stringify (fixed):

- show

show :: -

stringify (before):

show

show

Fix +- not at the beginning of the line when stringifying

original code & stringify (fixed):

  forever
+   show
  end

stringify (before):

forever
  + show
end

Fix +- escaping

original code & stringify (fixed):

\+ show
\- show

stringify (before):

+ show
- show

Fix :: - rendering

code: show :: -
before:
图片
fixed:
图片

Optimize diff format

new (stringify):

  show
+ hide
  hide
+ show

old (stringify):

show
+ hide
hide
+ show

NOTE: The current logic is that if the script has diffs, the entire script is indented. Perhaps it could be changed to be based on doc?


And I think we should add some tests?

@apple502j apple502j left a comment

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.

Breaking change, unfortunately.
Maybe you could make the current stringify an internal API (_stringify), and make stringify call prettyPrintDiff?

@apple502j apple502j mentioned this pull request Jun 21, 2026
@apple502j

Copy link
Copy Markdown
Member

@LuYifei2011 I'd appreciate if you could push the changes (or I can handle it myself, if necessary).

@LuYifei2011
LuYifei2011 requested a review from apple502j June 23, 2026 05:38
@apple502j
apple502j merged commit 243c13e into scratchblocks:main Jun 23, 2026
2 checks passed
@apple502j apple502j mentioned this pull request Jun 24, 2026
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.

Some bugs in block highlighting Diff lines stringify issue

2 participants