Make semi random text bold

I have the following text in all of my tiddlers tagged with ‘Use’ :- ‘Total Quantity:’ followed by a number , 1 to 10000 and there may be a fraction e.g.10½
I want to make this text bold, what is the best method please?
I’ve tried this sort of thing with addprefix and addsuffix to place the ‘’ but no joy:-
{{{ [tag[luse]search:text:regexp[Total Quantity:]]}}}

making the following assumptions:

  • you have many many tiddlers that are formatted this way
  • they are being generated by some sort of template

i would recommend

  1. using the commander plugin by Mohammad to do a batch find-and replace of the text Total Quantity:, replacing it with ''Total Quantity:''. you may want to look through the results first to make sure it isn’t finding anything unexpected. filtering by tag is a good idea too so it only finds matches in tiddlers tagged luse.
  2. updating your template so when you make new entries they will be bold.

hope this helps

It’s not clear to me what you’re looking for:

  • Some method, perhaps in an editor button, to allow you to find all matching text in the current tiddler and change the markup to add bold markup around each one.

  • A tool that will do a one-time conversion across all the wiki, or those with the User tag, to add that markup.

  • Something that runs at rendering time so that your markup would not be changed at all, but when the tiddler is shown, any matching text will be shown bold.

Or are you picturing something else? I think all of these are achievable, but they would require different amounts of skill and of effort.

Hello Scott,
Sorry I was not clear enough.
I had tables in tiddlers with the tag “use”, that contained different parts in bold text, I wanted to standardise them so I used Commander to remove all the bold markup. Then I wanted to make the text “Total Quantity: 0 to 9999” i.e that string with a variable number after it, bold. So it’s a one off correction to all those tiddlers. I have tried wildcards in commander and regex but can’t get that to work. I’ve messed around with regex in search and replace but can’t get that right. I could do it manually but it’s a days work, so for now I have given up. I’m certain there must be an easy solution.
Hope you can help.
Peter

Suggestion

This might work:

\procedure quantities() ((?<!'')Total Quantity: *\d+ *[¼½¾\u2150-\u215E]?)
\function bold.quantities() [search-replace:gi:regexp<quantities>,[''$1'']]

In Commander, you would use it differently, but as simple wikitext, you might use it to convert the text of tiddler Sample like this:

<$wikify name="result" output="html" text={{{ [{Sample}bold.quantities[]] }}} >
<<result>>
</$wikify>

Regex Explanation

Our regular expression looks like:

      /((?<!'')Total Quantity: *\d+ *[¼½¾\u2150-\u215E]?)/gi
// [1] (                                                )
// [2]  (?<!'') 
// [3]         Total Quantity:
// [4]                        _*
// [5]                          \d+
// [6]                             _*
// [7]                               [¼½¾\u2150-\u215E]
// [8]                                                 ?
  1. the parentheses wrapper adds a group that captures the whole content for easy replacement.
  2. is a negative look-behind, ensuring that we don’t have '' behind our match. We don’t want to convert ones that already have a ''bold'' wrapper. I couldn’t think of a good way to do the matching negative look-ahead with the optional sections at the end of the regex. But I think that is fine for a one-time conversion.
  3. is the main text
  4. is an optional space before the number (with the _ in the note representing a space.)
  5. is the digits
  6. is another optional space (again with _ for the space.)
  7. is a character class for the Unicode fractions
  8. makes that fraction character optional

Assumption

  • This assumes your fraction is a single unicode character. If it is a /-separated pair of numbers, or a &frasl;-separated one, then the regex would need to change for that. If it could be either type, then the regex would grow a bit more complex.

  • It also assumes that you have no decimal points (since you mentioned fractions.) If you need to support them as well, it’s only a bit harder.

  • Finally, it assumes you can handle Commander for this. I have little experience with it. But, if you want to do it with a button, this (untested) code might be enough:

    <$button>Update 'Use' tiddlers
      <$list filter=[tag[Use]]>
        <$action-setfield $field="text" $value={{{ [<currentTiddler>get[text]bold.quantities[]] }}} />
      </$list>
    </$button>
    

    (assuming that Use is correct in the OP and it wasn’t just a typo for User.)

Demo

This is a quick demo of the technique. Download it and drag the resulting file onto any wiki:

BoldQuantities.json (930 Bytes)

Thank you Scott, it’s a well thought out answer which I can see works. I will get my head around it tonight and give it a go.