Skip to content

Commit a21873a

Browse files
author
Xavier Leune
committed
Show markdown preview when editing a note
1 parent 5bf354c commit a21873a

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ A Simplenote [React](https://reactjs.org/) client packaged in [Electron](https:/
1414
6. For all logging from Electron to be printed to the terminal (e.g. `console.log` statements within `app.js`), you might need to set `env ELECTRON_ENABLE_LOGGING=1`.
1515
7. Sign up for a new account within the app. Use the account for **testing purposes only** as all note data will be periodically cleared out on the server.
1616

17-
_Note: Simplenote API features such as sharing and publishing will not work with development builds. Due to a limitation of `make` installation paths used for build cannot have spaces._
17+
_Note: Simplenote API features such as sharing and publishing will not work with development builds. Due to a limitation of `make` installation paths used for build cannot have spaces. You also need nodejs 12 max to get this app built._
1818

1919
## Building
2020

lib/note-content-editor.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { searchNotes, tagsFromSearch } from './search';
1818
import actions from './state/actions';
1919
import * as selectors from './state/selectors';
2020
import { getTerms } from './utils/filter-notes';
21-
import { noteTitleAndPreview } from './utils/note-utils';
21+
import { noteTitleAndPreview, isMarkdown } from './utils/note-utils';
2222
import { isMac, isSafari } from './utils/platform';
2323
import {
2424
withCheckboxCharacters,
@@ -561,7 +561,19 @@ class NoteContentEditor extends Component<Props> {
561561
Editor.defineTheme('simplenote', {
562562
base: 'vs',
563563
inherit: true,
564-
rules: [{ background: 'FFFFFF', foreground: '#2c3338' }],
564+
rules: [
565+
{ background: 'FFFFFF', foreground: '#2c3338' },
566+
{ token: 'keyword.md', foreground: '#2c3338', fontStyle: 'bold' },
567+
{ token: 'variable.source' },
568+
{ token: 'string.md', background: '#fdf6e3', foreground: '#657b83' },
569+
{ token: 'comment.md', foreground: '#a7aaad' },
570+
{ token: 'keyword.table', foreground: '#a7aaad' },
571+
{
572+
token: 'keyword.table.header',
573+
foreground: '#2c3338',
574+
fontStyle: 'bold',
575+
},
576+
],
565577
colors: {
566578
'editor.foreground': '#2c3338', // $studio-gray-80 AKA theme-color-fg
567579
'editor.background': '#ffffff',
@@ -1162,7 +1174,7 @@ class NoteContentEditor extends Component<Props> {
11621174
};
11631175

11641176
render() {
1165-
const { lineLength, noteId, searchQuery, theme } = this.props;
1177+
const { lineLength, noteId, searchQuery, theme, note } = this.props;
11661178
const { content, editor, overTodo } = this.state;
11671179
const searchMatches = searchQuery ? this.searchMatches() : [];
11681180

@@ -1191,7 +1203,7 @@ class NoteContentEditor extends Component<Props> {
11911203
key={noteId}
11921204
editorDidMount={this.editorReady}
11931205
editorWillMount={this.editorInit}
1194-
language="plaintext"
1206+
language={isMarkdown(note) ? 'markdown' : 'plaintext'}
11951207
theme={theme === 'dark' ? 'simplenote-dark' : 'simplenote'}
11961208
onChange={this.updateNote}
11971209
options={{
@@ -1210,7 +1222,7 @@ class NoteContentEditor extends Component<Props> {
12101222
lineHeight: 24,
12111223
lineNumbers: 'off',
12121224
links: true,
1213-
matchBrackets: 'never',
1225+
matchBrackets: isMarkdown(note) ? 'always' : 'never',
12141226
minimap: { enabled: false },
12151227
occurrencesHighlight: false,
12161228
overviewRulerBorder: false,

lib/utils/note-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export const noteTitleAndPreview = (
146146
return result;
147147
};
148148

149-
function isMarkdown(note: T.Note): boolean {
149+
export function isMarkdown(note: T.Note): boolean {
150150
return note.systemTags.includes('markdown');
151151
}
152152

0 commit comments

Comments
 (0)