1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
/** -*-C-*-ish
HTMLnesting.k Copyright (C) 2005 Chris Morris
This file is distributed under the terms of the GNU Lesser General
Public Licence. See COPYING for licence.
*/
module HTMLnesting;
import Builtins;
import Tuples;
import Dict;
// this module just defines some constants
globals {
ExistDict<String> isab;
ExistDict<String> cb;
ExistDict<String> cd;
ExistDict<String> cdo;
ExistDict<String> ae;
ExistDict<String> pe;
ExistDict<(String,String)> ne;
Bool inited;
}
public Void initNesting() {
if (inited) { return; }
inited = true;
isab = newExist(29,strHash);
for i in ["address","blockquote","div","h1","h2","h3","h4","h5","h6","hr","p","pre","ul","ol","dl","table","form","fieldset"] {
add(isab,i);
}
cb = newExist(29,strHash);
for i in ["address","blockquote","body","del","div","ins","li","td","th","fieldset","form"] {
add(cb,i);
}
cd = newExist(31,strHash);
for i in ["address","del","div","h1","h2","h3","h4","h5","h6","ins","pre","li","td","th","map","p","dt","dd","fieldset","label"] {
add(cd,i);
}
cdo = newExist(7,strHash);
for i in ["caption","legend","option","textarea"] {
add(cdo,i);
}
ae = newExist(11,strHash);
for i in ["br","hr","img","input","col","area"] {
add(ae,i);
}
pe = newExist(23,strHash);
for i in ["select","ul","ol","table","thead","tbody","tfoot","tr","dl","colgroup","optgroup","textarea","map"] {
add(pe,i);
}
ne = newExist(11);
for j in [("ul","li"),
("ol","li"),
("dl","dt"),
("dl","dd"),
("select","option"),
("select","optgroup"),
("optgroup","option")] {
add(ne,j);
}
}
public Bool isAlwaysBlock(String el) = exists(isab,el);
public Bool isBlock(String el) = (exists(isab,el) || el == "del" || el == "ins");
public Bool containsBlock(String el) = exists(cb,el);
// of course, all non-empty inline elements can too.
public Bool containsCData(String el) = exists(cd,el);
public Bool containsCDataOnly(String el) = exists(cdo,el);
public Bool alwaysEmpty(String el) = exists(ae,el);
public Bool pretendEmpty(String el) = exists(pe,el);
public Bool nestingExceptions((String,String) ex) = exists(ne,ex);
// table elements not listed because editing tables that way could get messy.
public [String] isAlwaysEmpty = keys(ae);
public ExistDict<String> getAlwaysEmpty = ae;
|