@gravityforms/gulp-tasks
Version:
Configurable Gulp tasks for use in Gravity Forms projects.
48 lines (37 loc) • 1.22 kB
JavaScript
const { Token } = require( './token' );
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, prevLine ) {
const trimmedText = text.trim();
// End if a new @tag starts
if ( trimmedText.startsWith( '@' ) && ! trimmedText.startsWith( '@htmlexample' ) ) {
return true;
}
// End if an empty line is encountered
if ( trimmedText === '' ) {
return true;
}
return false;
}
tokenCondition( text ) {
return text.trim().startsWith( '@htmlexample' );
}
getContent() {
let content = this.lines.slice();
const firstLine = content.shift();
const rawHtml = content.join( '\n' );
const escapedHtml = escapeHtmlPreserveIndentation( rawHtml );
return `<pre class="prettyprint source lang-html"><code>${ escapedHtml }</code></pre>`;
}
}
module.exports = { htmlExample };