mml_highlighter.js 1.0 KB

1234567891011121314151617181920212223242526272829
  1. import { AbstractHighlighter } from './abstract_highlighter.js';
  2. export class MmlHighlighter extends AbstractHighlighter {
  3. constructor() {
  4. super();
  5. this.mactionName = 'maction';
  6. }
  7. highlightNode(node) {
  8. let style = node.getAttribute('style');
  9. style += ';background-color: ' + this.colorString().background;
  10. style += ';color: ' + this.colorString().foreground;
  11. node.setAttribute('style', style);
  12. return { node: node };
  13. }
  14. unhighlightNode(info) {
  15. let style = info.node.getAttribute('style');
  16. style = style.replace(';background-color: ' + this.colorString().background, '');
  17. style = style.replace(';color: ' + this.colorString().foreground, '');
  18. info.node.setAttribute('style', style);
  19. }
  20. colorString() {
  21. return this.color.rgba();
  22. }
  23. getMactionNodes(node) {
  24. return Array.from(node.getElementsByTagName(this.mactionName));
  25. }
  26. isMactionNode(node) {
  27. return node.tagName === this.mactionName;
  28. }
  29. }