From 1d59d89588a9b328b81d19714e7b410bc7cef8c8 Mon Sep 17 00:00:00 2001 From: nathan-castlehow Date: Wed, 3 Jul 2019 09:28:36 +0800 Subject: [PATCH] feat(prettierOnMarkdown): Forced prettier options to always have parser set to markdown when used. --- browser/components/CodeEditor.js | 8 ++++++-- browser/main/lib/ConfigManager.js | 3 +-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/browser/components/CodeEditor.js b/browser/components/CodeEditor.js index ed24c671..8421b520 100644 --- a/browser/components/CodeEditor.js +++ b/browser/components/CodeEditor.js @@ -236,11 +236,15 @@ export default class CodeEditor extends React.Component { [translateHotkey(hotkey.prettifyMarkdown)]: cm => { // Default / User configured prettier options const currentConfig = JSON.parse(self.props.prettierConfig) - // Get current cursor position. + + // Parser type will always need to be markdown so we override the option before use + currentConfig.parser = 'markdown' + + // Get current cursor position const cursorPos = cm.getCursor() currentConfig.cursorOffset = cm.doc.indexFromPos(cursorPos) - // Prettify contents of editor. + // Prettify contents of editor const formattedTextDetails = prettier.formatWithCursor(cm.doc.getValue(), currentConfig) const formattedText = formattedTextDetails.formatted diff --git a/browser/main/lib/ConfigManager.js b/browser/main/lib/ConfigManager.js index f2d6d85a..d4c73b4a 100644 --- a/browser/main/lib/ConfigManager.js +++ b/browser/main/lib/ConfigManager.js @@ -71,8 +71,7 @@ export const DEFAULT_CONFIG = { "trailingComma": "es5", "tabWidth": 4, "semi": false, - "singleQuote": true, - "parser":"markdown" + "singleQuote": true }` },