math.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. determiner.math = function(block,lines,firstChar,secondChar,thirdChar){
  2. if( (firstChar == '\\' && secondChar == '[') || (firstChar == '$' && secondChar == '$') )
  3. {
  4. return "math-component";
  5. }
  6. return false;
  7. };
  8. bloxFormats.math = { label: '<svg class="icon icon-omega"><use xlink:href="#icon-omega"></use></svg>', title: 'Math', component: 'math-component' };
  9. formatConfig.push('math');
  10. const mathComponent = Vue.component('math-component', {
  11. props: ['compmarkdown', 'disabled'],
  12. template: '<div>' +
  13. '<input type="hidden" ref="markdown" :value="compmarkdown" :disabled="disabled" @input="updatemarkdown" />' +
  14. '<div class="contenttype"><svg class="icon icon-omega"><use xlink:href="#icon-omega"></use></svg></div>' +
  15. '<textarea class="mdcontent" ref="markdown" v-model="mathblock" :disabled="disabled" @input="createmarkdown"></textarea>' +
  16. '</div>',
  17. data: function(){
  18. return {
  19. mathblock: ''
  20. }
  21. },
  22. mounted: function(){
  23. this.$refs.markdown.focus();
  24. if(this.compmarkdown)
  25. {
  26. var dollarMath = new RegExp(/^\$\$[\S\s]+\$\$$/m);
  27. var bracketMath = new RegExp(/^\\\[[\S\s]+\\\]$/m);
  28. if(dollarMath.test(this.compmarkdown) || bracketMath.test(this.compmarkdown))
  29. {
  30. var mathExpression = this.compmarkdown.substring(2,this.compmarkdown.length-2);
  31. this.mathblock = mathExpression.trim();
  32. }
  33. }
  34. this.$nextTick(function () {
  35. autosize(document.querySelectorAll('textarea'));
  36. });
  37. },
  38. methods: {
  39. createmarkdown: function(event)
  40. {
  41. this.codeblock = event.target.value;
  42. var codeblock = '$$\n' + event.target.value + '\n$$';
  43. this.updatemarkdown(codeblock);
  44. },
  45. updatemarkdown: function(codeblock)
  46. {
  47. this.$emit('updatedMarkdown', codeblock);
  48. },
  49. },
  50. })