Skip to content
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

Preserve and Manage Original Markdown Formatting Across Editor Modes #557

Open
makhnatkin opened this issue Jan 21, 2025 · 0 comments
Open
Assignees
Labels
enhancement New feature or request

Comments

@makhnatkin
Copy link
Collaborator

Description

When switching between WYSIWYG and Markup modes in the MarkdownEditor, the structure of the original text in Markdown format may be modified. This is particularly problematic for certain blocks, such as yfm-table, where the serialized output differs from the original input. Users expect the original text in Markdown format to remain intact, preserving its exact structure when toggling modes.

Proposal

Introduce a new entity called MarkupManager to act as a centralized store for the original text in Markdown format and metadata about token positions. This will enable accurate reconstruction of the original Markdown during serialization.

This issue focuses on adding the MarkupManager class and integrating it with the existing MarkdownEditor infrastructure without altering the current functionality.

Requirements

  1. MarkupManager Responsibilities:

    • Store the original text in Markdown format (rawMarkdown).
    • Maintain token positions (poses) as a mapping from a Unique Token Identifier to [start, end] positions in the rawMarkdown.
    • Ensure that each token has a Unique Token Identifier for tracking. If a token lacks an identifier, it should be generated during parsing.
    • Provide methods to retrieve and update rawMarkdown and poses.
    • Store and expose the Markdown Parser instance.
  2. Integration Points:

    • Pass an instance of MarkupManager to the Markdown Parser and Markdown Serializer during initialization in ExtensionsManager.
  3. Non-breaking Changes:

    • Ensure that the new MarkupManager is integrated without affecting the current behavior of the MarkdownEditor.
  4. Tests:

    • Verify that MarkupManager correctly stores and retrieves rawMarkdown.
    • Validate that poses are updated and accessed as expected.
    • Ensure Unique Token Identifiers are correctly assigned to tokens without identifiers.
    • Ensure no regression in existing functionality.

Implementation Steps

  1. Create the MarkupManager class with the following methods:

    • setMarkup(rawMarkdown: string): void
    • getMarkup(): string
    • setPos(tokenId: string, pos: [number, number]): void
    • getPos(tokenId: string): [number, number] | null
    • setParser(parser: MarkdownParser): void
    • getParser(): MarkdownParser
    • reset(): void
  2. Ensure unique token identifier assignment:

    • Update the parsing process to check for existing Unique Token Identifiers in tokens.
    • If a Unique Token Identifier is missing, generate a unique identifier and assign it to the token.
  3. Update ExtensionsManager:

    • Create an instance of MarkupManager in createDeps.
    • Pass the instance to the MarkdownParser and MarkdownSerializer during their initialization.
  4. Write unit tests:

    • Test MarkupManager for text in Markdown formatstorage, position management, and parser handling.
    • Validate its integration in ExtensionsManager.
    • Test Unique Token Identifier generation for tokens missing an identifier.
  5. Submit the initial implementation with no impact on serialization logic.

@makhnatkin makhnatkin added the enhancement New feature or request label Jan 21, 2025
@makhnatkin makhnatkin self-assigned this Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant