Skip to content

Commit

Permalink
Changing default theme
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurankv committed Aug 20, 2023
1 parent f43b2f2 commit 2e9c497
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 56 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"env": {
"browser": true,
"node": true,
"es2021": true
},
"extends": [
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ See this project's [releases](/../../../releases).
### Added

- Added fold commands
- `run-*` implemented by the execute code plugin are treated as their original language with an update script to pull current values

### Changed

- Refactored editing view codeblock parsing to use callbacks in a loop function
- Can now update default themes

### Fixed

Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The plugin comes with a 'Default' theme and a few themes based on popular colour

All themes have customisable colours for both light and dark mode (to make changes to a specific mode, change to that mode first and then change the colours in settings). Each theme also includes other appearance settings such as displaying line numbers, allowing highlights to cover the line numbers and more.

When a setting or colour is changed within a theme, that change is not saved to the theme; you must then click the update button next to the theme name to update that theme to the current settings. Note that changes to the built-in themes cannot be saved.
When a setting or colour is changed within a theme, that change is not saved to the theme; you must then click the update button next to the theme name to update that theme to the current settings. Changes to the built-in themes can also be saved but to revert to the original themes, the plugin data will have to be reset.

The different component colours that can be set within a theme are:

Expand Down Expand Up @@ -70,8 +70,6 @@ The different component colours that can be set within a theme are:

![Solarized Default Dark Colours](images/SolarizedDefaultDarkColours.png)

I am not a designer, so if you have created a cool theme, send me the colour codes, and I might include it as a default theme in the next release :-\)

## Codeblock Parameters

Codeblock parameters are added to the first line of the codeblock following the language. They can be added in any order. If no language is set, a space should be left after the codeblock delimiter ` ``` ` to indicate that the first parameter is NOT the language of the codeblock.
Expand Down
32 changes: 16 additions & 16 deletions main.js

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
"update": "ncu -u && npm install && node manual-update.mjs",
"lint": "eslint --fix --max-warnings=0 src && stylelint --fix --max-warnings=0 src/styles.css src/css",
"version": "node version-bump.mjs",
"version": "node version-bump.mjs"
},
"keywords": [],
"author": "Mayuran Visakan",
"license": "MIT",
"devDependencies": {
"@types/node": "^20.5.0",
"@types/node": "^20.5.1",
"@typescript-eslint/eslint-plugin": "^6.4.0",
"@typescript-eslint/parser": "^6.4.0",
"builtin-modules": "3.3.0",
"esbuild": "0.19.2",
"eslint": "^8.47.0",
"eslint-plugin-json": "^3.1.0",
"obsidian": "latest",
"stylelint": "^15.10.2",
"stylelint": "^15.10.3",
"stylelint-config-idiomatic-order": "^9.0.0",
"stylelint-config-standard": "^34.0.0",
"stylelint-declaration-block-no-ignored-properties": "^2.7.0",
Expand All @@ -35,7 +35,7 @@
"stylelint-plugin-defensive-css": "^0.8.1",
"stylelint-stylistic": "^0.4.3",
"stylelint-use-logical-spec": "^5.0.0",
"tslib": "2.6.1",
"tslib": "2.6.2",
"typescript": "5.1.6"
},
"dependencies": {
Expand Down
3 changes: 2 additions & 1 deletion src/CodeblockParsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@ export async function pluginAdjustParameters(codeblockParameters: CodeblockParam
codeblockParameters.language = fileIncludeLanguage;
}
} else if (/run-\w*/.test(codeblockParameters.language)) {
console.log("foo");
if ("execute-code" in plugins) {
if (codeblockParameters.language.slice(4) in EXECUTE_CODE_SUPPORTED_LANGUAGES)
if (EXECUTE_CODE_SUPPORTED_LANGUAGES.includes(codeblockParameters.language.slice(4)))
codeblockParameters.language = codeblockParameters.language.slice(4);
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/EditingView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export function createCodeblockCodeMirrorExtensions(settings: CodeStylerSettings
if (excludedCodeblock)
return;
if (syntaxNode.type.name.includes("HyperMD-codeblock")) {
builder.add(syntaxNode.from,syntaxNode.from,Decoration.line({attributes: {style: `--line-number-gutter-width: ${lineNumberMargin?lineNumberMargin+"px":"calc(var(--line-number-gutter-min-width) - 12px)"}`, class: (this.settings.specialLanguages.some(regExp => new RegExp(regExp).test(codeblockParameters.language))||startLine||endLine?"code-styler-line":getLineClass(codeblockParameters,lineNumber,line.text).join(" "))+(["^$"].concat(this.settings.specialLanguages).some(regExp => new RegExp(regExp).test(codeblockParameters.language))?"":` language-${codeblockParameters.language}`)}}));
builder.add(syntaxNode.from,syntaxNode.from,Decoration.line({attributes: {style: `--line-number-gutter-width: ${lineNumberMargin?lineNumberMargin+"px":"calc(var(--line-number-gutter-min-width) - 12px)"}`, class: ((this.settings.specialLanguages.some(regExp => new RegExp(regExp).test(codeblockParameters.language))||startLine||endLine)?"code-styler-line":getLineClass(codeblockParameters,lineNumber,line.text).join(" "))+(["^$"].concat(this.settings.specialLanguages).some(regExp => new RegExp(regExp).test(codeblockParameters.language))?"":` language-${codeblockParameters.language}`)}}));
builder.add(syntaxNode.from,syntaxNode.from,Decoration.line({}));
builder.add(syntaxNode.from,syntaxNode.from,Decoration.widget({widget: new LineNumberWidget(lineNumber,codeblockParameters,maxLineNum,startLine||endLine)}));
lineNumber++;
Expand Down Expand Up @@ -277,6 +277,7 @@ export function createCodeblockCodeMirrorExtensions(settings: CodeStylerSettings
}
//NOSONAR
// let toHighlight: Array<{start: number, text: string, language: string}> = []; //NOTE: For future CM6 Compatibility
const sourceMode = editingViewIgnore(view.state);
for (const {from,to} of view.visibleRanges) {
syntaxTree(view.state).iterate({from: from, to: to,
enter: (syntaxNode)=>{
Expand Down Expand Up @@ -309,13 +310,15 @@ export function createCodeblockCodeMirrorExtensions(settings: CodeStylerSettings
if (!decorationValue.spec?.class)
decorated = true;
});
if (!decorated && !editingViewIgnore(view.state)) {
if (!decorated && !sourceMode) {
this.decorations = this.decorations.update({add: [{from: syntaxNode.from, to: syntaxNode.from + endOfParameters, value: Decoration.replace({})}]});
if (parameters?.title || (parameters?.icon && getLanguageIcon(parameters.language,languageIcons)))
this.decorations = this.decorations.update({add: [{from: syntaxNode.from, to: syntaxNode.from, value: Decoration.replace({widget: new OpenerWidget(parameters,languageIcons)})}]});
}
}
this.decorations = this.decorations.update({filterFrom: syntaxNode.from + (editingViewIgnore(view.state)?0:endOfParameters+1), filterTo: syntaxNode.to, filter: ()=>false});
this.decorations = this.decorations.update({filterFrom: syntaxNode.from + endOfParameters+1, filterTo: syntaxNode.to, filter: ()=>false});
if (sourceMode)
this.decorations = this.decorations.update({filterFrom: syntaxNode.from, filterTo: syntaxNode.from + endOfParameters, filter: (from: number, to: number, value: Decoration)=>"class" in value.spec}); // eslint-disable-line @typescript-eslint/no-unused-vars
if (!settings.currentTheme.settings.inline.syntaxHighlight)
return;
this.decorations = this.decorations.update({add: modeHighlight({start: syntaxNode.from + endOfParameters, text: text, language: parameters.language})});
Expand Down
16 changes: 8 additions & 8 deletions src/SettingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ export class SettingsTab extends PluginSettingTab {
button.setTooltip("Update theme");
button.setIcon("save");
button.onClick(() => {
if (this.plugin.settings.selectedTheme in DEFAULT_SETTINGS.themes)
new Notice("You cannot update the default themes"); //NOSONAR
else {
this.plugin.settings.themes[this.plugin.settings.selectedTheme] = structuredClone(this.plugin.settings.currentTheme);
this.updateAlternativeHighlights(alternativeHighlightsContainer);
new Notice(`${this.plugin.settings.selectedTheme} theme saved successfully!`); //NOSONAR
(async () => {await this.plugin.saveSettings();})();
}
// if (this.plugin.settings.selectedTheme in DEFAULT_SETTINGS.themes)
// new Notice("You cannot update the default themes"); //NOSONAR
// else {
this.plugin.settings.themes[this.plugin.settings.selectedTheme] = structuredClone(this.plugin.settings.currentTheme);
this.updateAlternativeHighlights(alternativeHighlightsContainer);
new Notice(`${this.plugin.settings.selectedTheme} theme saved successfully!`); //NOSONAR
(async () => {await this.plugin.saveSettings();})();
// }
});
})
.addExtraButton(button => {
Expand Down

0 comments on commit 2e9c497

Please sign in to comment.