UNPKG

@gravityforms/gulp-tasks

Version:
46 lines (35 loc) 930 B
import { Token } from './token.js'; 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 ) { 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 };