<!-- prettier-ignore --> doesn't work
apoorvmote opened this issue · comments
I am using this plugin with hugo and my content pages are written in html
NOT markdown
Problem is prettier is formatting my code when I don't want it to. So I tried following to ignore code
Option1: doesn't work
<!-- prettier-ignore -->
{{< highlight ts "linenos=table" >}}
import styles from './App.module.css';
function App() {
return (
<div className={styles.App}>
<header className={styles.AppHeader}>
{{< / highlight >}}
Option 2: doesn't work
<!-- prettier-ignore-start -->
{{< highlight ts "linenos=table" >}}
import styles from './App.module.css';
function App() {
return (
<div className={styles.App}>
<header className={styles.AppHeader}>
{{< / highlight >}}
<!-- prettier-ignore-end -->
Option 3: doesn't work
<!-- prettier-ignore -->
```ts
import styles from './App.module.css';
function App() {
return (
<div className={styles.App}>
<header className={styles.AppHeader}>
\```
Option 4: doesn't work
<!-- prettier-ignore-start -->
```ts
import styles from './App.module.css';
function App() {
return (
<div className={styles.App}>
<header className={styles.AppHeader}>
\```
<!-- prettier-ignore-end -->
The following option does work but there is annoying prettier ignore comment
{{< highlight ts "linenos=table" >}}
<!-- prettier-ignore -->
import styles from './App.module.css';
function App() {
return (
<div className={styles.App}>
<header className={styles.AppHeader}>
{{< / highlight >}}
above code will generate following snippet that has annoying prettier ignore comment
<!-- prettier-ignore -->
import styles from './App.module.css';
function App() {
return (
<div className={styles.App}>
<header className={styles.AppHeader}>
Have you tried a .prettyierignore
file? It worked for me in my own Hugo work.
https://prettier.io/docs/en/ignore.html
> cat .prettierignore
/public/
resources/_gen/
hugo_stats.json
Here is my .prettierignore
file
static
public
node_modules
resources/_gen/
hugo_stats.json
I got tired of waiting around and for code snippets I use gist.github.com
@apoorvmote so is this about files that are not handled by this plugin?
For *.ts
, * .md
the regular prettier plugin formatting is formatting your code.
If you want to exclude everything except for the HTML files you can do it with your .prettierignore
file:
prettier/prettier-vscode#578
Well even if it does work 100% there is another problem.
100% of my pages are written in amp
pages mostly talking about html
, jsx
and amp
itself. And even though the code snippet is inside <pre><code><button onClick={() => console.log('hello world')}>submit</button></code></pre>
the amp
runtime tries to execute html
inside <pre><code></code></pre>
on page load. So I couldn't use code snippets. I have no idea how amp.dev can show snippets without being executed.
So I switched everything to gist.github.com. And now I don't have this problem anymore. And since I am the only one having this issue. I will just close it.
@apoorvmote Could you reopen this issue but maybe make the title more specific to "<!-- prettier-ignore -->
doesn't work"?
I'm having the same issue, trying to use it with my hugo templates.
Good so I am not the only one who is having this issue.
FYI prettier-plugin-go-template@0.0.11-beta.9
also already includes Go specific ignore syntax:
<div>
{{/* prettier-ignore */}}
<script>
This
is
ignored
.
</script>
<span> But this is not </span>
</div>
All the contents of the ignored tag won't be formatted. Does this fulfill all of your needs? @jasikpark @apoorvmote
If something is not working with that syntax, please give me a specific example with input, output and expected sections. Also keep in mind that this plugin currently only supports HTML templates.
That looks like it'd work for me! I'll have to try that out, thanks for all your hard work on this!
@NiklasPor is beta-9 released yet? I don't see it on npm
Accidentally only published to my local registry. Should be available now
prettier-plugin-go-template@0.0.11-beta.9