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

Noparse issue with markdown fields #2161

Closed
riasvdv opened this issue Jul 31, 2020 · 18 comments · Fixed by #4257
Closed

Noparse issue with markdown fields #2161

riasvdv opened this issue Jul 31, 2020 · 18 comments · Fixed by #4257

Comments

@riasvdv
Copy link
Contributor

riasvdv commented Jul 31, 2020

Bug Description

I have a markdown field with the following contents:

{{ color.label }}

This is what gets output when I dump the field in my templates:

<p>noparse_56c56f2a2936bb9da06452fbd043aec8</p>

The final html however is just

<p></p>

Seems like the {{ color.label }} is somehow being parsed.

Environment

Statamic version: 3.0.0.-beta-41

PHP version: 7.4

Install method (choose one):

  • Fresh install from statamic/statamic
@jasonvarga
Copy link
Member

jasonvarga commented Jul 31, 2020

Are you using vue or something similar on the frontend?

Is that <p> empty in the actual rendered source?

@riasvdv
Copy link
Contributor Author

riasvdv commented Jul 31, 2020

So this is the field:

image

This is what's rendered

image

When I | dump the markdown, this is shown

image

Just using a normal antlers partial

<div class="max-w-3xl mx-auto my-8">
    {{ markdown }}
</div>

@riasvdv
Copy link
Contributor Author

riasvdv commented Jul 31, 2020

It's a set inside a Bard though, if that maybe helps

@jasonvarga
Copy link
Member

Can you confirm that you are looking at the rendered html output (using "view source") rather than devtools?

@riasvdv
Copy link
Contributor Author

riasvdv commented Jul 31, 2020

View source also has an empty <p>

image

@riasvdv
Copy link
Contributor Author

riasvdv commented Jul 31, 2020

Ah no, sorry, it's just an empty div

image

The <p></p> is from Bard

@jasonvarga
Copy link
Member

So it's correct?

@riasvdv
Copy link
Contributor Author

riasvdv commented Jul 31, 2020

No, when I type {{ color.label }} inside a markdown field, I expect to see this html:

<div class="max-w-3xl mx-auto my-8">
    {{ color.label }}
</div>

It shouldn't try to parse what I type inside the markdown field

@jasonvarga
Copy link
Member

Yeah ok sorry haven't finished my coffee. 😅

If you have some other text in the markdown field, you see that, right? Just not the {{ color.label }} part?

@riasvdv
Copy link
Contributor Author

riasvdv commented Jul 31, 2020

Yes

image

Result:

image

@jasonvarga
Copy link
Member

Can you paste the yaml for that field in your blueprint?

@riasvdv
Copy link
Contributor Author

riasvdv commented Jul 31, 2020

Sure, it's just the default Markdown one inside a Bard set

markdown:
              display: Markdown
              fields:
                -
                  handle: markdown
                  field:
                    restrict: false
                    automatic_line_breaks: true
                    automatic_links: false
                    escape_markup: false
                    smartypants: false
                    type: markdown
                    localizable: false
                    listable: hidden
                    display: Markdown

@mattmurtaugh
Copy link
Contributor

I'm pretty sure I'm have the same issue. It looks like there was a change with how markdown is parsed and it no longer parses any variables or tags within the content.

We use this a lot for things like {{ company:phone }} or {{ company:email }} in blog posts of pages to reference the global variable. I can't say for sure this ever worked in v3, but I heavily used it in v2.

I also have a special use case where I've created at widget tag that I can use to display widgets inside a blog post like this {{ widget:game from="job-simulator" position="left" }}. I know for sure this one worked because I wrote the tag specifically for v3. The tag works on its own in a template, but not if used within markdown like it used to.

Statamic version: 3.0.0-beta.46
PHP version: 7.4.6

@jasonvarga
Copy link
Member

Matt, you need to add antlers: true to a field to have it parse variables inside markdown. Sounds the opposite to the issue Rias is describing.

@github-actions
Copy link

github-actions bot commented Jan 9, 2021

This issue has not had recent activity and has been marked as stale — by me, a robot. Simply reply to keep it open and send me away. If you do nothing, I will close it in a week. I have no feelings, so whatever you do is fine by me.

@github-actions github-actions bot added the stale label Jan 9, 2021
@riasvdv
Copy link
Contributor Author

riasvdv commented Jan 15, 2021

This is still an issue afaik

@github-actions github-actions bot removed the stale label Jan 16, 2021
@lorisleiva
Copy link
Contributor

Hi all 👋 I'm experiencing the exact same issue here.

It makes it difficult to write Vue.js articles as all template variables are erased from code examples.

For example, the following markdown field (where antlers: false):

Capture 2021-03-14T12 24 50@2x

Gets rendered as:

Capture 2021-03-14T12 28 11@2x

A quick {{ content | dump }} outputs the following noparse_xxx values:

<h3>Util methods as filters</h3>
<p>For our final internal plugin, let's use a less heavy example. I often like using filters in VueJs for very common string operations. In case, you're not fam ▶
<pre><code class="language-html">noparse_79e9e31dd2fa3c6adc2472f6f11c1586                &lt;!-- &quot;published&quot; --&gt;
noparse_40ef335f4d0e04ff294feca54ee3f448   &lt;!-- &quot;Published&quot; --&gt;
</code></pre>

@lorisleiva
Copy link
Contributor

lorisleiva commented Mar 16, 2021

I did some digging and found a non-documented noparse modifier that can help as a workaround until this issue is resolved.

Instead of just using {{ content }} for a markdown field, you need to use the following modifiers:

{{ content | raw | noparse | markdown }}

I hope this helps. 🍀

EDIT: I've recently figured out that it was a form on the page that was causing this issue for me. I had a form augmenting the fields property and using {{ field }} inside it. For some reason, that caused the noparse logic to fail. Instead of looping through fields dynamically, I wrote them manually and everything worked as expected using {{ content }}.

However, I did have to add the noparse modifier to a bunch of code fields (even without a form on the page). Basically, I now have my markdown fields working using {{ markdown_field }} but my code fields are working using {{ code_field | noparse }}. 🤷‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants