mirror of
https://github.com/heyman/heynote.git
synced 2024-11-21 23:43:22 +01:00
Catch syntax errors when trying to format code
This commit is contained in:
parent
2c1e23c9f4
commit
03d0195eb3
@ -33,12 +33,20 @@ export const formatBlockContent = ({ state, dispatch }) => {
|
||||
const content = state.sliceDoc(block.content.from, block.content.to)
|
||||
|
||||
//console.log("prettier supports:", getSupportInfo())
|
||||
const formattedContent = formatWithCursor(content, {
|
||||
cursorOffset: cursorPos - block.content.from,
|
||||
parser: PARSER_MAP[langName].parser,
|
||||
plugins: PARSER_MAP[langName].plugins,
|
||||
tabWidth: state.tabSize,
|
||||
})
|
||||
|
||||
let formattedContent
|
||||
try {
|
||||
formattedContent = formatWithCursor(content, {
|
||||
cursorOffset: cursorPos - block.content.from,
|
||||
parser: PARSER_MAP[langName].parser,
|
||||
plugins: PARSER_MAP[langName].plugins,
|
||||
tabWidth: state.tabSize,
|
||||
})
|
||||
} catch (e) {
|
||||
const hyphens = "----------------------------------------------------------------------------"
|
||||
console.log(`Error when trying to format block:\n${hyphens}\n${e.message}\n${hyphens}`)
|
||||
return false
|
||||
}
|
||||
|
||||
dispatch(state.update({
|
||||
changes: {
|
||||
|
Loading…
Reference in New Issue
Block a user