Spreadsheet language support for CodeMirror
npm install codemirror-lang-spreadsheet
npm install codemirror-lang-spreadsheet
`
Usage
First import as shown below:
`
import {spreadsheet} from "codemirror-lang-spreadsheet";
`
Call the spreadsheet function inside the editor instance. This function expects an options object as an argument. Available options are idiom(string with desired language, eg "en-US") and decimalSeparator (string with decimal separator: "." or ";")
`
new EditorView({
extensions: [
// ... your other CodeMirror extensions
// ...
spreadsheet({
idiom: "en-US"
decimalSeparator: "."
})
],
parent: document.getElementById("editor")
});
`
๐ For a complete demo with highlighting, autocomplete and prettier go to: codemirror-app-spreadsheet
Supported idioms ๐ฃ๏ธ
Idioms are used for keywords like booleans (TRUE, FALSE) and error tokens (like #REF!, #NAME!, ...).
Currently supported:
- en-US
- pt-BR
It's pretty simple to add support for other idioms. See the contribution section.
Contribution
Contributions are welcome, but for every feature added, tests must be added.
To build:
`
npm run build
`
Running the tests:
`
npm run test
`
$3
To add support for a new idiom follow the steps below:
In the tokens.ts file, add the idiom as a new supported type:
`
TsupportedIdioms = 'en-US' | 'pt-BR';
`
Still in this file, for each of the i18n object keys, add a value with the respective idiom translation. There is no fallback to a default idiom, so even if a token is the same in another idiom, it has to be repeated.
`
const i18n = {
BoolToken: {
'en-US': ['TRUE', 'FALSE'],
'pt-BR': ['VERDADEIRO', 'FALSO']
},
RefErrorToken: { // repeated token
'en-US': '#REF!',
'pt-BR': '#REF!'
},
//...
}
`
Now it is necessary to create tests. Create a new folder named after the idiom inside the test/i18n folder. Copy the boolean.txt and errors.txt` files from another idiom and adapt them to the new idiom.