Re: BXE and DocBook - it works!

Christian Stocker <[email protected]> Thu, 09 Feb 2006 15:24:33 +0100
Newsgroups gmane.editors.bitflux.devel
Organization Bitflux GmbH
Message-ID <[email protected]>
Hi S=F6ren

Many thanks for your work, just one plea before I digg into all those
changes. Could you please provide an unified diff of your changes? That
way, it's much much less work for me to patch it.

Just do an

svn diff > bxe.patches

(or similar) and send those file to the list. If you're using windows,
tortoisesvn has a similar option.

It really will save me a lot of work and is much less errorprone.

If you're not able to do it, just send me your whole sources of BXE and
I will do the diff by myself

thanks

chregu

On 9.2.2006 12:03 Uhr, S=F6ren Eberhardt wrote:
> Hello,
>=20
> I've recently come across the task to write a DocBook-based wiki. I nee=
ded
> and WYSIWYG Editor component and hadn't heard of BXE before.
> But I found it and was SO happy!!
> But then it turned out that the editor could parse simple RelaxNG schem=
es,
> but not the DocBook schema.
> There was not much information about that available in the internet and
> one posting on the bx-editor-user list.
>=20
> So I started investigating what could cause this "bug" with BXE and
> DocBook and finally made it work.
>=20
> I've written a small log about the changes I've made. I really hope tha=
t
> they will be incorporated into future release of BXE.
>=20
> I'm new to this list and to BXE, so please don't beat me if something i=
s
> COMPLETELY wrong.
>=20
> _______________________________________________________________________=
__
>=20
> Changes to make BXE support DocBook RelaxNG (and other more complex
> grammars as well)
>=20
> Version of BXE that was used for the modifications:
> 2.0-dev 200601170330 Rev: 1448
>=20
> The source code snippets used here are the ones from the
> file versions of this revision fetched from SVN
>=20
> General
> ------------------------------
>=20
> The BXE is the only freely available WYSIWYG XML editor. It works great
> with simple grammars. But due to the lack of support for *all* elements=
 of
> the RelaxNG namespace it fails to parse more complex grammars (like the
> DocBook schemes: 4.x - 5.x and Simplified DocBook 1.0 / 1.1).
>=20
> After two weeks of digging deep into the Javascript code is was possibl=
e
> to tweak the BXE so that it was able to let me edit a "simplified docbo=
ok"
> document.
>=20
>=20
> Why only "simplified" DocBook?
> ------------------------------
>=20
> Well, the schema file is about 109kb and it takes about 2 sec. to load =
and
> parse it.
> If you take a look at the "normal" DocBook schema, which is about 450kb
> (as RelaxNG) and split into 5 files, you will soon see that it takes mo=
re
> than 15 sec. to parse the schema (and you will have to confirm "Yes, th=
e
> script can continue, don't stop it now" in Firefox more than once). The
> problem is that the schema is completely parsed in the browser.
> Maybe the parsing procedure can be optimized one day?!
>=20
>=20
> Changes
> ------------------------------
>=20
> a) Changes for supporting more RelaxNG elements
> #################################################################
>=20
> /relaxng/RelaxNG.js
>=20
> #########################
> DocBook starts with a choice!
> BXE wasn't expecting a choice element at the start. To make it simple,
> we only take the first choice element from the start.
>=20
> Line: 293, insert:
> --
> 		// The following part was missing in BXE!!
> 		// A grammar can also allow to start with a choice
> 		if (startChildren[i].isRelaxNGElement("choice")) {
> 			var choiceChilds =3D startChildren[i].childNodes;
> 			var xp =3D "/rng:grammar/rng:define[@name =3D '" +
> choiceChilds[i].getAttribute("name") + "']/rng:element"
> 			startNode =3D this.xmldoc.documentElement.getXPathFirst(xp);
> 			break Ende;
> 		}
> --
> #########################
> DocBook removes all /optional/attribute and /group nodes. That's not go=
od.
> At least commenting out this
> part didn't cause trouble.
> --
> Between line 83 and 84 insert: /*
> and one line 126 close the comment: */
> --
>=20
> #########################
> Add "group" as a RelaxNG element that is being parsed. For the easiness=
 of
> the
> thing I added group to the "choice" case:
>=20
> Line 543, insert below:
> --
> 			case "group":
> --
>=20
> so it's a fallthrough and we have the same node handling as it would be=
 a
> choice node.
> I'm not sure if this is correct, but it made DocBook work, because its
> grammar uses
> a lot of group nodes.
>=20
> #########################
>=20
> Don't create a node object for empty nodes!! This was the last showstop=
per
> before
> the full simplified docbook grammar could be parsed.
> Currently an empty node is creating an EmptyVDOM object.
> So I've changed this code (line 558/559) :
>=20
> --
> 				this.appendChild( new EmptyVDOM() );
> 				this._hasEmpty =3D true;
> --
>=20
> TO
>=20
> --
> 				this.addEmptyNode();// needed for DocBook compatiblity; soeren
> --
>=20
> and added this function to the file /relaxng/EmptyVDOM.js, line 48:
>=20
> --
> NodeVDOM.prototype.addEmptyNode =3D function() {
>=20
> 	this._hasEmpty =3D true;
>=20
> };
> --
> #########################
>=20
> In this file (EmptyVDOM.js) I had to wrap a special section into a try/=
catch
> block:
>=20
> Lines 150/151:
>=20
> --
> 				try {
> 					_attr[i].isValid(ctxt);
> 				 	_vdomAttr[_attr[i].name] =3D true;
> 				} catch(e) {}
> --
> #########################
>=20
> Back to /relaxng/RelaxNG.js NOW!
>=20
> The ReleaxNG element "notAllowed" was not supported. As a quick and dir=
ty
> fix I added it
> to the switch clause in RelaxNG.js, before line 561 (   case "data": )
>=20
> --
> 			case "notAllowed":
> 				this.appendChild( new NotAllowedVDOM() );
> 				this._hasEmpty =3D true;
> 				break;
> --
>=20
> This requires a new class "NotAllowedVDOM".
> Add it somewhere in this file. I did it before the line
>=20
> --
> EmptyVDOM.prototype =3D new NodeVDOM();
> --
>=20
> Add:
>=20
> --
> // Added by soeren
> // for DocBook compatibility
> NotAllowedVDOM.prototype =3D new NodeVDOM();
>=20
> function NotAllowedVDOM(node) {
> 	this.node =3D node;
> 	this.type =3D "RELAXNG_NOTALLOWED";
> 	this.nodeName =3D "RELAXNG_NOTALLOWED";
> }
>=20
> NotAllowedVDOM.prototype.isValid  =3D function() {
> 	return false;
> }
>=20
> NotAllowedVDOM.prototype.allowedElements =3D function() {
> 	return null;
> }
> --
>=20
> #################################
>=20
> That's it for the first part.
>=20
> #################################################################
>=20
> b) Bug fixes
>=20
> Sorry that I didn't use the bugtracker for now.
>=20
> #################################
> file /js/bxeFunctions.js
>=20
> Lines 212/213 ( the errors are explained in the comments):
> --
> 		// soeren: must call "cloneNode" on documentElement object
> 		var doc =3D bxe_config.xmldoc.documentElement.cloneNode(true);
> 		// soeren: cannot use doc. here!!
> 		var res =3D bxe_config.xmldoc.evaluate("//@__bxe_id", doc, null,
> XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
> --
> The same on line 221
> Change to
> --
> 		// soeren: cannot use doc. here!!
> 		res =3D bxe_config.xmldoc.evaluate("//@__bxe_defaultcontent", doc, nu=
ll,
> XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
> --
> #################################
> file /js/widget.js
>=20
> A small thing: Sometimes an XMLNode object has NO vdom property. This
> might occur due to
> errors while parsing the RelaxNG.
>=20
> But on line 699 BXE assumes that a vdom property is existant! That's no=
t
> good as it
> leads to an ugly Javascrpt error.
>=20
> Change
> --
> 		this.Popup.initTitle(node.XMLNode.vdom.bxeName);
> --
>=20
> TO
>=20
> --
> 		if( node.XMLNode.vdom ) {
> 			this.Popup.initTitle(node.XMLNode.vdom.bxeName);
> 		}
> 		else {
> 			this.Popup.initTitle( node.XMLNode.localName );
> 		}
> --
>=20
> So it uses the local node name for the popup title.
>=20
> _______________________________________________________________________=
_____
>=20
> That's it for now.
>=20
> The wiki-style script I'm working on will be a PHP-based plugin for the
> content management system Joomla! (also known as Mambo).
> It's called "DocBook:Collab".
>=20
> ciao, Soeren
>=20

--=20
christian stocker | Bitflux GmbH | schoeneggstrasse 5 | ch-8004 zurich
phone +41 44 240 56 70 | mobile +41 76 561 88 60 | fax +41 1 240 56 71
http://www.bitflux.ch | [email protected] |  GPG 0x5CE1DECB

--=20
bx-editor-dev mailing list
[email protected]
http://lists.bitflux.ch/cgi-bin/listinfo/bx-editor-dev