@gravityforms/gulp-tasks
Version:
Configurable Gulp tasks for use in Gravity Forms projects.
48 lines (38 loc) • 1.13 kB
JavaScript
import { Token } from './token.js';
class cssSelector extends Token {
typeText = 'cssselector';
endCondition( text ) {
if ( text.indexOf( 'cssselector' ) !== -1 ) {
return false;
}
return true;
}
tokenCondition( text ) {
if ( text.indexOf( 'cssselector' ) !== -1 ) {
return true;
}
return false;
}
processSelector( selector ) {
let output = '';
for ( let i = 0; i < selector.length; i++ ) {
const currentChar = selector.charAt( i );
if ( /[~@#$%^&*()+=,.[-\]{}\\|;:'"<>\?/]/g.test( currentChar ) ) {
output += `<span class="type-signature">${ currentChar }</span>`;
} else {
output += currentChar;
}
}
return output;
}
createLinkableHash( text ) {
return text.replace( /^[~@#$%^&()+=,.[-\]{}\\|;:'"<>\?/]/, '' ).replace( /[^\w-]/g, '-' ).toLowerCase();
}
getContent() {
let content = this.lines.join( '\n' ).trim();
content = content.replace( '@cssselector', '' ).trimStart();
const hash = this.createLinkableHash( content );
return `<h3 class="name has-anchor" id="~${ hash }">${ this.processSelector( content ) }</h3>`;
}
}
export { cssSelector };