preamble.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* eslint-disable
  2. max-len,
  3. */
  4. // TODO: This file was created by bulk-decaffeinate.
  5. // Fix any style issues and re-enable lint.
  6. /*
  7. * decaffeinate suggestions:
  8. * DS102: Remove unnecessary code created because of implicit returns
  9. * DS103: Rewrite code to no longer use __guard__
  10. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  11. */
  12. import App from '../../../base'
  13. export default App.factory('preamble', function (ide) {
  14. const Preamble = {
  15. getPreambleText() {
  16. const text = ide.editorManager.getCurrentDocValue().slice(0, 5000)
  17. const preamble =
  18. __guard__(text.match(/([^]*)^\\begin\{document\}/m), x => x[1]) || ''
  19. return preamble
  20. },
  21. getGraphicsPaths() {
  22. let match
  23. const preamble = Preamble.getPreambleText()
  24. const graphicsPathsArgs =
  25. __guard__(preamble.match(/\\graphicspath\{(.*)\}/), x => x[1]) || ''
  26. const paths = []
  27. const re = /\{([^}]*)\}/g
  28. while ((match = re.exec(graphicsPathsArgs))) {
  29. paths.push(match[1])
  30. }
  31. return paths
  32. },
  33. }
  34. return Preamble
  35. })
  36. function __guard__(value, transform) {
  37. return typeof value !== 'undefined' && value !== null
  38. ? transform(value)
  39. : undefined
  40. }