snezhig/obsidian-front-matter-title

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

redactedscribe opened this issue · 10 comments

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.

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

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.

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

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).

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.

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.

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: " *".)

So, what else we should discuss in this issue?

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!

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