1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-12 17:26:17 +00:00

feat(prettierOnMarkdown): Forced prettier options to always have parser set to markdown when used.

This commit is contained in:
nathan-castlehow
2019-07-03 09:28:36 +08:00
parent 911fd9a004
commit 1173631255
2 changed files with 7 additions and 4 deletions

View File

@@ -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

View File

@@ -71,8 +71,7 @@ export const DEFAULT_CONFIG = {
"trailingComma": "es5",
"tabWidth": 4,
"semi": false,
"singleQuote": true,
"parser":"markdown"
"singleQuote": true
}`
},