Skip to content

refactor prosemirror conversion for understandability #779

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vezwork
Copy link
Collaborator

@vezwork vezwork commented Aug 5, 2025

Changes

  • Apply formatter to changed files (mostly normalize whitespace, semicolons)
  • Big refactor of mapTokens (renamed to mapTokensRecursive)
    • Move nested functions out
    • Clarify isToken logic by removing redundant logic
    • This function has somewhat brain-bending recursive functionality (I was confused and I also saw it being misused in resolvePandocBlockCapsuleText, resulting in redundant logic). It has two interrelated recursive parts. A "recursive array data mapping" part and a "recursive function output content mapping" part. Because of the recursive nature of this function, I feel justified in going full functional programmer on its refactor: I refactored into two separate functions that return functions: mapRecursiveArray factors out the "recursive array data mapping" part, and mapTokenAndContentTokensRecursively factors out the "recursive function output content mapping" part. It is still a difficult function to understand, but I've removed some redundancy and made how its parts depend on eachother more direct and explicit.
    • Add docs
  • After refactoring mapTokensRecursive I understood it better and was able to understand and significantly simplify resolvePandocBlockCapsuleText
  • Change writeToken to prefer Array.find over iterating through the array until the element is found.
  • Refactor createHandlers
    • Pulls out the non-looping part into createHandler which is nice because it can now early return instead of modifying a variable.

TODO

  • add tests

@vezwork vezwork force-pushed the refactor/pandoc-to-prosemirror branch 5 times, most recently from f02062a to 8b224d7 Compare August 5, 2025 21:11
@vezwork vezwork requested a review from cscheid August 5, 2025 22:02
@vezwork vezwork changed the title refactor code around conversion to prosemirror for my understanding refactor prosemirror conversion for understandability Aug 6, 2025
@vezwork vezwork force-pushed the refactor/pandoc-to-prosemirror branch from 8b224d7 to 650f72b Compare August 6, 2025 14:14
@vezwork vezwork force-pushed the refactor/pandoc-to-prosemirror branch from 650f72b to 919fdaa Compare August 6, 2025 14:15
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.

1 participant