1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-15 23:35:34 +00:00
elinks/src/document/html
2024-06-03 17:22:24 +02:00
..
parser [html5] Also add NAV element. Refs #282 2024-01-07 20:11:00 +01:00
test [meson] / operator for paths 2024-06-03 17:22:24 +02:00
frames.c [strchr] casting first parameter to const char * was not a good idea 2022-01-18 20:30:48 +01:00
frames.h [cflags] Removed -Wno-pointer-sign 2021-01-02 16:20:27 +01:00
iframes.c [iframes] Still not functional 2023-06-10 17:57:28 +02:00
iframes.h [iframes] Still not functional 2023-06-10 17:57:28 +02:00
internal.h [lists] LIST_HEAD -> LIST_HEAD_EL to not clash with libevent's LIST_HEAD. Also added curl implementation of ftpes and sftp 2023-06-19 18:43:53 +02:00
Makefile [iframe] Copy-paste programming does not work 2021-07-25 23:07:05 +02:00
meson.build [meson] Do not build test programs by default 2022-11-30 10:17:49 +01:00
parse-meta-refresh.c [strchr] casting first parameter to const char * was not a good idea 2022-01-18 20:30:48 +01:00
parse-meta-refresh.h [cflags] Removed -Wno-pointer-sign 2021-01-02 16:20:27 +01:00
parser.c [js] placeholder for onkeypress 2023-09-21 09:30:50 +02:00
parser.h [js] placeholder for onkeypress 2023-09-21 09:30:50 +02:00
README Rename struct box to struct el_box. 2018-09-09 19:14:56 +02:00
renderer.c [ecmascript] Commented out clientHeight and similar properties 2024-03-02 19:13:45 +01:00
renderer.h [va_start] change enum to unsigned int in va_arg 2022-06-23 21:31:01 +02:00
tables.c [isspace] Some implementations of isspace require unsigned char 2022-06-28 20:25:06 +02:00
tables.h [tables] some static functions now are in global scope 2021-07-12 17:34:22 +02:00

This is the "Mikulas' HTML Processor". The parser and renderer we actually use.
It's scary, yes.


Parser - renderer interaction
=============================

(See also doc/hacking.txt. Incoherent (and possibly misleaded on some points;
don't trust it to the letter) rambling follows.)

The parser is written modularily so it is separated from the renderer and can
be actually used with a different renderer as well (they do that in Links2,
using graphics renderer with the current parser). The entry point from the rest
of ELinks is inside the renderer, which sets up couple of callbacks (like "put
this text on screen" or "special element indicator", where special element
might be a <hr>, a link or a table) and calls the parser.

Usually, the renderer just lets the parser chew through the document on its own and
only processes the callbacks, sometimes it kicks in though - at that point it
does a "management override", skips a chunk of the source and resumes the parser
after it's over. Most commonly, it does this with tables - when you hit a table,
html_table() does basically nothing and the renderer at that point skips to
</table>. What happens with the table you ask? The renderer calls itself
recursively on just the table; that means a separate parser instance is run for
the table, and for each distinct cell a new renderer instance is called. The
table is (parsed and) rendered two times - first to just find out the wanted
cell sizes, then it optimizes that and figures out the layout and does a second
rendering pass where it uses the calculated cell sizes to actually write the cells
to the canvas.


Box model plans
===============

The design described above - calling the renderer recursively on the table and each cell -
is a cheap substitute for the box model. Except for those cases where the
renderer basically just writes on the canvas sequentially as the text comes in, moving
the pen only rightwards and down; there are only some parameters like
indentation and border sizes which affect the rightwards and down motion.

It needs to be changed so that the renderer maintains a *box model* - at each
moment the text being written out is inside a stack of boxes. This is what
the table renderer achieves by just making each box a separate renderer
instance - you can't get away without boxes when rendering tables. But boxes
are essential for all block elements at the moment you go CSS, and we went CSS
and would like to support floating elements.

Even without support of the float property, boxes will have an immediate advantage since you will be
able to e.g. set their background - now e.g. slashdot looks really ugly since
it has background set on some block elements but since we have no box model we set the
background only on the rendered text itself, not the rectangular canvas around
it.

Boxes can probably be implemented by just transmitting information "here a new
box (block element) begins" and "here a box ends" from parser to the renderer,
and maintaining a box stack with some geometry information in the renderer (and
now, you've just got DOM for block elements if you turn this from a temporary
stack to a persistent tree; but we might not want to do that, at least not
unconditionally).


Rendering boxes
~~~~~~~~~~~~~~~

When you are actually rendering, you must not apply the attributes on the whole
box after rendering; inline elements might have custom attributes and we won't
have boxes for those. Also, you don't know the box width until you've already
rendered it. Several possibilities occur to me:

(i) Dry-run each box to find out the dimensions, prefill the rectangle with
attributes and then hard-render. Awfully quadratic, would kill performance.

(ii) Post-fill: for each line and each box in stack, remember "content width".
After the box is over you look at its each line and post-fill it from the
content width to the box width (at both sides).

(iii) Maximalistic: assume maximal spread and reduce afterwards. Basically fill
the whole line (from starting X coordinate) with the box attributes and when
the box is done rendering, fill the rest of all its lines (from ending X
coordinate) with the parent's box attributes.

I like (iii) most.


Boxes and floats
~~~~~~~~~~~~~~~~

In order to be able to support floats, you want to be able to revisit previous
boxes and resize them based on the new box. To do that, you need to remember
parser contexts for all the boxes in the stack (you should have only few of
those). If you hit a floating box, you:

	* dry-render it to find out the dimensions and then do the dimensions
	  negotiation like you'd do with cell tables; or maybe a different one,
	  I didn't read the specs on it; don't put anything on canvas

	* pop the floating box

	* duplicate the parent box, so you have a "sibling box" that contains
	  all the content hit so far; limit its parser context to reach
	  only to the start of your floating box

	  Note that you don't want to merge multiple float boxes together.
	  So, an implementation might have something like this instead of the
	  "duplication":

	  struct el_box {
		struct el_box floaters[];
	  }

	  where floaters are children of this box; normally you have one
	  which is mostly read-only and contains everything rendered so far,
	  and one which points to the next box in your stack. When you process
	  a floating box, it gets a separate entry in the floaters[] array
	  and won't get merged to floaters[0].

	* wipe the sibling box (floaters[*]) from canvas

	* rerender the sibling box with calculated geometry constraints

	* rerender the floating box dtto

(This might be modified based on how floats are actually supposed to behave;
I'm not sure of that. ;-) ) This algorithm is careful not to keep a list of
all sibling boxes in memory since with a simple long document a mere sequence
of paragraphs would cost us huge amount of memory. There's probably no way
around keeping a list of sibling floating boxes in memory, though.