mirror of
https://github.com/heyman/heynote.git
synced 2025-02-16 18:21:02 +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)
|
const content = state.sliceDoc(block.content.from, block.content.to)
|
||||||
|
|
||||||
//console.log("prettier supports:", getSupportInfo())
|
//console.log("prettier supports:", getSupportInfo())
|
||||||
const formattedContent = formatWithCursor(content, {
|
|
||||||
cursorOffset: cursorPos - block.content.from,
|
let formattedContent
|
||||||
parser: PARSER_MAP[langName].parser,
|
try {
|
||||||
plugins: PARSER_MAP[langName].plugins,
|
formattedContent = formatWithCursor(content, {
|
||||||
tabWidth: state.tabSize,
|
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({
|
dispatch(state.update({
|
||||||
changes: {
|
changes: {
|
||||||
|
Loading…
Reference in New Issue
Block a user