Skip to content

Conversation

@lytion
Copy link
Contributor

@lytion lytion commented Sep 22, 2025

Description

Reported issue: #7820
To summarize, if you use indent button and then switch to markdown, indent will be lost.

I decided to fix this issue by adding a transformer by I think it could also be fixed by handling it directly in createMarkdownExport and createMarkdownImport

This transformer simply add '\t' when exporting to markdown and remove those '\t' and set indent when importing from markdown. This only happen if '\t' is found at the beginning of the string and if the parent is a paragraph to avoid applying it to lists.

Closes #7820

This transformer allows to keep indentation when switching with markdown
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 22, 2025
@vercel
Copy link

vercel bot commented Sep 22, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
lexical Ready Ready Preview Comment Nov 27, 2025 1:52pm
lexical-playground Ready Ready Preview Comment Nov 27, 2025 1:52pm

@etrepum
Copy link
Collaborator

etrepum commented Sep 22, 2025

Failing lint https://github.com/facebook/lexical/actions/runs/17919434734/job/50950181819?pr=7845

/home/runner/work/lexical/lexical/packages/lexical-markdown/src/index.ts
Error:   31:3  error  'INDENT' is defined but never used. Allowed unused vars must match /^_/u  @typescript-eslint/no-unused-vars

@etrepum
Copy link
Collaborator

etrepum commented Sep 22, 2025

Now the prettier check is failing https://github.com/facebook/lexical/actions/runs/17919849090/job/50951631139

You can run the integrity checks locally with npm run ci-check, and if the husky git commit hooks are installed then it will catch these formatting issues locally as well. You can fix the prettier issue with npm run prettier:fix

@fantactuka
Copy link
Collaborator

fantactuka commented Oct 29, 2025

Given it's not a standard spec transformation, it might be better to keep it as a separate exported transformer instead of including it into default transformers set. And then add it explicitly into playground's transformers list

- Remove INDENT from TEXT_MATCH_TRANSFORMERS
- Export INDENT and use it in playground

Signed-off-by: Simon Bauchet <[email protected]>
# Conflicts:
#	packages/lexical-markdown/src/MarkdownTransformers.ts
#	packages/lexical-markdown/src/__tests__/unit/LexicalMarkdown.test.ts
@lytion
Copy link
Contributor Author

lytion commented Nov 14, 2025

Is there some way to run tests in a linux environment or should I test it in a vm ?
Edit: Looks like updating the branch fix the e2e test

etrepum
etrepum previously approved these changes Nov 14, 2025
return;
}
parentNode.setIndent(indents.length);
textNode.setTextContent(textNode.getTextContent().replace(/^\t+/, ''));
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems like maybe there's a bug elsewhere because tabs are usually supposed to use TabNode

Co-authored-by: Bob Ippolito <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Indent lost when switching to Markdown

4 participants