84 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-03-13 21:39:27 +01:00
import styles from './styles.scss';
/**
* Override the editor css
* @param {[type]} block [description]
* @return {[type]} [description]
*/
2018-03-13 13:12:06 +01:00
export function getBlockStyle(block) {
switch (block.getType()) {
case 'blockquote':
return styles.editorBlockquote;
case 'code-block':
return styles.editorCodeBlock;
default: return null;
}
}
export function getInnerText(style) {
let innerText;
switch (style) {
case 'BOLD':
2018-03-15 20:21:21 +01:00
innerText = '**bold text**';
2018-03-13 13:12:06 +01:00
break;
case 'ITALIC':
2018-03-15 20:21:21 +01:00
innerText = '*italic text*';
2018-03-13 13:12:06 +01:00
break;
case 'UNDERLINE':
2018-03-15 20:21:21 +01:00
innerText = '__underlined text__';
2018-03-13 13:12:06 +01:00
break;
case 'LINK':
innerText = '[text](link)';
break;
2018-03-20 12:12:02 +01:00
case 'STRIKED':
innerText = '~~striked out~~';
break;
2018-03-13 13:12:06 +01:00
default:
innerText = '';
}
return innerText;
}
2018-03-13 21:39:27 +01:00
export function getBlockContent(style) {
switch (style) {
case 'IMG':
return {
innerContent: 'link',
endReplacer: ')',
startReplacer: '![text](',
};
case 'code-block':
return {
innerContent: 'code block',
endReplacer: '`',
startReplacer: '`',
};
case 'blockquote':
return {
innerContent: 'quote',
endReplacer: '',
startReplacer: '> ',
};
default:
return {
innerContent: '',
endReplacer: '',
startReplacer: '',
};
}
}
2018-03-13 21:39:27 +01:00
/**
* Get the start and end offset
* @param {Object} selection
* @return {Object}
*/
export function getOffSets(selection) {
return {
end: selection.getEndOffset(),
start: selection.getStartOffset(),
};
}