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

How to prevent generating closing tag? #16

Open
thomrad opened this issue Aug 10, 2021 · 10 comments
Open

How to prevent generating closing tag? #16

thomrad opened this issue Aug 10, 2021 · 10 comments

Comments

@thomrad
Copy link

thomrad commented Aug 10, 2021

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

@thomrad
Copy link
Author

thomrad commented Aug 10, 2021

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>

@Dzoukr
Copy link
Owner

Dzoukr commented Aug 10, 2021

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

@thomrad
Copy link
Author

thomrad commented Aug 10, 2021

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.

@Dzoukr
Copy link
Owner

Dzoukr commented Aug 10, 2021

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

@thomrad
Copy link
Author

thomrad commented Aug 10, 2021

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.

@Dzoukr
Copy link
Owner

Dzoukr commented Aug 10, 2021

Hmmm... 🤔 If you would be able to produce a test (with PR to fix) that would be a big help! 🙏

@thomrad
Copy link
Author

thomrad commented Aug 10, 2021

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.

@Dzoukr
Copy link
Owner

Dzoukr commented Aug 11, 2021

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

@thomrad
Copy link
Author

thomrad commented Aug 11, 2021

Challenge accepted 🙏

@schwarzeszeux
Copy link

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).

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

3 participants