Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style note's title when note has a title value set #179

Open
redactedscribe opened this issue Oct 8, 2023 · 10 comments
Open

Style note's title when note has a title value set #179

redactedscribe opened this issue Oct 8, 2023 · 10 comments

Comments

@redactedscribe
Copy link

I've got the processor feature set to replace the title with the title plus an asterisk (e.g. My note -> My note *). This just helps me see that the file is indeed displaying its title and not the original filename. This is because one of my uses for the title is to add emojis to make things more visual (✏️ My note *). The problem is that this processed title with the asterisk is also used for all link suggestions when the Suggest feature enabled, when I don't really want the asterisk in the Markdown document, only [[✏️ My note]].

If there was an option to style the title using regex but only for rendering purposes, not for anything that is inserted into a document's source, that would overcome the issue. Or maybe titles could be styled using CSS across Obsidian according to some basic options: Color, italic, bold, etc. Anything that would help identify that I'm looking at a title, not a filename. The problem with CSS is that if Obsidian's theme changes, maybe the title styling would not suit, hence my initial suggestion of only using regex.

Thanks.

@snezhig
Copy link
Owner

snezhig commented Nov 1, 2023

The main problem it that the Processor is applied to all features? Or I got it wrong?

@redactedscribe
Copy link
Author

redactedscribe commented Nov 1, 2023

You are correct. To rephrase the feature request simply: I want an option to be able to visually detect when a file is displaying a rewritten title.

@snezhig
Copy link
Owner

snezhig commented Nov 1, 2023

If processor was realized like a template with option to set it individually for each feature, would it solve your problem?

@redactedscribe
Copy link
Author

redactedscribe commented Nov 1, 2023

I don't understand, sorry. The goal is: If title: has a value, style inline titles and sidebar filenames in red, for example. It's only a visual adjustment which the plugin would control, nothing to do with Markdown formatting/style (or templates, I think).

@redactedscribe
Copy link
Author

redactedscribe commented Nov 4, 2023

After the release of v2.7.0's #182 icon: feature, I've changed my Common main template value from title to {{icon }}{{title|_basename}}. The problem now is that {{icon }}{{title|_basename}} is triggering the processor rewrite to run and so I cannot use my previous method of using the processor to indicate that the file is using a custom title:.

Processor pattern: (.+)
Processor replacement: $1 *

With title (or {title}}) an asterisk would only be appended to the title if title: had a value. But using {{icon }}{{title|_basename}} an asterisk is always appended so I cannot know if a file has title: set or not. The processor triggering when using {{icon }}{{title|_basename}} or similar may however be good or desirable in many or most cases.

Using my new Common main template value, I don't think this FR is possible any more. There would need to be a way to trigger styling only if title: has a value.

@snezhig
Copy link
Owner

snezhig commented Nov 4, 2023

You can try to use processor in Function mode with the template {{icon }}({{title}})({{_basename}}) and following code:

var {
    groups: {
        icon,
        t,
        basename
    },
} = title.match(new RegExp(`(?<icon>.*)\\((?<t>.*)\\)\\((?<basename>.*)\\)`));
console.log("icon = " + icon, "t = " + t, "bs = " + basename)
return `${icon}${t? t+ "*" : basename}`

Remove console after test. It just for debugging.

@redactedscribe
Copy link
Author

redactedscribe commented Nov 4, 2023

Console showed e.g. icon = 🙂 t = bs = Test. It works, thank you! Asterisks only shown if title: has a value.

(I had to add a space on the last line to be exactly what I wanted: " *".)

@snezhig
Copy link
Owner

snezhig commented Nov 7, 2023

So, what else we should discuss in this issue?

@redactedscribe
Copy link
Author

I am okay with simply adding an asterisk to the displayed titles via your useful function. It isn't however as straightforward as having an option: "Style titles when title: is set?" Yes > If colour is possible to add to titles in the UI, then allow user to set a colour. If not, maybe Bold/Italic is possible?

I don't know how useful others would find this, but I think it's useful being able to look at a note's UI title, without needing to inspect the frontmatter, to see that has been "renamed" via title:. Feel free to close the issue; we can end the discussion here until someone else chimes in.

Thank you for your help!

@snezhig
Copy link
Owner

snezhig commented Nov 8, 2023

I put this topic on pause for now and come back after solving other issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants