Skip to main content

LezerHighlighter

                            
                              
                                class 
                                LezerHighlighter
                                implements 
                                
                                  
                                    
                                      CodeHighlighter
                                      
                                        
                                          
                                            
                                              
                                                
                                                  LezerCache
                                                
                                                
                                                  null
                                                
                                              
                                            
                                          
                                        
                                      
                                    
                                  
                                
                              
                              

Describes custom highlighters used by the Code node.

Constructors

constructor

                            
                              
                                public 
                                new
                                LezerHighlighter
                                
                                  
                                    
                                      parser
                                      : 
                                      Parser
                                    
                                    
                                      style
                                      : 
                                      HighlightStyle
                                       = 
                                      DefaultHighlightStyle
                                    
                                  
                                
                                : 
                                LezerHighlighter
                              
                              

Parameters

  • parser : Parser
  • style : HighlightStyle = DefaultHighlightStyle

Methods

highlight

                            
                              
                                public 
                                highlight
                                
                                  
                                    
                                      index
                                      : 
                                      number
                                    
                                    
                                      cache
                                      : 
                                      
                                        
                                          
                                            null
                                          
                                          
                                            LezerCache
                                          
                                        
                                      
                                    
                                  
                                
                                : 
                                HighlightResult
                              
                              

Highlights the code at the given index.

Parameters

  • index : number

    The index of the code to highlight.

  • cache : null LezerCache

    The result of prepare .


initialize

                            
                              
                                public 
                                initialize
                                (): 
                                boolean
                              
                              

Initializes the highlighter.

This method is called when collecting async resources for the node.It can be called multiple times so caching the initialization isrecommended.

If initialization is asynchronous, a promise should be registered using DependencyContext.collectPromise and the value of false shouldbe returned. The hook will be called again when the promise resolves.This process can be repeated until the value of true is returned whichwill mark the highlighter as ready.


prepare

                            
                              
                                public 
                                prepare
                                
                                  
                                    
                                      code
                                      : 
                                      string
                                    
                                  
                                
                                : 
                                
                                  
                                    
                                      null
                                    
                                    
                                      LezerCache
                                    
                                  
                                
                              
                              

Prepares the code for highlighting.

This method is called each time the code changes. It can be used to doany preprocessing of the code before highlighting. The result of thismethod is cached and passed to highlight when the code ishighlighted.

Parameters

  • code : string

    The code to prepare.


tokenize

                            
                              
                                public 
                                tokenize
                                
                                  
                                    
                                      code
                                      : 
                                      string
                                    
                                  
                                
                                : 
                                string
                                []
                              
                              

Tokenize the code.

Parameters

  • code : string

    The code to tokenize.