CAT-SOOP is a flexible, programmable learning management system based on the Python programming language. https://catsoop.mit.edu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

61 lines
2.0 KiB

  1. # This file is part of CAT-SOOP
  2. # Copyright (c) 2011-2017 Adam Hartz <hartz@mit.edu>
  3. #
  4. # This program is free software: you can redistribute it and/or modify it under
  5. # the terms of the GNU Affero General Public License as published by the Free
  6. # Software Foundation, either version 3 of the License, or (at your option) any
  7. # later version.
  8. #
  9. # This program is distributed in the hope that it will be useful, but WITHOUT
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  12. # details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. tutor.qtype_inherit('bigbox')
  17. _base_render_html = render_html
  18. defaults.update({
  19. 'csq_soln': '',
  20. 'csq_npoints': 1,
  21. 'csq_show_check': False,
  22. })
  23. def markdownify(context, text):
  24. return context['csm_language']._md(text)
  25. def richtext_format(context, text, msg="Preview:"):
  26. text = text.replace('<', '&lt;').replace('>', '&gt;')
  27. out = '</br>%s<br/>' % msg
  28. out += ('<div style="background-color: #eeeeee;'
  29. 'padding:10px; border-radius:10px;">')
  30. out += markdownify(context, text)
  31. out += ('<script type="text/javascript">'
  32. 'catsoop.render_all_math($("#cs_qdiv_%s"), true);'
  33. '</script>') % context['csq_name']
  34. out += '</div>'
  35. return out
  36. checktext = "Preview"
  37. def handle_check(submission, **info):
  38. last = submission.get(info['csq_name'])
  39. return richtext_format(info, last)
  40. def render_html(last_log, **info):
  41. out = _base_render_html(last_log, **info)
  42. help_url = '/'.join([info['cs_url_root'], '__QTYPE__', 'richtext',
  43. 'formatting.html'])
  44. out += ('''<a onClick="window.open('%s', '_blank', '''
  45. ''''');" '''
  46. '''style="cursor:pointer; cursor:hand;">'''
  47. '''Formatting Help</a>''') % help_url
  48. return out