pourmand1376 / obsidian-custom-font

A plugin to set custom font for obsidian
https://obsidian.md/plugins?id=custom-font-loader
Apache License 2.0
49 stars 1 forks source link

update force mode #6

Closed LukasLow closed 7 months ago

LukasLow commented 7 months ago

view in https://github.com/pourmand1376/obsidian-custom-font/issues/5

LukasLow commented 7 months ago

ok now with theme the text would not update :(

pourmand1376 commented 7 months ago

Hi, Thanks for contributing.

Could you please explain Why this PR is necessary and What it does?

Honestly, It is unclear from the code what you wanted to do. I suppose your problem would be solved by just disabling Force Mode. Am I wrong?

Do you want to disable Force Mode when custom CSS is applied?

LukasLow commented 7 months ago

Hi Amir,

Let me clarify the purpose and functionality of the changes made in this pull request (PR).

The primary goal of these changes is to refine the way force_mode applies font settings, ensuring it's both effective and less intrusive. This is achieved by providing more nuanced control over font styling, particularly under force_mode conditions.

Refinement of force_mode Application:

Original Approach: Previously, force_mode applied the font-family property globally to all elements using the * selector, which was quite aggressive and led to overriding all other and custom CSS font-family rules. New Approach: The introduction of the addImportantToCSS() function ensures that force_mode is applied more selectively. This function adds !important to each individual CSS rule, as opposed to applying it globally. This method ensures the precedence of force_mode settings without broadly overriding other styles, thus maintaining better control over the CSS styling. Enhancements to get_default_css Function:

Original Functionality: The function was initially setting various CSS custom properties related to fonts. Enhancements Made: The modified function now includes a direct application of the font-family property to div span elements, in addition to setting custom properties. This targeted approach reduces the likelihood of global overrides. Additionally, the function now adds more font-related custom properties, offering greater flexibility and customization options.

Addressing Your Query: The changes are not about disabling force_mode when custom CSS is applied. Instead, they aim to make force_mode more compatible with custom styling by ensuring it doesn't completely override user-defined styles. The idea is to enhance user experience by offering a more balanced approach between force_mode enforcement and custom CSS application. In essence, these changes improve the flexibility and usability of CSS styling functionality in our project, particularly in scenarios where force_mode is active. They allow for more precise control over font styling, ensuring that force_mode enhancements are applied effectively without disrupting the overall styling intentions.

I hope this explanation clarifies the intent and functionality of the changes proposed in this PR.

pourmand1376 commented 7 months ago

Sorry. AI generated answers don't help here. Please have some respect and provide the answer yourself.

LukasLow commented 7 months ago

I'm sorry mate, I just thought it would be more understandable because i trusted the ai to write better english and i tend to write very short. I am very sorry and thankfull you give a secound chance. and i hope the following you can unterstand very well

Could you please explain Why this PR is necessary and What it does? It is not necessary because now it works, but I have the issue that I use a theme and need to use force mode. In the code I saw, it extends the css string and added a "" with a "!important" that is essential overriding any custom css and everything in obsidian. now with the changes the default or custom css will be respectet in the forcemode because of no "" and the "!important" will be added to everyline of the default or custom css.

Honestly, It is unclear from the code what you wanted to do. I suppose your problem would be solved by just disabling Force Mode. Am I wrong? if I disable force mode the plugin would not work with a theme. I wanted a way, so math would not be disrupted from a "*" rule.

Do you want to disable Force Mode when custom CSS is applied? no, now everything except math should be in the scope of the changes from force mode and force mode don't override custom css

pourmand1376 commented 7 months ago

Hmm, Now I understand. Still, I think there is no need to change the code.

For your problem to solve, first disable Force Mode.

Then use custom CSS style and write something like this:

div, span, h1, h2, h3, h4, h5, h6, p, a, code {
    font-family: YourFontFamilyName;
        --font-default: YourFontFamilyName;
        --default-font: YourFontFamilyName;
        --font-family-editor: YourFontFamilyName;
        --font-monospace-default: YourFontFamilyName,
        --font-interface-override: YourFontFamilyName,
        --font-text-override: YourFontFamilyName,
        --font-monospace-override: YourFontFamilyName,  
        --font-family-strong: YourFontFamilyName,   
        --font-text-theme: YourFontFamilyName,  
        --font-family-tag: YourFontFamilyName,  
    }

It will do the work for you.

I can not merge this PR since it lacks compatibility with previous versions. There may be some people who need to apply some font to their math style and this breaks previous functionality.

LukasLow commented 7 months ago

thank you, this works : ) but for ease of use (changing font) i would like to keep the changes in the code, I hope you're cool with me changing my repo to a version that works with a git clone. I will not upload it to obsidians plugin list because it basically the same.

Btw: .otf files work with your plugin too and above i needed to change it to font-family: YourFontFamilyName !important;

pourmand1376 commented 7 months ago

Who am I to have problem with that? I have made the License Apache just to make sure that anyone can do any changes he/she wants and be happy with it.

LukasLow commented 7 months ago

Thx