prism-aspnet.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. Prism.languages.aspnet = Prism.languages.extend('markup', {
  2. 'page-directive': {
  3. pattern: /<%\s*@.*%>/,
  4. alias: 'tag',
  5. inside: {
  6. 'page-directive': {
  7. pattern: /<%\s*@\s*(?:Assembly|Control|Implements|Import|Master(?:Type)?|OutputCache|Page|PreviousPageType|Reference|Register)?|%>/i,
  8. alias: 'tag'
  9. },
  10. rest: Prism.languages.markup.tag.inside
  11. }
  12. },
  13. 'directive': {
  14. pattern: /<%.*%>/,
  15. alias: 'tag',
  16. inside: {
  17. 'directive': {
  18. pattern: /<%\s*?[$=%#:]{0,2}|%>/,
  19. alias: 'tag'
  20. },
  21. rest: Prism.languages.csharp
  22. }
  23. }
  24. });
  25. // Regexp copied from prism-markup, with a negative look-ahead added
  26. Prism.languages.aspnet.tag.pattern = /<(?!%)\/?[^\s>\/]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">=]+))?)*\s*\/?>/;
  27. // match directives of attribute value foo="<% Bar %>"
  28. Prism.languages.insertBefore('inside', 'punctuation', {
  29. 'directive': Prism.languages.aspnet['directive']
  30. }, Prism.languages.aspnet.tag.inside['attr-value']);
  31. Prism.languages.insertBefore('aspnet', 'comment', {
  32. 'asp-comment': {
  33. pattern: /<%--[\s\S]*?--%>/,
  34. alias: ['asp', 'comment']
  35. }
  36. });
  37. // script runat="server" contains csharp, not javascript
  38. Prism.languages.insertBefore('aspnet', Prism.languages.javascript ? 'script' : 'tag', {
  39. 'asp-script': {
  40. pattern: /(<script(?=.*runat=['"]?server\b)[^>]*>)[\s\S]*?(?=<\/script>)/i,
  41. lookbehind: true,
  42. alias: ['asp', 'script'],
  43. inside: Prism.languages.csharp || {}
  44. }
  45. });