Markdownify applying to `.Inner` with comments did not strip `/*` and `*/`

First I created a shortcode named markdown.html, which prints the content of .Inner and its markdownify:

{{- $content := .Inner -}}
{{- $render := $content | markdownify -}}
<div class="_test_">
    <style>
        ._test_ table {
            border-collapse: collapse;
            width: 100%;
        }
        ._test_ tr, ._test_ th, ._test_ td {
            text-align: left;
            padding: 8px;
            border: 1px solid #ddd;
        }
    </style>
    <table>
      <tr><th>.Inner</th><th>markdownify</th></tr>
      <tr><td>{{- printf "%s" (replace $content "\n" "\\n") -}} </td>
      <td>{{- printf "%s" (replace $render "\n" "\\n") -}} </td></tr>
    </table>
</div>

Then I used it in a markdown file like this:

Apply `markdownify` to the following content
```markdown
{{</*/* other-shortcode */*/>}}
Some content.
{{</*/* /other-shortcode */*/>}}
```
will reproduce the following result:
{{< markdown >}}
{{</*/* other-shortcode */*/>}}
Some content.
{{</*/* /other-shortcode */*/>}}
{{< /markdown >}}

Here, I used /*/* as the first one will be swallowed when passed to the shortcode.

The result is

In the above picture, we see the content of .Inner is

{{</* other-shortcode */>}}
Some content`.
{{</* /other-shortcode */>}}

Markdownify did not remove the comment character. It recognizes the second star as an emphasis.
I’m wondering why this happened. Could someone give some hints or some workaround?

I expected it should trim the comment symbol /* and */, and then call the other-shortcode.

You are mixing HTML with markdown, which is fine, but you need to be aware of the rules for doing so, specifically condition #6 in https://spec.commonmark.org/0.30/#html-blocks.

Replace this:

{{< markdown >}}
{{</*/* other-shortcode */*/>}}
Some content.
{{</*/* /other-shortcode */*/>}}
{{< /markdown >}}

With this:

{{< markdown >}}
{{</*/* other-shortcode */*/>}}

Some content.
{{</*/* /other-shortcode */*/>}}
{{< /markdown >}}

Thank you for providing the information. The addition of a blank line does prevent the asterisk from being interpreted as an emphasis tag. However, I’ve observed that the symbols /* and */ are not being stripped, and several <p> tags are being added.

I have a few questions regarding how Hugo processes a standard Markdown file and the functioning of the markdownify feature:

  1. It appears that markdownify calls shortcodes. Could you clarify why it doesn’t strip the comment symbols?
  2. At what point does markdownify remove comments?
  3. When are shortcodes applied in the processing pipeline?
  4. Could you explain the sequence of operations for a typical Markdown file in Hugo? Is it initially converted to HTML, then subjected to shortcode application, and finally, the layout is applied?

I appreciate your time in addressing these questions. Thank you once again.

Of course not. You have double-escaped the shortcode.

This conversation would be easier if we understood your objective (i.e., what do you want to display?).

Apologies for any confusion earlier. I aim to create a shortcut that displays both the source code and the rendered result side by side. I expect that by inputting a string into markdownify, I can obtain results identical to what is written in the markdown file.

For instance, if the markdown file contains content with comments like this:

{{</* highlight python */>}}
import os
{{</* /highlight */>}}

The desired rendered result should be a string without the comment symbols, resembling this:

{{< highlight python >}} import os {{< /highlight >}}

Is it possible to achieve this using markdownify or other functions provided by Hugo within the shortcode?

These are not comments. The /* and */ strings within the opening and closing shortcode tags are a mechanism for escaping shortcodes to prevent template execution.

What is the “other-shortcode”? Please be precise and provide an example.

Take this for a spin:

git clone --single-branch -b hugo-forum-topic-47329 https://github.com/jmooring/hugo-testing hugo-forum-topic-47329
cd hugo-forum-topic-47329
hugo server

Brilliant to provide the example and host it on GitHub. Based on your example, I made a slight modification to the markdown shortcut in my repository and added example 4 with my expected outcome. Could you please take a look?

git clone --single-branch -b hugo-forum-topic-47329 https://github.com/lrtfm/hugo-testing hugo-forum-topic-47329

Thank you for your patience.

Do you want to execute the inner short code, or do you want to just display the markup? You can’t have it both ways.

Just display the markup.

Sorry, but I don’t understand. You are labeling the table cell “RENDERED”. The example I provided does just that.

See the following screenshot

The text

{{</* other-shortcode */>}}
Some content.
{{</* /other-shortcode */>}}

in markdown file will be rendered as

{{< other-shortcode >}} Some content. {{< /other-shortcode >}}

But in the table, the rendered cell shows

{{</* other-shortcode />}} Some content. {{</ /other-shortcode */>}}

which is not what I expected.

So you want to use a shortcode to document how to document a shortcode. Really?

It seems yes. And I would like to know how the markdown file is processed.

Find another way.

Well, Thank you.