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

Multiply number column after calling lineNumbersBlock multiply times #74

Open
XianfuZhengAfterpay opened this issue Mar 15, 2020 · 2 comments

Comments

@XianfuZhengAfterpay
Copy link

Is your feature request related to a problem? Please describe.
In our use case, we have an editable highlight js component by adding contenteditable attribute. We want to update the line number whenever the content is changed (lose focus event).

The problem here is , it adds a new column for the line number after each lineNumbersBlock. Is the right function to call to update the line number?

Describe the solution you'd like
I expect it should maintain the internal state so only one line column should be shown.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

The below code is what we are using:
element.addEventListener( 'focusout', function( event ) { hljsWithLineNumber.highlightBlock( event.currentTarget ); hljsWithLineNumber.lineNumbersBlock(event.currentTarget); }, false );
Please see screen shot:
image

@guillaume-dorczynski
Copy link

guillaume-dorczynski commented Jun 6, 2020

highlightjs is not meant to be a code editor, it should be used only for highlighting code. If you want a code editor, look at Ace or CodeMirror

@realwugang
Copy link

    const lineNumbersBlockWeakMap = new WeakMap()
    window.hljs.lineNumbersBlock2 = (element, options) => {
      if (lineNumbersBlockWeakMap.has(element)) return
      lineNumbersBlockWeakMap.set(element, true)
      window.hljs.lineNumbersBlock(element,options)
      setTimeout(() => {
        lineNumbersBlockWeakMap.delete(element)
      })
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants