Skip to content

Commit

Permalink
feat: add underline mark
Browse files Browse the repository at this point in the history
  • Loading branch information
sibiraj-s committed Dec 25, 2020
1 parent db30617 commit 888573d
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions demo/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { CustomMenuComponent } from './components/custom-menu/custom-menu.compon
nodeViews,
menu: [
['bold', 'italic'],
['underline'],
['code', 'blockquote'],
['ordered_list', 'bullet_list'],
[{ heading: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] }],
Expand Down
1 change: 1 addition & 0 deletions src/lib/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import TextColor from './TextColor';
export const STRONG = new MarkToggle('strong');
export const EM = new MarkToggle('em');
export const CODE = new MarkToggle('code');
export const UNDERLINE = new MarkToggle('u');
export const BLOCKQUOTE = new BlockquoteToggle();
export const UL = new ListItemToggle(true);
export const OL = new ListItemToggle(false);
Expand Down
1 change: 1 addition & 0 deletions src/lib/editor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { schema } from './schema';
const DEFAULT_MENU: Toolbar = [
['bold', 'italic'],
['code', 'blockquote'],
['underline'],
['ordered_list', 'bullet_list'],
[{ heading: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] }],
['link', 'image'],
Expand Down
2 changes: 2 additions & 0 deletions src/lib/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import bold from './bold';
import italic from './italic';
import code from './code';
import underline from './underline';
import orderedList from './ordered_list';
import bulletList from './bullet_list';
import quote from './quote';
Expand All @@ -23,6 +24,7 @@ const icons = {
bold,
italic,
code,
underline,
ordered_list: orderedList,
bullet_list: bulletList,
blockquote: quote,
Expand Down
4 changes: 4 additions & 0 deletions src/lib/icons/underline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default `
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M12 17c3.31 0 6-2.69 6-6V3h-2.5v8c0 1.93-1.57 3.5-3.5 3.5S8.5 12.93 8.5 11V3H6v8c0 3.31 2.69 6 6 6zm-7 2v2h14v-2H5z"/>
`;
1 change: 1 addition & 0 deletions src/lib/modules/menu/MenuCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const SimpleCommands = new Map<string, SimpleCommand>();
SimpleCommands.set('bold', Commands.STRONG);
SimpleCommands.set('italic', Commands.EM);
SimpleCommands.set('code', Commands.CODE);
SimpleCommands.set('underline', Commands.UNDERLINE);
SimpleCommands.set('blockquote', Commands.BLOCKQUOTE);
SimpleCommands.set('bullet_list', Commands.UL);
SimpleCommands.set('ordered_list', Commands.OL);
Expand Down
1 change: 1 addition & 0 deletions src/lib/modules/menu/menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class MenuComponent implements OnDestroy {

simpleCommands = [
'bold', 'italic',
'underline',
'code', 'blockquote',
'ordered_list', 'bullet_list',
'align_left', 'align_center', 'align_right', 'align_justify'
Expand Down
13 changes: 13 additions & 0 deletions src/lib/schema/marks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ const code: MarkSpec = {
}
};

// :: MarkSpec An underline mark. Rendered as an `<u>` element.
// Has parse rules that also match `text-decoration: underline`.
const u: MarkSpec = {
parseDOM: [
{ tag: 'u' },
{ style: 'text-decoration=underline' }
],
toDOM(): DOMOutputSpec {
return ['u', 0];
}
};

const textColor: MarkSpec = {
attrs: {
color: {
Expand Down Expand Up @@ -123,6 +135,7 @@ const makrs = {
em,
strong,
code,
u,
text_color: textColor,
text_background_color: textBackgroundColor
};
Expand Down
1 change: 1 addition & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type TCR = { dom: HTMLElement, update: (state: EditorState) => void };
type TBHeading = Array<'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'>;
type TBItems = 'bold' | 'italic'
| 'code' | 'blockquote'
| 'underline'
| 'ordered_list' | 'bullet_list'
| 'link' | 'image'
| 'text_color' | 'background_color'
Expand Down

0 comments on commit 888573d

Please sign in to comment.