html_inline.js 1013 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Process html tags
  2. 'use strict';
  3. var HTML_TAG_RE = require('../common/html_re').HTML_TAG_RE;
  4. function isLetter(ch) {
  5. /*eslint no-bitwise:0*/
  6. var lc = ch | 0x20; // to lower case
  7. return (lc >= 0x61/* a */) && (lc <= 0x7a/* z */);
  8. }
  9. module.exports = function html_inline(state, silent) {
  10. var ch, match, max, token,
  11. pos = state.pos;
  12. if (!state.md.options.html) { return false; }
  13. // Check start
  14. max = state.posMax;
  15. if (state.src.charCodeAt(pos) !== 0x3C/* < */ ||
  16. pos + 2 >= max) {
  17. return false;
  18. }
  19. // Quick fail on second char
  20. ch = state.src.charCodeAt(pos + 1);
  21. if (ch !== 0x21/* ! */ &&
  22. ch !== 0x3F/* ? */ &&
  23. ch !== 0x2F/* / */ &&
  24. !isLetter(ch)) {
  25. return false;
  26. }
  27. match = state.src.slice(pos).match(HTML_TAG_RE);
  28. if (!match) { return false; }
  29. if (!silent) {
  30. token = state.push('html_inline', '', 0);
  31. token.content = state.src.slice(pos, pos + match[0].length);
  32. }
  33. state.pos += match[0].length;
  34. return true;
  35. };