mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-21 09:38:01 +02:00
This commit is contained in:
parent
de03679be0
commit
2e3783f1c6
@ -588,6 +588,9 @@ packages/editor/CodeMirror/editorCommands/insertLineAfter.js
|
||||
packages/editor/CodeMirror/editorCommands/supportsCommand.js
|
||||
packages/editor/CodeMirror/editorCommands/swapLine.js
|
||||
packages/editor/CodeMirror/getScrollFraction.js
|
||||
packages/editor/CodeMirror/markdown/codeBlockLanguages/allLanguages.js
|
||||
packages/editor/CodeMirror/markdown/codeBlockLanguages/defaultLanguage.js
|
||||
packages/editor/CodeMirror/markdown/codeBlockLanguages/lookUpLanguage.js
|
||||
packages/editor/CodeMirror/markdown/computeSelectionFormatting.test.js
|
||||
packages/editor/CodeMirror/markdown/computeSelectionFormatting.js
|
||||
packages/editor/CodeMirror/markdown/decoratorExtension.test.js
|
||||
@ -600,7 +603,6 @@ packages/editor/CodeMirror/markdown/markdownMathParser.test.js
|
||||
packages/editor/CodeMirror/markdown/markdownMathParser.js
|
||||
packages/editor/CodeMirror/markdown/markdownReformatter.test.js
|
||||
packages/editor/CodeMirror/markdown/markdownReformatter.js
|
||||
packages/editor/CodeMirror/markdown/syntaxHighlightingLanguages.js
|
||||
packages/editor/CodeMirror/pluginApi/PluginLoader.js
|
||||
packages/editor/CodeMirror/pluginApi/codeMirrorRequire.js
|
||||
packages/editor/CodeMirror/testUtil/createEditorSettings.js
|
||||
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -568,6 +568,9 @@ packages/editor/CodeMirror/editorCommands/insertLineAfter.js
|
||||
packages/editor/CodeMirror/editorCommands/supportsCommand.js
|
||||
packages/editor/CodeMirror/editorCommands/swapLine.js
|
||||
packages/editor/CodeMirror/getScrollFraction.js
|
||||
packages/editor/CodeMirror/markdown/codeBlockLanguages/allLanguages.js
|
||||
packages/editor/CodeMirror/markdown/codeBlockLanguages/defaultLanguage.js
|
||||
packages/editor/CodeMirror/markdown/codeBlockLanguages/lookUpLanguage.js
|
||||
packages/editor/CodeMirror/markdown/computeSelectionFormatting.test.js
|
||||
packages/editor/CodeMirror/markdown/computeSelectionFormatting.js
|
||||
packages/editor/CodeMirror/markdown/decoratorExtension.test.js
|
||||
@ -580,7 +583,6 @@ packages/editor/CodeMirror/markdown/markdownMathParser.test.js
|
||||
packages/editor/CodeMirror/markdown/markdownMathParser.js
|
||||
packages/editor/CodeMirror/markdown/markdownReformatter.test.js
|
||||
packages/editor/CodeMirror/markdown/markdownReformatter.js
|
||||
packages/editor/CodeMirror/markdown/syntaxHighlightingLanguages.js
|
||||
packages/editor/CodeMirror/pluginApi/PluginLoader.js
|
||||
packages/editor/CodeMirror/pluginApi/codeMirrorRequire.js
|
||||
packages/editor/CodeMirror/testUtil/createEditorSettings.js
|
||||
|
@ -6,7 +6,7 @@ import { EditorState } from '@codemirror/state';
|
||||
import { markdown, markdownLanguage } from '@codemirror/lang-markdown';
|
||||
import { GFM as GitHubFlavoredMarkdownExtension } from '@lezer/markdown';
|
||||
import { MarkdownMathExtension } from './markdown/markdownMathParser';
|
||||
import syntaxHighlightingLanguages from './markdown/syntaxHighlightingLanguages';
|
||||
import lookUpLanguage from './markdown/codeBlockLanguages/lookUpLanguage';
|
||||
import { html } from '@codemirror/lang-html';
|
||||
import { defaultKeymap, emacsStyleKeymap } from '@codemirror/commands';
|
||||
import { vim } from '@replit/codemirror-vim';
|
||||
@ -26,7 +26,7 @@ const configFromSettings = (settings: EditorSettings) => {
|
||||
// Don't highlight KaTeX if the user disabled it
|
||||
settings.katexEnabled ? MarkdownMathExtension : [],
|
||||
],
|
||||
codeLanguages: syntaxHighlightingLanguages,
|
||||
codeLanguages: lookUpLanguage,
|
||||
}),
|
||||
markdownLanguage.data.of({ closeBrackets: openingBrackets }),
|
||||
];
|
||||
|
@ -1,7 +1,3 @@
|
||||
//
|
||||
// Exports a list of languages that can be used in fenced code blocks.
|
||||
//
|
||||
|
||||
import { LanguageDescription } from '@codemirror/language';
|
||||
import { languages } from '@codemirror/language-data';
|
||||
|
||||
@ -13,13 +9,13 @@ const additionalAliases: Record<string, string[]> = {
|
||||
|
||||
// Convert supportedLanguages to a CodeMirror-readable list
|
||||
// of LanguageDescriptions
|
||||
const syntaxHighlightingLanguages: LanguageDescription[] = [];
|
||||
export const allLanguages: LanguageDescription[] = [];
|
||||
|
||||
for (const language of languages) {
|
||||
const languageId = language.name.toLowerCase();
|
||||
|
||||
if (additionalAliases.hasOwnProperty(languageId)) {
|
||||
syntaxHighlightingLanguages.push(LanguageDescription.of({
|
||||
allLanguages.push(LanguageDescription.of({
|
||||
name: language.name,
|
||||
alias: [...language.alias, ...additionalAliases[languageId]],
|
||||
extensions: language.extensions,
|
||||
@ -28,8 +24,8 @@ for (const language of languages) {
|
||||
load: () => language.load.call(language),
|
||||
}));
|
||||
} else {
|
||||
syntaxHighlightingLanguages.push(language);
|
||||
allLanguages.push(language);
|
||||
}
|
||||
}
|
||||
|
||||
export default syntaxHighlightingLanguages;
|
||||
export default allLanguages;
|
@ -0,0 +1,18 @@
|
||||
import { LanguageDescription, LanguageSupport, StreamLanguage } from '@codemirror/language';
|
||||
|
||||
// To allow auto-indent to work in an unrecognised language, we define an
|
||||
// empty language. Doing so seems to enable auto-indent in code blocks with
|
||||
// that language.
|
||||
const defaultLangauge = StreamLanguage.define({
|
||||
token: (stream) => {
|
||||
stream.next();
|
||||
return null;
|
||||
},
|
||||
});
|
||||
|
||||
const defaultLanguageDescription = LanguageDescription.of({
|
||||
name: 'default',
|
||||
support: new LanguageSupport(defaultLangauge),
|
||||
});
|
||||
|
||||
export default defaultLanguageDescription;
|
@ -0,0 +1,10 @@
|
||||
import { LanguageDescription } from '@codemirror/language';
|
||||
import { languages } from '@codemirror/language-data';
|
||||
import defaultLanguage from './defaultLanguage';
|
||||
|
||||
// Intended for use by the `markdown({ ... })` extension.
|
||||
const lookUpLanguage = (languageInfo: string) => {
|
||||
return LanguageDescription.matchLanguageName(languages, languageInfo) ?? defaultLanguage;
|
||||
};
|
||||
|
||||
export default lookUpLanguage;
|
@ -1,10 +1,8 @@
|
||||
import syntaxHighlightingLanguages from '../markdown/syntaxHighlightingLanguages';
|
||||
import allLanguages from '../markdown/codeBlockLanguages/allLanguages';
|
||||
|
||||
// Ensure languages we use are loaded. Without this, tests may randomly fail (LanguageDescriptions
|
||||
// are loaded asyncronously, in the background).
|
||||
const loadLangauges = async () => {
|
||||
const allLanguages = syntaxHighlightingLanguages;
|
||||
|
||||
for (const lang of allLanguages) {
|
||||
await lang.load();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user