UNPKG

@gravityforms/gulp-tasks

Version:
48 lines (37 loc) 1.22 kB
const { Token } = require( './token' ); function escapeHtmlPreserveIndentation( str ) { return str .split( '\n' ) .map(line => line.replace( /&/g, '&amp;' ) .replace( /</g, '&lt;' ) .replace( />/g, '&gt;' ) ) .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 };