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

Inserting HTML into items #15

Open
austinj opened this issue Apr 7, 2021 · 5 comments
Open

Inserting HTML into items #15

austinj opened this issue Apr 7, 2021 · 5 comments
Labels
bug Something isn't working Useful Information

Comments

@austinj
Copy link

austinj commented Apr 7, 2021

I'm attempting to insert a link into the text for an Items element using HTML, but Hugo fails to build the page and throws this error: "failed to load data: "/Users/austinj/Documents/GitHub/retract/data/items.yml:23:1": failed to unmarshal YAML: yaml: line 23: did not find expected key". Line 23 is where I've done the following:

- name : "Title here"
content : "Content here and here is a <a href="https://www.github.com">link</a>."
style : "solid style2 major fa-cog"

Is there a way to add a link into the text of an item element?

@caressofsteel
Copy link
Owner

Have you tried formatting the link using markdown instead of HTML? I would also try escaping the double quotation marks in the URL.

@austinj
Copy link
Author

austinj commented Apr 9, 2021 via email

@caressofsteel
Copy link
Owner

Ok. When I have some time I'll look into it. Thanks for the report.

@caressofsteel caressofsteel added the bug Something isn't working label Apr 9, 2021
Repository owner deleted a comment from austinj Apr 10, 2021
@georgeblck
Copy link

What worked for me was saving the following html-code as layouts/partials/item.html

<section>
    <span class="icon {{ .style }}"></span>
    <h3>{{ .name }}</h3>
    {{ with .content }}<p>{{ . | safeHTML }}</p>{{ end }}
</section>

That way html syntax in the content field of each item is parsed correctly

@JHenneberg
Copy link

JHenneberg commented Jul 29, 2022

you can do it with pure markdown, but for this you need to adjsut the template. Just change safeHTML with markdownify:

{{ with .content }}<p>{{ . | safeHTML }}</p>{{ end }}

actually it should work what you are trying to do. Somethin like <h1>Smth</h1> is working wiht safeHTML

Edit: I just tried it and it is working: <a href="https://www.google.de">sowas</a> results in no error but a beatiful clickable link (safeHTML on of course not markdownify)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Useful Information
Projects
None yet
Development

No branches or pull requests

4 participants