prism-remove-initial-line-feed.js 550 B

123456789101112131415161718192021
  1. (function () {
  2. if (typeof Prism === 'undefined' || typeof document === 'undefined') {
  3. return;
  4. }
  5. Prism.hooks.add('before-sanity-check', function (env) {
  6. if (env.code) {
  7. var pre = env.element.parentNode;
  8. var clsReg = /(?:^|\s)keep-initial-line-feed(?:\s|$)/;
  9. if (
  10. pre && pre.nodeName.toLowerCase() === 'pre' &&
  11. // Apply only if nor the <pre> or the <code> have the class
  12. (!clsReg.test(pre.className) && !clsReg.test(env.element.className))
  13. ) {
  14. env.code = env.code.replace(/^(?:\r?\n|\r)/, '');
  15. }
  16. }
  17. });
  18. }());