Skip to content

Commit

Permalink
feat: added ability to globally turn off Admonition Color being set d…
Browse files Browse the repository at this point in the history
…irectly on element

feat: added ability to turn off Admonition Color per admonition type

if the admonition color is turned off, it must be set via CSS
  • Loading branch information
valentine195 committed Nov 1, 2021
1 parent 245fbe2 commit afbcc23
Show file tree
Hide file tree
Showing 8 changed files with 3,167 additions and 228 deletions.
3,109 changes: 2,973 additions & 136 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
"rollup:dev": "rollup --config rollup.config-dev.js -w",
"rollup:publish": "rollup --config rollup.publish.js -w",
"rollup:build": "rollup --config rollup.config.js",
"dev": "webpack --config webpack.dev.js -w",
"dev": "set NODE_OPTIONS=--openssl-legacy-provider && webpack --config webpack.dev.js -w",
"publish": "webpack --config webpack.publish.js",
"build": "npm run publish && webpack"
"build": "npm run publish && webpack",
"release": "standard-version"
},
"standard-version": {
"t": ""
},
"keywords": [],
"author": "Jeremy Valentine",
Expand Down Expand Up @@ -39,6 +43,7 @@
"webpack-cli": "^4.7.2"
},
"dependencies": {
"@fortawesome/free-brands-svg-icons": "^5.15.4"
"@fortawesome/free-brands-svg-icons": "^5.15.4",
"standard-version": "^9.3.2"
}
}
2 changes: 2 additions & 0 deletions src/@types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface Admonition {
icon: AdmonitionIconDefinition;
color: string;
command: boolean;
injectColor: boolean;
}

export interface INestedAdmonition {
Expand All @@ -27,6 +28,7 @@ export interface ISettingsData {
syncLinks: boolean;
version: string;
enableMarkdownProcessor: boolean;
injectColor: boolean;
}

export type AdmonitionIconDefinition = {
Expand Down
8 changes: 8 additions & 0 deletions src/assets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,14 @@ input.is-invalid {
width: 1em;
}

.admonition-color-settings .setting-item-control {
gap: 1rem;
}
.admonition-color-settings input[type="color"]:disabled {
opacity: 0.75;
cursor: not-allowed;
}

/** Internal */

.admonition li.task-list-item.is-checked p {
Expand Down
20 changes: 13 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ const DEFAULT_APP_SETTINGS: ISettingsData = {
autoCollapse: false,
defaultCollapseType: "open",
syncLinks: true,
enableMarkdownProcessor: false
enableMarkdownProcessor: false,
injectColor: true
};

export default class ObsidianAdmonition
Expand Down Expand Up @@ -395,12 +396,14 @@ export default class ObsidianAdmonition
"An admonition must have a title if it is collapsible."
);
}

const admonition = this.admonitions[type];
const admonitionElement = await getAdmonitionElementAsync(
type,
title.trim(),
this.admonitions[type].icon,
this.admonitions[type].color,
admonition.icon,
admonition.injectColor ?? this.data.injectColor
? admonition.color
: null,
collapse
);

Expand Down Expand Up @@ -664,13 +667,16 @@ title:
const id = getID();

/* const iconNode = icon ? this.admonitions[type].icon; */

const admonition = this.admonitions[type];
let admonitionElement = getAdmonitionElement(
type,
title,
iconDefinitions.find(({ name }) => icon === name) ??
this.admonitions[type].icon,
color ?? this.admonitions[type].color,
admonition.icon,
color ??
(admonition.injectColor ?? this.data.injectColor
? admonition.color
: null),
collapse,
id
);
Expand Down
15 changes: 11 additions & 4 deletions src/modal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,15 @@ export class InsertAdmonitionModal extends Modal {
this.noTitle = false;
}
if (this.element) {
const admonition = this.plugin.admonitions[this.type];
const element = getAdmonitionElement(
this.type,
this.title,
this.plugin.admonitions[this.type].icon,
this.plugin.admonitions[this.type].color,
admonition.icon,
admonition.injectColor ??
this.plugin.data.injectColor
? admonition.color
: null,
this.collapse
);
element.createDiv({
Expand Down Expand Up @@ -565,11 +569,14 @@ ${this.editor.getDoc().getSelection()}
buildAdmonition() {
this.admonitionEl.empty();
if (this.type && this.plugin.admonitions[this.type]) {
const admonition = this.plugin.admonitions[this.type];
this.element = getAdmonitionElement(
this.type,
this.title,
this.plugin.admonitions[this.type].icon,
this.plugin.admonitions[this.type].color,
admonition.icon,
admonition.injectColor ?? this.plugin.data.injectColor
? admonition.color
: null,
this.collapse
);
this.element.createDiv({
Expand Down
Loading

0 comments on commit afbcc23

Please sign in to comment.