code-wrapper.js 518 B

123456789101112131415
  1. /*
  2. 处理code
  3. */
  4. module.exports = function codeWrapper(html) {
  5. const group = html.replace(/<\/pre>/g, '</pre>:::').split(':::');
  6. const codeOnline = `<div class="handle-part"><a href="https://gitpod.io/#https://github.com/jdf2e/nutui.git" target="_blank" class="online-btn">在线运行</a></div>`;
  7. return group
  8. .map(fragment => {
  9. if (fragment.indexOf('</div>demo') !== -1) {
  10. return fragment.replace('<p></div>demo</p>', '') + codeOnline;
  11. }
  12. return fragment;
  13. })
  14. .join('');
  15. };