ember-prism icon indicating copy to clipboard operation
ember-prism copied to clipboard

Question: Do curlies in always have to be escaped in prism, in a .hbs file?

Open amyrlam opened this issue 3 years ago • 5 comments

👋 I made this repro https://github.com/hashicorp/flight/pull/367, am wondering if this is a limitation of PrismJS or if you had any insights?

Curlies do not display (nothing displays in their place, no error):

<CodeBlock
  @language="markup"
  @code=' 
    <FlightIcon @name="zap" @size="24" @stretched={{true}} />
  '
/>

Curlies do not display, using https://prismjs.com/plugins/unescaped-markup/:

    <script type="text/plain" class="language-markup">
<FlightIcon @name="triangle-fill" @isInlineBlock={{false}} />
    </script>

This syntax does work for me:

<CodeBlock
  @language="markup"
  @code='
    <FlightIcon @name="triangle-fill" @isInlineBlock=&lbrace;&lbrace;false&rbrace;&rbrace; />
  '
/>

Aside: It seemed like there was better syntax highlighting using @language="markup" vs @language="markup".

If you have any insight please LMK!

amyrlam avatar Jan 08 '22 01:01 amyrlam

*I meant for language, markup seemed better highlighting than handlebars, thx @didoo for pointing out the typo

amyrlam avatar Jan 08 '22 17:01 amyrlam

I figured out a fix to this thanks to my colleague, @meirish (you the real MVP! :pray:) and will submit a PR. This syntax works:

    {{! prettier-ignore-start }}
    {{! template-lint-disable no-triple-curlies }}
    <CodeBlock
      @language="markup"
      @code={{{'
        <FlightIcon @name="zap" @size="24" @stretched={{true}} />
      '}}}
    />
    {{! prettier-ignore-start }}
    {{! template-lint-enable no-triple-curlies }}

Helpful article he shared that I can propose including: https://michaelsoolee.com/ember-unescaped-html/

amyrlam avatar Jan 10 '22 21:01 amyrlam

@amyrlam thanks for opening an issue! Is the same true if you put the code in a string variable first and do something like @code={{this.myCode}}? I would try that and/or escaping the curlies with \.

RobbieTheWagner avatar Jan 11 '22 01:01 RobbieTheWagner

@rwwagner90 Thanks for the reply, much appreciated, that's a good idea!

I'm going to stick with this syntax for now, so that say a future "Edit on GitHub" button can have everything on the docs page editable in the .hbs file.

@code={{{'
  <FlightIcon @name="zap" @size="24" @stretched={{true}} />
'}}} 

I can add a note to the README in a PR if useful? (If not useful, can close the issue as solved.) Just let me know!

amyrlam avatar Jan 12 '22 04:01 amyrlam

@amyrlam it couldn't hurt to have this info captured in the README. A PR would be great!

RobbieTheWagner avatar Feb 11 '22 16:02 RobbieTheWagner