Dzoukr/Fue

How to prevent generating closing tag?

thomrad opened this issue ยท 10 comments

Hello!

I am using this library just a few days and really like it. I am using it for writting markdown and java code. Problem is, when having a Java code template, which uses these brackets <> for writing generics, then I automatically get an closing tag of said generic.

i.e.

public class Foo { ... }

turns into

public class Foo { ... }

How can I prevent this behaviour?

Greetings
Thomas

Ok, now I tried to pass the <> brackets via function into the template. But that still gives me the closing tag at the end of the resulting string...

    let template = """
package at.co.rl.esif.output.{{{file.ShortName.ToLower()}}};

import at.co.rl.esif.service.mapper.GenericMapper;

public class DefaultDataMapper {
    public static final GenericMapper{{{file.ShortName |> capitalize |> brackets}}}EntityBase entityBaseMapper = (r, e) -> {
        return e;
    };
}

        let writeDataMapper =
            init
            |> add "file" esifFile
            |> add "capitalize" capitalize
            |> add "brackets" (fun x -> "<" + x + ">")
            |> fromText template

results in

public class DefaultDataMapper {
    public static final GenericMapper<Accrol>EntityBase entityBaseMapper = (r, e) -> {
        return e;
    };
}
</Accrol>

Hi, I suspect HtmlAgilityPack with HtmlDocument.Create() would automatically add closing tag (it thinks it's the HTML code).

Hi, thank's for your reply. I am replacing the wrongly generated end tag with empty space after parsing the template. a bit of a hack, but does the job. in the end it is still an html parser.

Hi, thanks for the info! I think whole this library is "bit of a hack, but does the job" ๐Ÿ˜„

BTW, everything you put after < will get parsed as a string, even if you use the {{{ ... }}} brackets.

so """some text <{{{ with |> dosomething }}}>"""

ends in

some text<{{{{ with |> dosomething }}}></{{{ with |> dosomething }}}>

to prevent this, I had to pull a function in, which generates the opening angel bracket < - then I just have to get rid of the closing tag.

Hmmm... ๐Ÿค” If you would be able to produce a test (with PR to fix) that would be a big help! ๐Ÿ™

Hm, I can try. I don't know if I have enough knowledge of F# and I am sure I don't know how to proceed. Quite new to Git/Github. Maybe you can explain what you want from me, or give me a hint where I can read some procedures for Test and PR.
Sorry, really a beginner here.

No problem. Here is the path I would go through:

Challenge accepted ๐Ÿ™

This is related to #6 and #8.

I've also run into this problem (I wanted to create an rss-feed).

The core issue is the usage of HtmlAgilityPack.
In my case it was removing anything between <link>...</link> (for html this is correct behaviour).
To solve this and potential future issues, it might be necessary to look into alternative parsers.
One such alternative could be AngleSharp.

The question to me is, do you see this library as a html-only library or a general purpose templating library.
Or are willing to have it evolve into one :)

Because if it's the latter, we might want to discuss an alternative syntax for conditionals/loops.
Personally, I like the syntax and so far it's enough to cover all my use cases (html and xml/rss).