Skip to content

Multiply number column after calling lineNumbersBlock multiply times  #74

Open
@XianfuZhengAfterpay

Description

@XianfuZhengAfterpay

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

Activity

guillaume-dorczynski

guillaume-dorczynski commented on Jun 6, 2020

@guillaume-dorczynski

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

realwugang commented on Oct 10, 2024

@realwugang
    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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Multiply number column after calling lineNumbersBlock multiply times · Issue #74 · wcoder/highlightjs-line-numbers.js