I spent several hours coding up an HTML translator and have it 75% complete. Another coding session will finish it; then I'll have to test it a wee bit. Finished by Tuesday, I reckon.
I only found one awkward spot in the design of the Translator API. An Illustration markup like this:
[Illustration:fig_55.png|fig_55.jpgFig. 55 The whang-dangle is..
Produces a sequence of "events" as follows:
OPEN_ILLO with the two filenames OPEN_PARA LINE "The whang-doodle..."
So at the time I am generating the code for an image div, I have only the filenames. (Passing the filenames after the colon is a PPQT extension. If the user doesn't do that, the Translator has no way to get them.) The HTML Translator can use this to build a nice opening string of:
<div class=image> <a href='images/fig_55.jpg'> <img src='images/fig_55.png' /></a>
However, it would be a useful service if it could also generate alt= and title= attributes from the starting text of the caption, for example alt="Fig. 55 The whang-dangle.... But that can't happen because the opening text of the caption will not arrive for two more events.
I thought about postponing actual output of the image markup until the first paragraph arrived, but that would make the code just horribly ugly. On every OPEN_PARA event you'd have to ask, is this the start of a caption?
I put in a similar but lesser kludge in translating a Footnote. The OPEN_FNOTE event has the footnote key value, so it can generate the target anchor and the back-link to the footnote reference. Unfortunately all that goes inside the first paragraph of the note:
<div class='footnote'> <p><a id='Footnote_X'></a><a href='FNref_X'>[X]</a>
So here is the <p> being put out ahead of the coming OPEN_PARA event. So I had to create a switch footnote_starting and test it in the OPEN_PARA code, and when it is on, not generate anything and turn it off.
But by and large, the HTML Translator just kind of fell together. You just consider each of the 34 event codes in sequence, write a little bit of code, and repeat.
No comments:
Post a Comment