Why do you feel inline fields are less practical compared to a <span>
tag? When looking at this example:
You could either <span style="background: #fff88f">span html
tags</span>, or [highlight:: inline fields], or ==markdown
highlight== to highlight bits and pieces of text.
I feel that next to using ==
around the text, then using inline fields is a neater option. In the answer linked below I showcase how this could be done for multiple variants of highlights related to ideas, questions and explanation with the CSS snippet to make it work.
Where did you try to use that regexmatch() of yours? And does it really have the full content of the file available in file.text? I’ve got two variants which I would consider in a similar use case, and that would be decorated tasks, or inline fields. Both of these would with dataview be easy to gather up a list of at the top of the document without disturbing/rewriting the file itself. Using tasks In minimal theme, and quite a few others, you can insert various different status characters, and…
And here are some pros and cons for the various options:
- Using span html tags:
- Span allows for arbitrarily styling within the note itself
- Some don’t like that excessive markup to get that styling of spans
- You need to use regex searches, or javascript content reading scripts to extract the highlights
- Using
==highlight==
:- Included by default
- Can be styled, but there is just “one” type of styling across the vault by default
- Very unobtrusive in the text, but is still visible enough in source mode
- Using inline fields:
- Not very obtrusive in the text
- Allows for easy querying across files
- With multiple fields, you can several groups of highlights, if that’s a desire
- Requires a one time setup of the CSS for each group of highlight fields
- Using tasks (as discussed in other text):
- Is the only option which allows link back from the query result (except for when searching for span html tags)
- Do require the highlighted text to be one a line of its own
- Easy to query