Can I markdownify and then strip HTML tags?


I have a question concerning the title tag. On some content, I’m using Markdown in titles, like italics for the name of a book or a movie.

When this title is displayed on the page, I want to markdownify it to have HTML output. But in the header, I want to have only the content as text, without Markdown or HTML markup.

Is there an easy way to do this ?

Thanks !

1 Like

What I do is to add an additional title, say main_title, and use markdown with line feeds etc. in that one. In one site I even have both a main_title and lead_title. Then I use the regular .Title in head.

Yes, I thought about that, but was hoping for a more easy, or at least automated, solution…

I remember now that I had stumble upon the same problem last summer, and I wanted to use a Go function, which was not possible:frowning:

I’m working on a new project where I could duplicate every title, but if I wanted to transfer my main blog on Hugo, it would be impossible (more than 1100 articles to deal with…).

So I guess there is really no solution right now. Maybe I should create a GitHub issue asking for this ? I can’t be the only one on Earth who use HTML in titles… or am I ?

I do, and it works fine for me. Creating a one time script that duplicates the title into a custom_title element for your 1000+ posts sounds like a one liner in bash or Perl or whatever. We could introduce a plain_title or something, but in my head it clutters more than it really solves things …

The one argument for it would be to get some common theme support for it … But then I would rather have a method that:

  1. Looks for a custom title with a name
  2. If not found, use the one in .Title

I think, what should be added is a markdownify-like function that output plain text, no matter what. Wouldn’t it be useful ?

It’s not the existing posts that bothers me, but also the next. If I have to fill two different parameters each time… It’s not impossible, but it’s (relatively) painful.

… maybe (plainify …), but I fear people would start abusing it and then complaining about Hugo being slow …

Well, OK, but people are grown-ups… :slightly_smiling:

Anyway, for now, I’m going to duplicate title, but I still think it would be great to have this, if nothing else for the HTML title that accepts only plain text.

No, they’re not.

1 Like
1 Like


Great, thanks ! :slightly_smiling:

Do you know if this function could make it to 0.16 release ?

No idea.


1 Like