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

expand inside notice incorrectly interpreted as a code block #476

Open
fcooper8472 opened this issue Nov 30, 2020 · 4 comments
Open

expand inside notice incorrectly interpreted as a code block #476

fcooper8472 opened this issue Nov 30, 2020 · 4 comments

Comments

@fcooper8472
Copy link

Placing an "expand" shortcode inside a "notice" shortcode, such as:

{{% notice note %}}
{{%expand "The expand label"%}}The expand content{{% /expand%}}
{{% /notice %}}

produces the following:

<div class="notices note"><!-- raw HTML omitted -->
<pre><code class="hljs xml">    The expand label
	
    <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"expand-content"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"display: none;"</span>&gt;</span>
    The expand content
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code><span class="copy-to-clipboard" title="Copy to clipboard"></span></pre>
<!-- raw HTML omitted -->
</div>

I understand that there is a limitation of the notice shortcode, where styling is only applied to the first <p>, but the same behaviour exists with #455 that solves that particular limitation.

What I can't understand is how the inner expand is being interpreted as code (<pre><code class="hljs xml"> tags added).

For reference, when not inside a notice, the following (expected) behaviour is observed:

<div class="expand">
    <div class="expand-label" style="cursor: pointer;" onclick="$h = $(this);$h.next('div').slideToggle(100,function () {$h.children('i').attr('class',function () {return $h.next('div').is(':visible') ? 'fas fa-chevron-down' : 'fas fa-chevron-right';});});">
        <i style="font-size:x-small;" class="fas fa-chevron-right"></i>
        <span>
        
    	
    	The expand label
    	
    	</span>
    </div>
    <div class="expand-content" style="display: none;">
        The expand content
    </div>
</div>

I would be happy to work on a fix, but currently don't understand the problem. Any ideas what I'm missing?

@McShelby
Copy link

McShelby commented Dec 1, 2020

The different behavior comes from the additional usage of safeHTML in the expand shortcod I haven't tested it, but I'ld bet, if you delete this from the expand shortcode it will behave the same as the notice shortcode.

@fcooper8472
Copy link
Author

@McShelby thanks for the suggestion - unfortunately that didn't work.

If I re-write the shortcode to look like this:

<details>
    <summary>{{ .Get 0 }}</summary>
    {{.Inner}}
</details>

then it works as expected. But, even wrapping it in an extra div, e.g.,

<div class="expand">
    <details>
        <summary>{{ .Get 0 }}</summary>
        {{.Inner}}
    </details>
</div>

causes the final </details> tag to be somehow interpreted as a code block, producing:

<pre><code class="hljs xml"><span class="hljs-tag">&lt;/<span class="hljs-name">details</span>&gt;</span>
</code><span class="copy-to-clipboard" title="Copy to clipboard"></span></pre>

when used inside the notice shortcode. I'll try and investigate some more... but this seems pretty odd to me.

fcooper8472 added a commit to SABS-R3/ScientificComputingInMatlab that referenced this issue Dec 1, 2020
@McShelby
Copy link

McShelby commented Dec 1, 2020

Okay, I lost my bet - I owe you a coffee.

Now a tested recommendation. Leave the shortcodes as is. Instead of your example, write:

{{< notice note >}}
{{%expand "The expand label"%}}The expand content{{% /expand%}}
{{< /notice >}}

This worked for me up to the point of correct HTML. Nevertheless this still cuts your notice box into halfs until you

a) manually apply #455 to your code or
b) wait until #455 was merged into a production release in the future

@fcooper8472
Copy link
Author

@McShelby with apologies for the delay, I wanted to say that I got this working as you described.

I opted for a), to manually apply #455, and that worked fine for my application. Thanks for your input on this!

I'll leave this open for now as I see that #455 is not yet merged.

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

2 participants