forked from laurent22/joplin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mobile,Desktop: Fixes laurent22#9971: Fix auto-indentation in some ty…
…pes of code blocks
- Loading branch information
1 parent
5820f63
commit 41fa702
Showing
7 changed files
with
64 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
packages/editor/CodeMirror/markdown/codeBlockLanguages/defaultLanguage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { LanguageDescription, LanguageSupport, StreamLanguage } from '@codemirror/language'; | ||
|
||
// To allow auto-indent to work in an unrecognised language, we define a language | ||
// that provides just autoindent. | ||
const defaultLangauge = StreamLanguage.define({ | ||
startState: (indentUnit) => { | ||
return { | ||
indentUnit, | ||
lastIndent: 0, | ||
isLineStart: true, | ||
}; | ||
}, | ||
token: (stream, state) => { | ||
if (state.isLineStart) { | ||
const indent = stream.eat(/\s*/) || ''; | ||
state.lastIndent = indent.length; | ||
state.isLineStart = false; | ||
} else { | ||
const n = stream.next(); | ||
if (n === '\n') { | ||
state.isLineStart = true; | ||
} | ||
} | ||
return null; | ||
}, | ||
indent: (state) => { | ||
return state.lastIndent; | ||
}, | ||
}); | ||
|
||
const baseLanguageDescription = LanguageDescription.of({ | ||
name: 'default', | ||
support: new LanguageSupport(defaultLangauge), | ||
}); | ||
|
||
export default baseLanguageDescription; |
14 changes: 14 additions & 0 deletions
14
packages/editor/CodeMirror/markdown/codeBlockLanguages/lookUpLanguage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// Exports a list of languages that can be used in fenced code blocks. | ||
// | ||
|
||
import { LanguageDescription } from '@codemirror/language'; | ||
import { languages } from '@codemirror/language-data'; | ||
import defaultLanguage from './defaultLanguage'; | ||
|
||
|
||
const lookUpLanguage = (languageInfo: string) => { | ||
return LanguageDescription.matchLanguageName(languages, languageInfo) ?? defaultLanguage; | ||
}; | ||
|
||
export default lookUpLanguage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters