Home Forums General XMetaL Discussion Using xml:lang Values to Control Spell Checking Reply To: Using xml:lang Values to Control Spell Checking

Derek Read

Reply to: Using xml:lang Values to Control Spell Checking

The APIs are not documented in the Programmer's Guide (6.0) yet, but here's an example you can try with the Journalist demo.
It is still possible these APIs may change a little bit in the future (part of the reason we haven't documented them yet).

[code]// Disable Spell Checking for Certain Nodes
//********************************************************* function spellService() {
//create the spell checker service
} spellService.prototype.shouldSpellCheck = function(node) {
//spell check every node…
var spellCheck = 1; //…unless it triggers one of the following tests //node is an element
if (node.nodeType == 1) {
//element name = if (node.nodeName == “ProgramListing”) {
//do not spell check
spellCheck = 0;
} //node's parent's attribute called “Style” has a value equal to “Bullet”
if (node.parentNode.getAttribute(“Style”) == “Bullet”) {
//do not spell check
spellCheck = 0;
} return spellCheck;
} var spServ = new spellService(); ActiveDocument.SetSpellCheckerService(spServ);
[/code] Note that because the journalist.mcr already has an “On_Document_Open_Complete” event macro you will want to incorporate this into that same section of the MCR file. With that in place try the following XML file that uses the journalist.dtd:


spellchecked spellchecked spellcheckednotspellchecked spellchecked
spellchecked notspellchecked

[/code] This example is somewhat contrived because the Journalist demo only has an Id attribute for most elements that allow PCDATA. So, in this example a node that is directly inside an element with the attribute “Style” set to “Bullet” is skipped (ie: ), while child elements of that node are not skipped (they are spell checked). You will need to design your logic based on your own elements, attributes and their relationships of course. Hopefully you want to just skip entire elements, or have implemented something similar to xml:lang, as that should make the logic fairly straightforward. Ideally the amount of code in here should be kept to a minimum to make things run as fast as possible.