novelWriter icon indicating copy to clipboard operation
novelWriter copied to clipboard

A warning in the build tool when an undefined auto-replace key was found in the manuscript

Open paulkater opened this issue 9 months ago • 2 comments

It would be an interesting addition for me to have the output generator (F5, preview, build tool) check for "undefined" auto-replace codes and report them somehow.

I love those replace codes, but once I found that a replacement code "Sa" slipped into a document which should have been a "sa". (Yes, I'm lazy when it comes to typing long or complicated words in fantasy stories.) As auto-replace is case sensitive, this typo wasn't replaced and made it into a manuscript. I stumbled upon it by accident, luckily before publishing.

To prevent this from happening I added all versions of the original key (SA,sa,Sa,sA) to the auto-replace section, to go around this problem.

As to the solution, I like your suggestion:

"Add a strict mode setting that will alert you in the Build tool if there are any such fields that were not replaced. In the event you need text that is on the same form as such a replace key, it must be escaped. The alert would only be a warning though, and not block you from building the manuscript."

I considered your other suggestion:

"Make the syntax highlighter check that the replace key is defined, and only add the highlight colour if it is"

which is great but not precisely for me because the highlight colour isn't always visible to me: I'm colour blind. Depending on the display/monitor I can see it (or not). A workable option for this could be if this highlight colour is configurable in the settings. E.g. the blue text between opening and closing quotes is perfect. Red, which most people would opt for, is a total no-no for me. An alternate optical indicator in the editor would be to remove the < and > marks from around the auto-replace code unless they're escaped. I thought I'd throw that in. ;-)

paulkater avatar Mar 22 '25 15:03 paulkater

Related discussion: #2269

My suggestion from the discussion:

I'm reluctant to make them case insensitive because the feature was originally designed for replacing character names. It was in fact the first feature request novelWriter had. The use case was a German novel with Japanese characters and references written in Japanese, and the person requesting it moved from LaTeX where he used custom commands for the names.

In any case, I have some proposals that may help with this issue:

  1. Make the syntax highlighter check that the replace key is defined, and only add the highlight colour if it is.
  2. Add a strict mode setting that will alert you in the Build tool if there are any such fields that were not replaced. In the event you need text that is on the same form as such a replace key, it must be escaped. The alert would only be a warning though, and not block you from building the manuscript.

A long term plan is to add analysis to the build preview and editor. Adding options to check for possible formatting errors is among the ideas. See #1345 and #712.

I also plan to extend the auto-complete feature over time (it now only applies to tags) and could also add it for auto-replace keys.

vkbo avatar Mar 22 '25 16:03 vkbo

My two proposed solutions are not mutually exclusive, so I will consider both.

I think it makes most sense to add the auto-replace settings in the Project Settings tab where the keys are defined. Adding a case-insensitive switch is also possible. The auto-replace is implemented using regex anyway, which has an IGNORECASE setting.

vkbo avatar Mar 22 '25 16:03 vkbo