Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML modes create "dirty" HTML #22

Closed
nphilipp opened this issue Aug 22, 2016 · 5 comments
Closed

HTML modes create "dirty" HTML #22

nphilipp opened this issue Aug 22, 2016 · 5 comments

Comments

@nphilipp
Copy link

nphilipp commented Aug 22, 2016

Kajiki's HTML modes default to produce "dirty" HTML, e.g. unclosed

  • tags. There's a hacky way to improve this, but it still doesn't use shortened end tags for e.g. <meta ... />, <img ... />, plays loose with inserting whitespace (e.g. two blank lines at the beginning of rendered documents):

    # make kajiki render nicer HTML
    from kajiki import html_utils
    html_utils.HTML_OPTIONAL_END_TAGS.clear()
    

    You can say many things about Genshi, but the (X)HTML it renders is beautiful. I realize that Kajiki uses a totally different way to create the templates which might make "staying close to the original template" difficult, but it should at least preserve closed and shortened end tags.

  • @amol-
    Copy link
    Collaborator

    amol- commented Aug 22, 2016

    In case XML syntax is desired shouldn't user just use XML mode? HTML allows for unclosed tags and actually deprecates self closing tags, but if I remember correctly kajiki XML mode does actually what you want to achieve.

    @nphilipp
    Copy link
    Author

    There are a couple of things that don't really cope well with the differences between HTML and XML (when delivered with an XML content type to the browser), e.g. some third-party Javascript modules expect tags to be uppercase in the DOM.

    HTML5 explicitly allows self-closing void start tags, so I guess I'm in the clear there (except maybe for the suggested shortcut to using FontAwesome icons, i.e. a self-closing <i ... /> tag, but there's a licit alternative in <embed ... />).

    Is there a way to use Kajiki XML mode in Turbogears and have it delivered as text/html? If so, I haven't found the way to do it.

    @amol-
    Copy link
    Collaborator

    amol- commented Aug 22, 2016

    I'm not saying that self closed tags are wrong, jus that they are not required and they are actually just ignored for void elements, so kajiki is doing the right thing in HTML mode as those tags are self closing in any case.

    Regarding how to switch kajiki to xml mode setting in turbogears templating.kajiki.force_mode = xml in your app_cfg.py should do what you are looking for. (See http://turbogears.readthedocs.io/en/latest/reference/config-options.html#tg.renderers.kajiki.KajikiRenderer) hope that helps!

    @nphilipp
    Copy link
    Author

    They're not required for HTML, but they're good if you want the rendered content not make stuff expecting XML go belly up (say the XML mode of your editor trying to balance out tags, or indent things intelligently 😉). I'm not expecting Kajiki to self-close all void start tags, only to preserve it if I do it in the template.

    I'll try what you suggested about forcing Kajiki to use XML mode in TG, but as I said above, it needs to be delivered with content type text/html so client-side doesn't have the changes in DOM etc. that make other things (JS libraries) break.

    @nphilipp
    Copy link
    Author

    So, setting base_config['templating.kajiki.force_mode'] = 'xml' rendered void elements with self-closing start tags (not so with e.g. <script> but that is expected with what the HTML standard says about it), and delivers the page as text/html. That works for me and trims down this issue to "playing loose with whitespace" but that's not a huge problem (unless you optimize for bytes sent ;).

    That leaves me only issue #21 before I can make the switch :).

    @amol- amol- closed this as completed Nov 13, 2016
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    None yet
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants