Skip to content

Commit

Permalink
Support for subscript and superscript marks (#531)
Browse files Browse the repository at this point in the history
Co-authored-by: abeforgit <arnebertrand@gmail.com>
  • Loading branch information
elpoelma and abeforgit authored Jan 17, 2023
1 parent a1032b2 commit c361681
Show file tree
Hide file tree
Showing 14 changed files with 244 additions and 423 deletions.
6 changes: 6 additions & 0 deletions addon/components/plugins/subscript/button.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Rdfa::ToolbarIcon
@active={{this.isActive}}
@title={{t 'ember-rdfa-editor.subscript'}}
@icon='subscript'
{{on 'click' this.toggle}}
/>
20 changes: 20 additions & 0 deletions addon/components/plugins/subscript/button.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { action } from '@ember/object';
import Component from '@glimmer/component';
import { ProseController } from '@lblod/ember-rdfa-editor';

type Args = {
controller: ProseController;
};
export default class SubscriptButton extends Component<Args> {
get controller() {
return this.args.controller;
}
get isActive() {
return this.controller.isMarkActive(this.controller.schema.marks.subscript);
}

@action
toggle() {
this.controller.toggleMark('subscript');
}
}
6 changes: 6 additions & 0 deletions addon/components/plugins/superscript/button.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Rdfa::ToolbarIcon
@active={{this.isActive}}
@title={{t 'ember-rdfa-editor.superscript'}}
@icon='superscript'
{{on 'click' this.toggle}}
/>
22 changes: 22 additions & 0 deletions addon/components/plugins/superscript/button.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { action } from '@ember/object';
import Component from '@glimmer/component';
import { ProseController } from '@lblod/ember-rdfa-editor/core/prosemirror';

type Args = {
controller: ProseController;
};
export default class SuperscriptButton extends Component<Args> {
get controller() {
return this.args.controller;
}
get isActive() {
return this.controller.isMarkActive(
this.controller.schema.marks.superscript
);
}

@action
toggle() {
this.controller.toggleMark('superscript');
}
}
15 changes: 15 additions & 0 deletions addon/plugins/subscript/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { WidgetSpec } from '@lblod/ember-rdfa-editor/core/prosemirror';
import { MarkSpec } from 'prosemirror-model';

export const subscript: MarkSpec = {
excludes: 'subscript superscript',
parseDOM: [{ tag: 'sub' }],
toDOM() {
return ['sub', 0];
},
};

export const subscriptWidget: WidgetSpec = {
componentName: 'plugins/subscript/button',
desiredLocation: 'toolbarMiddle',
};
15 changes: 15 additions & 0 deletions addon/plugins/superscript/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { WidgetSpec } from '@lblod/ember-rdfa-editor/core/prosemirror';
import { MarkSpec } from 'prosemirror-model';

export const superscript: MarkSpec = {
excludes: 'superscript subscript',
parseDOM: [{ tag: 'sup' }],
toDOM() {
return ['sup', 0];
},
};

export const superscriptWidget: WidgetSpec = {
componentName: 'plugins/superscript/button',
desiredLocation: 'toolbarMiddle',
};
1 change: 1 addition & 0 deletions app/components/plugins/subscript/button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@lblod/ember-rdfa-editor/components/plugins/subscript/button';
1 change: 1 addition & 0 deletions app/components/plugins/superscript/button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@lblod/ember-rdfa-editor/components/plugins/superscript/button';
11 changes: 11 additions & 0 deletions app/styles/ember-rdfa-editor/_c-content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,16 @@ $say-editor-highlight-hover-color: var(--au-gray-200) !default;
display: inline-block;
}

sub {
vertical-align: sub;
font-size: smaller;
}

sup {
vertical-align: super;
font-size: smaller;
}

// Table styling
table th {
white-space: initial;
Expand Down Expand Up @@ -439,3 +449,4 @@ $say-editor-highlight-hover-color: var(--au-gray-200) !default;
font-weight: var(--au-medium);
}
}

Loading

0 comments on commit c361681

Please sign in to comment.