Skip to content

Indenting / nesting content macro #15

@ghost

Description

Hi, I think I have a (partial) solution to the nesting problem: a function to format content as-if it is a nested and indented HTML element.

For instance, if I generate some HTML like so:

let content = html! {
    ul {
        li { : "toot" }
    }
}

I get the following HTML:

<ul><li>toot</li></ul>

As an aside, this puzzles me, is there anything I can do to get indented output? It'd be a great feature to me, I would expect output like this

<ul>
    <li>
        toot
    </li>
</ul>

Anyway, now I want to insert it into an HTML page:

let page = html! {
    html {
        body {
            : Raw(content)
        }
    }
}

And this gets me:

<html><body><ul><li>toot</li></ul></body></html>

Now, what I'm suggesting is a function or character to insert raw text with newlines and an indent, like so:

let page = html! {
    html {
        body {
            > content
        }
    }
}

Or perhaps: > Raw(content), or : Block(content), or some other variant.

For the result:

<html><body>
    <ul><li>toot</li></ul>
</body></html>

It would take the indent level from the parent's indent level and add one to it. If the raw content is multiline, it would indent all lines separately, like so:

<html><body>
    <ul><li>toot</li></ul>
    <ul><li>toot</li></ul>
</body></html>

What do you think? Would this be hard to implement? It'd really be a boon to getting nice formatted HTML output out of my Markdown server project (https://gitlab.com/willemmali-rust/markbrowse).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions