@gravityforms/gulp-tasks
Version:
Configurable Gulp tasks for use in Gravity Forms projects.
46 lines (35 loc) • 930 B
JavaScript
import { Token } from './token.js';
function escapeHtmlPreserveIndentation( str ) {
return str
.split( '\n' )
.map( ( line ) =>
line.replace( /&/g, '&' )
.replace( /</g, '<' )
.replace( />/g, '>' ),
)
.join( '\n' );
}
class htmlExample extends Token {
typeText = 'htmlexample';
endCondition( text ) {
const trimmedText = text.trim();
if ( trimmedText.startsWith( '@' ) && ! trimmedText.startsWith( '@htmlexample' ) ) {
return true;
}
if ( trimmedText === '' ) {
return true;
}
return false;
}
tokenCondition( text ) {
return text.trim().startsWith( '@htmlexample' );
}
getContent() {
const content = this.lines.slice();
content.shift();
const rawHtml = content.join( '\n' );
const escapedHtml = escapeHtmlPreserveIndentation( rawHtml );
return `<pre class="prettyprint source lang-html"><code>${ escapedHtml }</code></pre>`;
}
}
export { htmlExample };