File tree Expand file tree Collapse file tree 3 files changed +15
-7
lines changed
Expand file tree Collapse file tree 3 files changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { mount, shallow } from 'enzyme';
22import path from 'path' ;
33import glob from 'glob' ;
44import { promises as fs } from 'fs' ;
5+ import Variable from '@readme/variable' ;
56import syntaxHighlighter , { uppercase , canonical } from '../src' ;
67
78const fixtures = glob . sync ( path . join ( __dirname , '/__fixtures__/*' ) ) ;
@@ -157,7 +158,15 @@ describe('highlight mode', () => {
157158 expect ( node . find ( 'p' ) . first ( ) . hasClass ( 'cm-lineNumber' ) ) . toBe ( true ) ;
158159 } ) ;
159160
161+ it ( 'should convert variable regex matches to a component instance' , ( ) => {
162+ expect ( node . find ( Variable ) ) . toHaveLength ( 1 ) ;
163+ } ) ;
164+
160165 it ( 'should highlight based on range input' , ( ) => {
161- expect ( node . find ( '.cm-linerow.cm-highlight' ) ) . toHaveLength ( 4 ) ;
166+ expect ( node . find ( '.cm-linerow.cm-highlight' ) ) . toHaveLength ( 2 ) ;
167+ } ) ;
168+
169+ it ( 'should add an overlay to non-highlighted in lines when ranges are applied' , ( ) => {
170+ expect ( node . find ( '.cm-linerow.cm-overlay' ) ) . toHaveLength ( 6 ) ;
162171 } ) ;
163172} ) ;
Original file line number Diff line number Diff line change @@ -22,8 +22,8 @@ ReactDOM.render(
2222 { ch : 0 , line : 1 } ,
2323 ] ,
2424 [
25+ { ch : 0 , line : 2 } ,
2526 { ch : 0 , line : 3 } ,
26- { ch : 0 , line : 5 } ,
2727 ] ,
2828 ] ,
2929 }
Original file line number Diff line number Diff line change @@ -47,20 +47,19 @@ StructuredOutput.propTypes = {
4747 * @arg {[][]{line: Int}} ranges
4848 * @return {[String] } Consumable classNames
4949 */
50- const highlightedLines = ranges => {
50+ const highlightedLines = ( ranges , totalLength ) => {
5151 const highlights = [ ] ;
5252
5353 ranges . forEach ( ( [ anchor , head ] ) => {
5454 const end = head . line ;
5555 let position = anchor . line ;
56-
57- while ( position <= end ) {
56+ while ( position < end ) {
5857 highlights [ position ] = 'cm-highlight' ;
5958 position += 1 ;
6059 }
6160 } ) ;
6261
63- for ( let i = 0 ; i < highlights . length ; i += 1 ) {
62+ for ( let i = 0 ; i < totalLength ; i += 1 ) {
6463 if ( ! highlights [ i ] ) highlights [ i ] = 'cm-overlay' ;
6564 }
6665
@@ -88,7 +87,7 @@ const StyledSyntaxHighlighter = ({ output, ranges }) => {
8887 }
8988 } ) ;
9089
91- const highlights = ranges && ranges . length ? highlightedLines ( ranges ) : [ ] ;
90+ const highlights = ranges && ranges . length ? highlightedLines ( ranges , gutteredOutput . length ) : [ ] ;
9291 return (
9392 < div className = "CodeMirror cm-s-material-palenight" >
9493 < StructuredOutput gutteredInput = { gutteredOutput } highlights = { highlights } />
You can’t perform that action at this time.
0 commit comments