UserJS for XHTML 1.1 Ruby module

Forums » » User JavaScript

You need to be logged in to post in the forums. If you do not have an account, please sign up first.

Go to last post

8. February 2006, 10:35:28

White Lynx

Posts: 1978

UserJS for XHTML 1.1 Ruby module

To celebrate glorious victory of vikings from Osland in fierce battle with army of vertical alignment bugs, I decided to write UserJS 'implementation' of XHTML 1.1 Ruby module.
Those who have Opera 9TP2 can install ruby.js and try this page or this one.

If you'll notice bugs please post them here.

Note that Ruby module is part of XHTML 1.1 and documents with Ruby should be served as application/xhtml+xml, application/xml or text/xml (and not text/html), ruby elements should be in XHTML namespace http://www.w3.org/1999/xhtml

N.B. In Opera 9 TP2 you can set up UserJS directory from
-[Tools]
--[Preferences]
---[Sites]
----[Default settings]
-----[Scripting]
------[My javascript files]

(then place ruby.js in directory specified there).

P.S. Don't expect too much from ruby.js it just transforms ruby into XHTML + CSS tagsoup.

8. February 2006, 18:59:09

xErath

javascript guru

Posts: 6588

do you provide the enormous pice of code needed for fallback in older versions ? you should
For a collection of user scripts visit
http://my.opera.com/xErath/blog/

9. February 2006, 06:47:58

White Lynx

Posts: 1978

No. There is no fallback code, it works in 9TP2 only, the reason for heavy markup is attempt to support complex ruby with rbspan attributes and base that may contain extra stuff, like sub/superscripts. In fact only the following part of script is responsible for simple ruby:
element.insertBefore(element.getElementsByTagNameNS('http://www.w3.org/1999/xhtml','rt')[0].cloneNode('true'),element.firstChild);

The rest deals with complex one. I will post annotated version later, so it will be easier to read/modify code.

15. August 2006, 17:12:47

jesus2099

♡.. \(^Δ^;)/ ..☭

Posts: 356

This page doesn't work because of its content type as text/html, does it?
http://jesus2099.free.fr/fichiers/faq/J2_SRTalpha_seishin.htm
I don't remember why but I think I had a reason for putting text/html rather than application/...
Could you tell ?
jesus2099 × Ti = Tristan + patate12 ÷ saucisson7 éditer bug report
※ My bugs and whishlist for Opera
Using latest stable version on Windows XP

16. August 2006, 10:16:12

White Lynx

Posts: 1978

Yes, the reason is content type, one can change the script to handle text/html too, but since Ruby is not supposed to be used in text/html, script only runs on application/xhtml+xml, application/xml and text/xml pages.

16. August 2006, 10:52:07

jesus2099

♡.. \(^Δ^;)/ ..☭

Posts: 356

I changed the Content-type to application/xhtml+xml but the userjs doesn't trigger yet. Could you have a look at my page and tell me what is it that you see is wrong please? smile

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
<title>Les magies de Super robot taisen α (jesus2099)</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"/>
...

Is it the <html> tag ?
jesus2099 × Ti = Tristan + patate12 ÷ saucisson7 éditer bug report
※ My bugs and whishlist for Opera
Using latest stable version on Windows XP

16. August 2006, 11:32:11

Undertow

Posts: 593

you need to change the mime type.
178212+184112=192212

16. August 2006, 13:01:03

jesus2099

♡.. \(^Δ^;)/ ..☭

Posts: 356

Thanks Undertow, but I don't understand which one ?

And, White lynx, is it mandatory to use the following line (as in your samples) ?
<?xml version="1.0" encoding="utf-8"?>
jesus2099 × Ti = Tristan + patate12 ÷ saucisson7 éditer bug report
※ My bugs and whishlist for Opera
Using latest stable version on Windows XP

16. August 2006, 13:13:29

White Lynx

Posts: 1978

Thanks Undertow, but I don't understand which one?


If your server is configured appropriately, then just change file extension from .htm to .xhtml or .xml and then it will served as application/xhtml+xml or application/xml respectively.

is it mandatory to use the following line (as in your samples)?


No, it is optional.

16. August 2006, 14:24:16 (edited)

jesus2099

♡.. \(^Δ^;)/ ..☭

Posts: 356

Thanks White Lynx, I made a new file with xhtml extension.
And maybe, there is something interesting for you here.
Each time I used complex ruby, both rbc and rtc take the border settings of my surrounding table.
Please have a look : http://jesus2099.free.fr/fichiers/faq/J2_SRTalpha_seishin.xhtml
I don't know bu maybe you mught add some border: 0; somewhere in your great ruby.js.

Edit: It seems that it also takes the other properties such as the padding and margin. The complex ruby on my page have their characters spaced where my simple ruby don't. Maybe then border: 0; margin: 0; padding: 0; etc.

Edit 2: You might also press SHIFT+P to see print preview. There are other issues, still concerning table, rows and such (the row border it seems ; the light grey line), that may be of some interest for your userjs dev.
jesus2099 × Ti = Tristan + patate12 ÷ saucisson7 éditer bug report
※ My bugs and whishlist for Opera
Using latest stable version on Windows XP

16. August 2006, 15:32:41

White Lynx

Posts: 1978

Each time I used complex ruby, both rbc and rtc take the border settings of my surrounding table.


This is because complex ruby is formatted as table, I changed UserJS, new one resets margins,
borders and other CSS properties, this should partly solve the problem but will not fully protect ruby from CSS applied to tables.


You might also press SHIFT+P to see print preview.



Known bug with inline-tables http://www.geocities.com/csssite/opera/bug13.xhtml

16. August 2006, 16:43:51

jesus2099

♡.. \(^Δ^;)/ ..☭

Posts: 356

How great !
Thank you up

Is it the inlay-table bug causing this 1cm vertical spacing between ruby base and ruby text of complex ruby in print preview ?

jesus2099 × Ti = Tristan + patate12 ÷ saucisson7 éditer bug report
※ My bugs and whishlist for Opera
Using latest stable version on Windows XP

17. August 2006, 08:35:47

White Lynx

Posts: 1978

Is it the inlay-table bug causing this 1cm vertical spacing between ruby base and ruby text of complex ruby in print preview ?


Yes, it does not affect simple Ruby which is formatted as inline-block, but complex Ruby which is formatted as inline-table is affected by that bug.

7. September 2006, 16:58:24

jesus2099

♡.. \(^Δ^;)/ ..☭

Posts: 356

Hi Lynx,
Why not in userjs.org too / instead ?
jesus2099 × Ti = Tristan + patate12 ÷ saucisson7 éditer bug report
※ My bugs and whishlist for Opera
Using latest stable version on Windows XP

9. October 2006, 15:27:44

White Lynx

Posts: 1978

Well, Ruby module is part of XHTML 1.1 and documents with Ruby should be served as application/xhtml+xml, application/xml or text/xml, per specs it is nor expected to be used in text/html documents like Wikipedia article above, but if necessary it is possible to modify UserJS to allow ruby in text/html too.

18. October 2006, 15:50:49

jesus2099

♡.. \(^Δ^;)/ ..☭

Posts: 356

Hi Lynx,
There is Kai Lapis, coding something similar : http://my.opera.com/userjs/forums/topic.dml?id=163010
She (he?) is true that your script is not easy to find. Maybe you should cooperate in some way, exchange secret techniques ... Make a coproduction in some way for the better of us all ruby fanatics. yes
jesus2099 × Ti = Tristan + patate12 ÷ saucisson7 éditer bug report
※ My bugs and whishlist for Opera
Using latest stable version on Windows XP

19. October 2006, 10:12:02

White Lynx

Posts: 1978

There are no secret techniques smile script is in public domain and anyone can copy/modify/redistribute it without any restrictions. One can enable it in HTML too, like this
http://xml-maiden.com/userjs/ruby/html/ruby.js
but Ruby is not part of HTML, so original script does not run on text/html pages by design.

Kai Lapis's script uses more simple approach, that does not take care of baseline alignement in cases when height of base and/or annotations differes from expected (for example base carries some complex inline content), but this issue is not important as usually ruby contains only simple text.

19. October 2006, 14:30:59

jesus2099

♡.. \(^Δ^;)/ ..☭

Posts: 356

In fact, I just learned that XHTML documents should be written into ".xhtml. extension files. Because the two files I linked up contain identical code but only the ".xhtml" one triggers with your code.
document.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "ruby")
jesus2099 × Ti = Tristan + patate12 ÷ saucisson7 éditer bug report
※ My bugs and whishlist for Opera
Using latest stable version on Windows XP

10. September 2007, 10:49:39

White Lynx

Posts: 1978

Those who are testing Opera 9.5 can try updated version of ruby.js
New is supposed to be smaller, faster and better. It avoids tables unless rbspan attribute is used somewhere.

10. September 2007, 11:13:45

Darken

Dragonfly rulez!

Posts: 356

Okay, thanx for the update.

26. June 2008, 15:59:34

jesus2099

♡.. \(^Δ^;)/ ..☭

Posts: 356

Hey you two, since userjs is dead, you could upload your scripts into http://userscripts.org (it's a nice repository) and tag them accordingly (like tag:opera friendly because the website is for any browser and tag:<ruby>.
jesus2099 × Ti = Tristan + patate12 ÷ saucisson7 éditer bug report
※ My bugs and whishlist for Opera
Using latest stable version on Windows XP

Forums » » User JavaScript