Problem with markdown and shortcode

I have a shortcode I use for foreign words:


{{ if .IsNamedParams }}<span class="foreign-lang" lang="{{ .Get "lang" }}" title="{{ .Get "title" }}">{{ .Inner | mardownify }}</span>{{ else }}<span class="foreign-lang" lang="{{ .Get 0 }}" title="{{ .Get 1 }}">{{ .Inner | mardownify }}</span>{{ end }}

It works great for inline foreign language words. But I found an edge case where it seems to mess up.

If I use it within a code block, it enters the code block but never exits the code block; the markdown code fails.

So if I do this

    {{<lang “es” “Help me!”>}}¡Ayudame!{{</lang>}}

This is text

It ends up all being in the code block and all the markdown processing stops.

  1. Is there something I am missing like a markdownify tag?

  2. Do I need the {{ if .IsNamedParams}} or can I just stack the names next to gets like this: {{ .Get “title”}}{{ .Get 1}} ?

Not sure if this is the problem, but you’re missing an end-quoute in the above example.

Sorry. That was me typing the question. I definitely don’t have that in my actual code.

OK, now I see it:

This

{{ .Inner | mardownify }}

Is, I would say, almost never the right thino g to do. And the behaviour got even more undefined when we got shortcode support in markdownify in Hugo 0.100.0 (if you start think about it, you end up in a rabbit hole pretty fast).

If you need som inner content to be rendered as Markdown, I would look into the {{% delimiter or, if really needed, apply markdownify/RenderString to smaller text snippets and not the entire .Inner block. I’m not totally sure what exactly happens in your situation (I don’t see the source).

Ok, so let’s say I remove that markdownify tag. It doesn’t really fix anything. Here is straight copy and pastes from my site and a screenshot of what is rendered.

{{ if .IsNamedParams }}<span class="foreign-lang" lang="{{ .Get "lang" }}" title="{{ .Get "title" }}">{{ .Inner }}{{ .Get 2 }}</span>{{ else }}<span class="foreign-lang" lang="{{ .Get 0 }}" title="{{ .Get 1 }}">{{ .Inner }}{{ .Get 2 }}</span>{{ end }}

Now I have in my post:

She thought about how to word it and ended up settling on a pithy and non-specific language.

    {{<lang es "I want to buy">}}Quiero comprar.</a>

The response came back soon enough.

It renders like the following:

^ Notice “The response came back soon enough.” is in the code block. And the HTML source:

<p>She thought about how to word it and ended up settling on a pithy and non-specific language.</p>
<pre><code><span class="foreign-lang" lang="es" title="I want to buy">Quiero comprar.</a>

The response came back soon enough.

So not paragraph tags around the problem statement and it never closes the

 or  tags

Again, it’s not possible to help you with this very detailed question without having all the details (= all the source code).

OK, here is the repository:

The example of a file that is problematic is /content/vol01/01.068-target.md

ok I am a total dumbass and had an open tag. I can’t even believe how long i stared at the code

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.