Skip to content

Commit

Permalink
Merge pull request #977 from ubyssey/smart-quote
Browse files Browse the repository at this point in the history
Smart quote
  • Loading branch information
davidkao0902 authored Jul 24, 2020
2 parents e9871a3 + 6a2e043 commit c482c7e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,33 +96,34 @@ class ContentEditor extends React.Component {
const { editorState } = this.state;
const selection = editorState.getSelection();
const content = editorState.getCurrentContent();
const style = editorState.getCurrentInlineStyle();
const currentIndex = selection.getEndOffset();
const currentBlock = editorState.getCurrentContent().getBlockForKey(selection.getStartKey()).getText().substring(0, currentIndex);

let contentReplaced = Modifier.insertText(content, selection, str);

if(currentBlock !== "") {
if(str === '\"' && currentBlock.lastIndexOf('“') <= currentBlock.lastIndexOf('”') && currentBlock[currentIndex-1].match(/[\s-]/g)) {
contentReplaced = Modifier.insertText(content, selection, '“');
contentReplaced = Modifier.insertText(content, selection, '“', style);
}
else if(str === '\"') {
contentReplaced = Modifier.insertText(content, selection, '”');
contentReplaced = Modifier.insertText(content, selection, '”', style);
}
else if(str === "\'" && currentBlock.lastIndexOf('‘') <= currentBlock.lastIndexOf('’') && currentBlock[currentIndex-1].match(/[\s-]/g)) {
contentReplaced = Modifier.insertText(content, selection, '‘');
contentReplaced = Modifier.insertText(content, selection, '‘', style);
}
else if(str === "\'") {
contentReplaced = Modifier.insertText(content, selection, );
contentReplaced = Modifier.insertText(content, selection, '’', style);
} else {
return false;
}
}
else {
if(str === "\'") {
contentReplaced = Modifier.insertText(content, selection, '‘');
contentReplaced = Modifier.insertText(content, selection, '‘', style);
}
else if (str === '\"'){
contentReplaced = Modifier.insertText(content, selection, '“');
contentReplaced = Modifier.insertText(content, selection, '“', style);
}
else {
return false;
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(name='dispatch',
description='A publishing platform for modern newspapers',
version='1.3.3',
version='1.3.4',
url='https://github.com/ubyssey/dispatch',
author='Peter Siemens',
author_email='[email protected]',
Expand Down

0 comments on commit c482c7e

Please sign in to comment.