/*
This file is part of LONCAPA-Daxe.
LONCAPA-Daxe is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
LONCAPA-Daxe is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Daxe. If not, see <http://www.gnu.org/licenses/>.
*/
part of loncapa_daxe;
class SimpleUIText {
static List<String> possibleDescendants = ['m','lm','chem','num','table','tr','td','ul','ol','li',
'a','span','p','b','i','sup','sub','section','img'];
/**
* Returns true if the given node only contains elements that can be displayed
* with simple UI as part of the text.
* Can throw a SimpleUIException.
*/
static bool checkNodeContents(DaxeNode node) {
for (DaxeNode dn=node.firstChild; dn!= null; dn=dn.nextSibling) {
if (!SimpleUIText.checkNode(dn)) {
if (dn.nodeName != null)
throw new SimpleUIException(LCDStrings.get('element_prevents') + ' ' + dn.nodeName);
return false;
}
}
return true;
}
/**
* Returns true if the given node can be displayed with simple UI as part of the text.
*/
static bool checkNode(DaxeNode node) {
if (node.nodeType == DaxeNode.TEXT_NODE)
return true;
if (!possibleDescendants.contains(node.nodeName)) {
String title = doc.cfg.elementTitle(node.ref);
throw new SimpleUIException(LCDStrings.get('element_prevents') + ' ' + node.nodeName +
(title != null ? " ($title)" : ''));
} if (node.attributes.length != 0) {
// In what case could attributes be a problem for HTML elements ?
return true;
}
return SimpleUIText.checkNodeContents(node);
}
}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>