Details

Applies to

1.5.0 (MoinMoin/formatter/ sources)

Purpose
Improve formatter methods to allow arbitrary HTML/CSS attributes to be passed consistently
Description

The main purpose of this patch is to clean up the internal APIs for formatters, while maintaining as much backwards compatibility as possible. The cleanup provides a more natural and consistent calling convention for all the different formatting methods. It also especially tries to get the HTML formatter up to a more standard-compliant output. This fix will also enable a lot of other CSS and styling features and enhancements.

See also the description on FeatureRequests/FormatterApiConsistencyForHtmlAttributes

Patch

formatter-patch-r4.diff (rev 4) (committed to moin--refactor--1.5--patch-3)

The bulk of the changes are specific to the text_html.py formatter. Changes in the other files mostly consist of just allowing optional keyword arguments to be passed to the methods (which are mostly ignored).

The HTML formatter is now capable of generating XHTML compliant, or at least well-formed XML, output---for those parts of the document that the formatter generates. However this is still not enough to make MoinMoin produce correct XHTML, but it's a step in the right direction. This patch allows all elements (tags) to have almost any standard attribute added to them, and enables this with consistent method calling conventions.

The docstrings to many of the methods have been improved.

This also incorporates a fix for MoinMoinBugs/StrikeElementNotStrict

Older patches. These are for historic reference only, do not use.

For macro and extension writers

If you write or maintain any macros or other extensions which make calls to the formatter directly, you should familiarize yourself with the new calling conventions. Most formatter methods now take and number of additional arbitrary keyword-arguments. This can be useful for setting CSS styles or other things.

You may want to start by reading the docstring for the function rewrite_attribute_name() in the file MoinMoin/formatter/text_html.py.

Also note that this patch has some preliminary support for properly indenting HTML code according to its structure, which can make debugging easier. But this is not perfect yet, primarily because of complexities with how the page caching works.

Discussion

Thanks for putting lots of effort in improving the formatter. I am considering applying your patches after some changes:


I uploaded a new version of this patch (rev 2). This includes fixing the small bugs, most of the major refactoring work, lots of coding convention PEP8 fixes, added even more complete docstrings and comments. It does not address yet all your issues. I thought it was important to get the big changes done first. I've tested with IE and Firefox, Windows and Linux, and I think these changes are pretty sound now.

The refactoring of the formatAttributes method should make the code much clearer, but you can judge that. There are two new helper functions at the top of the file which offload a lot of the special-cases.

Also I didn't react to your XML-isms complaint yet. I think it needs more thought; we're actually much closer to clean HTML than you may think. I at least want to allow the formatter to produce well-formed XML (as well as allow plugin/macro writers to be able to produce clean XHTML even if moin does not). Check what I've done with this revision, and we can argue the other bit later. -- DeronMeranda 2006-01-16 20:30:31

OK, that sounds quite promising. I was a bit conservative because the last 2-3 tries for xhtml compliance only solved the small things (like " />" everywhere), but not the bigger problems (like correct list nesting). And 95% correct xhtml is practically as good as no xhtml at all. You did try some nested lists? See also that open converter bug MoinMoinBugs/IllegalListElementp relating to <p> directly within <li>. Maybe meet us on the MoinMoinChat for discussion inclusion of your patch before/after 1.5.1. -- ThomasWaldmann 2006-01-17 08:26:31

Some more comments while looking at the diff:

When you are at it anyway: please fix MoinMoinBugs/StrikeElementNotStrict also (and close it), so we don't have conflicts.

I've addressed most of your recent issues. Except when you said to pass **kw through to lower-level functions, I thought I was doing that everywhere it made sense, and I'm just not seeing the omission...please give me a hint.

One other positive thing is that I may be making accidental progress on the GUI editing bug with nested lists. Even though my previous revision produced correctly nested tags, my working-copy updated patch now also fixes a lot of the indenting and extraneous newlines in the html source. Structurally its the same document, but it seems to make the GUI editor much happier. But even if this works the GUI editor code must be unnecessarily fragile. -- DeronMeranda 2006-01-18 21:04:56


New patch revision is out (rev 4). I'm hoping this is near final. If you can test, please do so and give feedback. -- DeronMeranda 2006-01-19 20:34:43

Please read arch@arch.thinkmo.de--2003-archives/moin--refactor--1.5--patch-4 for the PEP8 changes I did.

Plan


CategoryFeatureImplemented

MoinMoin: MoinMoinPatch/FormatterApiConsistencyForHtmlAttributes (last edited 2007-10-29 19:09:16 by localhost)