markdown-it-sub.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*! markdown-it-sub 1.0.0 https://github.com//markdown-it/markdown-it-sub @license MIT */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.markdownitSub = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. // Process ~subscript~
  3. 'use strict';
  4. // same as UNESCAPE_MD_RE plus a space
  5. var UNESCAPE_RE = /\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;
  6. function subscript(state, silent) {
  7. var found,
  8. content,
  9. token,
  10. max = state.posMax,
  11. start = state.pos;
  12. if (state.src.charCodeAt(start) !== 0x7E/* ~ */) { return false; }
  13. if (silent) { return false; } // don't run any pairs in validation mode
  14. if (start + 2 >= max) { return false; }
  15. state.pos = start + 1;
  16. while (state.pos < max) {
  17. if (state.src.charCodeAt(state.pos) === 0x7E/* ~ */) {
  18. found = true;
  19. break;
  20. }
  21. state.md.inline.skipToken(state);
  22. }
  23. if (!found || start + 1 === state.pos) {
  24. state.pos = start;
  25. return false;
  26. }
  27. content = state.src.slice(start + 1, state.pos);
  28. // don't allow unescaped spaces/newlines inside
  29. if (content.match(/(^|[^\\])(\\\\)*\s/)) {
  30. state.pos = start;
  31. return false;
  32. }
  33. // found!
  34. state.posMax = state.pos;
  35. state.pos = start + 1;
  36. // Earlier we checked !silent, but this implementation does not need it
  37. token = state.push('sub_open', 'sub', 1);
  38. token.markup = '~';
  39. token = state.push('text', '', 0);
  40. token.content = content.replace(UNESCAPE_RE, '$1');
  41. token = state.push('sub_close', 'sub', -1);
  42. token.markup = '~';
  43. state.pos = state.posMax + 1;
  44. state.posMax = max;
  45. return true;
  46. }
  47. module.exports = function sub_plugin(md) {
  48. md.inline.ruler.after('emphasis', 'sub', subscript);
  49. };
  50. },{}]},{},[1])(1)
  51. });