Closed lb42 closed 4 years ago
Hang on, I've now found the proper tutorial in which I read:
"We can do that by adding some behaviors. In your index.html, add the following after between the first and second lines of the code in the <script></script>
tags:"
so I now have an HTML file which looks like this:
<script >
let behaviors = {
"tei": {
"distributor": [
["[ref]", ["<a href=\"$rw@ref\" target=\"_blank\">","</a>"]]
]
}
};
var ceteicean = new CETEI();
ceteicean.shadowCSS = "../../css/cetei.css";
ceteicean.addBehaviors(behaviors);
ceteicean.getHTML5("https://raw.githubusercontent.com/COST-ELTeC/ELTeC-eng/master/level1/ENG18410_Sinclair.xml",
function(data) {
document.getElementsByTagName("body")[0].appendChild(data);});
</script>
which I am hoping will cause <distributor ref="http://whatever">wibble</distributor>
to get formatted as if it read <a href='http://whatever">wibble</a>
... but it doesn't.
Am I on the right track though?
I actually added that bit in response to your perfectly reasonable request this morning! So that's why you couldn't find it before. You are mostly on the right track. I tried plugging in your example and you might be running into the same issue I hit, namely that elements with un-registered namespaces cause an error. That's a bug, which I plan to fix. You can avoid it by registering the namespace thus:
let behaviors = {
"namespaces": {
"el": "http://distantreading.net/eltec/ns"
},
"tei": { ... }
}
You may want to update the version of CETEIcean you're using to a recent release (I'm going to try to do a new one today). You can lose the .shadowCSS
bit, as we gave up using Shadow DOM (sadly, not as useful as it sounds). I'm happy to help troubleshoot your code if you want. The distributor behavior itself looks correct to me, so something else may be getting in the way.
I added the namespaces thing but it still don't seem to work. I'll try updating my CETEICEAN version tomorrow. Thanks for the troubleshooting offer ! I'll take you up on that if updating fails. How can you tell there's an error btw? I am not getting any diagnostics (but maybe that's because I am just opening the HTML file from firefox instead of via a webserver)
Just to confirm I am still having problems with the latest release. I don't understand why the teiHeader is (apparently) not being processed at all (it was in the older releases) ... I found the line in the tutorial which tells me to add a "teiHeader":null, to my tei behaviors, but the header is still not being displayed.
Hiding the teiHeader is the default, erm, behavior. You can override that either with a new behavior for the header, or by using the removeBehavior(nsPrefix, elementName)
method.
I supplied a null behaviour for the header, as recommended in the tutorial, and that worked. It might be better to suggest using removeBehavior in the documentation since adding a null behaviour to make something appear is sort of counterintuitive... but I'm closing this ticket anyway, with thanks for your patient helpfulness!
For the JS-challenged, could you perhaps add a complete example to the wiki pages about behaviors? I added some stuff into the existing "behaviors.js" file, but I can't see where this file gets included or actioned. Do I have to recompile my CETEI.js file?