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

Add data-gutter on exporting CodeNode #6

Closed
2wheeh opened this issue Jan 9, 2024 · 5 comments
Closed

Add data-gutter on exporting CodeNode #6

2wheeh opened this issue Jan 9, 2024 · 5 comments

Comments

@2wheeh
Copy link

2wheeh commented Jan 9, 2024

Hi ! I came here to want to follow this : facebook/lexical#4743 (comment)

I found a way to set data-gutter without implementing a whole custom node:

It can be easier with this feature like this

   html: {
      export: new Map([
        [
          CodeNode,
          (_, node) => {
            const element = document.createElement('pre');
            element.setAttribute('spellcheck', 'false');
            const language = node.getLanguage();

            if (language) {
              element.setAttribute('data-highlight-language', language);
            }

            const children = node.getChildren();
            const childrenLength = children.length;

            let gutter = '1';
            let count = 1;
            for (let i = 0; i < childrenLength; i++) {
              if ($isLineBreakNode(children[i])) {
                gutter += '\n' + ++count;
              }
            }

            element.setAttribute('data-gutter', gutter);

            return { element };
          },
        ],
      ]),
    },
@ibastawisi
Copy link
Owner

ibastawisi commented Jan 9, 2024

looks good to me, thanks.
by the way, why is this issue here and not on https://github.com/facebook/lexical?

@2wheeh
Copy link
Author

2wheeh commented Jan 9, 2024

@ibastawisi I just tried to find in which codebase you implement that and thought it is here. hope you don't mind it.

@ibastawisi
Copy link
Owner

@ibastawisi I just tried to find in which codebase you implement that and thought it is here. hope you don't mind it.

yeah no problem.
this editor config thing never worked for me!
I also needed to add syntax highlighting for c sharp, so I ended up copying the sources for the node and doing what I wanted.

@2wheeh
Copy link
Author

2wheeh commented Jan 9, 2024

btw for more language support, you just have to import prismjs sub package:

import 'prismjs/components/prism-csharp'

@ibastawisi
Copy link
Owner

btw for more language support, you just have to import prismjs sub package:

import 'prismjs/components/prism-csharp'

yeah that's what I did, thanks a lot.

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

No branches or pull requests

2 participants