General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion Tip: Faster spell checking by skipping certain elements

  • dcramer

    Tip: Faster spell checking by skipping certain elements

    Participants 3
    Replies 4
    Last Activity 13 years, 6 months ago

    I've long wanted the ability to skip over certain elements when spell checking a document. For example, most code listings are a waste of time or even dangerous to spell check.

    I just figured out how to accomplish this and it turns out to be pretty easy.

    1. Study the Journalist DTD and notice that a set of macros exists to toggle between five different structure view css style sheets (the function is switchSVStyles() in On_Macro_File_Load). Adapt this mechanism to your DTD but instead have it affect the main doc's css. You may choose to have a main css and then different css stylesheets that import the main one. That way you can switch to one of the small css files where you define overrides that are special and keep most of your rules in the main css.

    2. Define rules in your “override” css files to hide elements you don't want to spell check using display: none. For example:
    programlisting, filename, code { display: none; }

    3. Now when you want to spell check, run the macro that swtiches css files to the one you want. Run the spell checker and any content with display: none is not spell checked.

    You could also add a spellcheck attribute (or abuse an existing attribute) to create overrides. Say there are certain code listing elements you do want to spell check even though you want to skip most: add spellcheck=”yes” to those that you do want to spell check and write you css rules to elements with spellcheck=”yes” show while the unwanted ones are hidden.

    My one wish is that the method for changing css stylesheets were less crude. The Journalist example involves having XMetaL change the file name of the css! I have to assume that this macro breaks in an environment where the user does not have permission to write to the directory where the css lives.

    Does anybody know of a more graceful way to switch css stylesheets with a macro?


    Derek Read

    Reply to: Tip: Faster spell checking by skipping certain elements

    There is a more graceful way coming in a future release (I expect it to be officially documented at some point in the Programmers Guide). An API will allow you to add arbitrary CSS as a string, essentially the equivalent of tacking a CSS @import statement onto the end of your files. This willl let you override other settings (standard CSS cascade rules should apply). Until then you have the best solution possible.

    Concern about writing to the file system is valid however, regardless of what you are doing (as with your current solution) and XMetaL customizations that require manipulating files on the user's machine should take this into account (part of the reason for the API previously mentioned is because it will give you one less thing to worry about during deployment of customization files if you can simply pass strings of CSS in via script).

    You've hit on another topic here though. We plan to implement various features for spell checking and one of those includes support for xml:lang. Given that support, it should then be possible (provided your DTD defines that attribute) to set xml:lang=”zxx” for an element to have our spell checker skip over it.



    Reply to: Tip: Faster spell checking by skipping certain elements

    Interesting. Will you be able to skip over content based on other attributes? One use case I can't quite pull off with the css trick is to spell check only content that has revisionflag=”added” or revisionflag=”changed”. The idea is that as I edit the doc for the next release, I'll add revisionflag attrs any time I add or change (and in some cases delete, but no need to spell check that; the revisionflag attrs could be added pro grammatically too with a smart enough xml diff tool). Those revisionflag attrs are used to make changebars appear in the output so reviewers know where to focus their attention. I'd also like to spell check only that content that has revisionflag attrs.

    In addition, it would be nice if your language-aware spell checker could skip programlistings, code, filename and other elements of my choosing.

    However, this would all be beside the point if you move to a spell checker that shows red underlines as you type. Having that spell checker be aware of what language it's spell checking based on xml:lang would be nifty too.



    Derek Read

    Reply to: Tip: Faster spell checking by skipping certain elements

    We're open to extending the feature over time but I can't say if we'll have time to implement what you're suggesting for arbitrary attributes (sounds like DocBook attrs in your case). Most likely we're going to concentrate on xml:lang for now.

    We're also looking at implementing a “squiggly line” feature for spell checking and that is likely to be completed in time for our upcoming release as well, though again, no guarantees as I'm not directly involved.


    Derek Read

    Reply to: Tip: Faster spell checking by skipping certain elements

    Just in case anyone finds this old post (378) and is wondering about the status…

    …the functionality discussed here was implemented for the 6.0 release and is discussed in the following post:,539.0.html


  • You must be logged in to reply to this topic.

Lost Your Password?