Skip to content

How to remove backquote around inline code? #18

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

Closed
dpyzo0o opened this issue Jul 15, 2020 · 18 comments
Closed

How to remove backquote around inline code? #18

dpyzo0o opened this issue Jul 15, 2020 · 18 comments

Comments

@dpyzo0o
Copy link

dpyzo0o commented Jul 15, 2020

The default style of inline code has backquotes which I do not want. I tried to override it with the following configuration but it does not work.

// tailwind.config.js
module.exports = {
  theme: {
    typography: {
      default: {
        css: {
          code: {
            '&::before': {
              content: '""',
            },
            '&::after': {
              content: '""',
            },
          }
          // ...
        },
      },
    },
  },
  plugins: [
    require('@tailwindcss/typography'),
    // ...
  ],
}

Screen Shot 2020-07-15 at 15 28 55

@adamwathan
Copy link
Member

Can you create a GitHub repo that reproduces this? I just tried it on our blog and was able to override it no problem with your exact code.

@vincentdoerig
Copy link

Hi @dpyzo0o, if you add !important it should work. So like this:

typography: {
  default: {
    css: {
      code: {
        '&::before': {
          content: '"" !important',
        },
        '&::after': {
          content: '"" !important',
        },
      }
      // ...
    },
  },
},

I was able to reproduce your issue though, I think the problem is that the new class gets added before the typography plugin class and thus overwriting it.

Screenshot 2020-07-15 at 22 31 25
I imagine this is something that could be fixed?

@dpyzo0o
Copy link
Author

dpyzo0o commented Jul 16, 2020

@vincentdoerig Yes, adding !important can solve the issue but I'm trying to avoid using !important if possible. Indeed I'm able to remove the backquotes by setting display: none

// tailwind.config.js
module.exports = {
  theme: {
    typography: {
      default: {
        css: {
          code: {
            '&::before': {
              display: 'none',
            },
            '&::after': {
              display: 'none',
            },
          }
          // ...
        },
      },
    },
  },
  plugins: [
    require('@tailwindcss/typography'),
    // ...
  ],
}

@adamwathan I'm sure this issue is reproducible, here is a minimal repo that reproduces the issue, https://github.com/dpyzo0o/tailwindcss-bug-reproduce

@dpyzo0o
Copy link
Author

dpyzo0o commented Jul 16, 2020

@adamwathan some findings... Writing in this way will correctly overwrite the original style. Seems like using &::before, &::after will cause the styles to be applied before the original styles.

// tailwind.config.js
module.exports = {
  theme: {
    typography: {
      default: {
        css: {
          'code::before': {
            content: '""',
          },
          'code::after': {
            content: '""',
          }
          // ...
        },
      },
    },
  },
  plugins: [
    require('@tailwindcss/typography'),
    // ...
  ],
}

@adamwathan
Copy link
Member

adamwathan commented Jul 16, 2020

Ah yeah you know what I think I wrote it that way when I was testing things out, so I was wrong when I said I used your code exactly 🤦

It looks like this is due to a particular detail of how deep merging works in lodash, which causes object properties to be merged in a different order than I'd expect (overrides are added as earlier keys in the object being merged to, not later).

For now I would recommend mimicking the exact selector we use in the styles.js reference whenever you need to make an override, and we will see about making the merging behavior more intuitive.

EDIT: Actually doesn't seem like a lodash issue, not sure where this order issue pops up, might be in postcss-js. Will explore.

@adamwathan
Copy link
Member

Actually I know exactly what is happening now, sorry.

Your changes are being merged with our existing code key, which comes before our code::before and code::after keys.

Here's our code:

code: {
  color: defaultTheme.colors.gray[900],
  fontWeight: '600',
},
'code::before': {
  content: '"`"',
},
'code::after': {
  content: '"`"',
},

When you're code is merged in, it creates this object:

code: {
  color: defaultTheme.colors.gray[900],
  fontWeight: '600',
  '&::before': {
    content: '""',
  },
  '&::after': {
    content: '""',
  },
},
'code::before': {
  content: '"`"',
},
'code::after': {
  content: '"`"',
},

So when it's all flattened out, our existing code::before and code::after selectors win. This is sort of a tough one to figure out how to "fix" because the current behavior is actually really useful for lots of situations, so we might just want to figure out a way to let the user control this more finely.

Going to close this for now since there's a solution (use our keys) and I can't say for sure we are going to take action on it.

@nad-au
Copy link

nad-au commented Jul 28, 2020

Hello, we have the same problem in that all our inline code is showing backticks, which we don't want. You mentioned that you have a solution: use our keys. Please can you explain this? I've gone through all the above and we still see backticks everywhere.

@nad-au
Copy link

nad-au commented Jul 28, 2020

Apologies, I made a mistake in the tailwind.config.js. This is working for me now:

// tailwind.config.js
module.exports = {
  theme: {
    typography: {
      default: {
        css: {
          'code::before': {
            content: '""',
          },
          'code::after': {
            content: '""',
          },
        },
      },
    },
  },
  plugins: [require("@tailwindcss/typography")],
};

@alexellis
Copy link

@Waterdrips ☝️ this should do the trick?

@MoSattler
Copy link

MoSattler commented Nov 24, 2020

This did not work for me (TW2.0) - when I was adding this to my tailwind config, it completely broke all styles.
I had to add a small change, and it worked

// tailwind.config.js
module.exports = {
  theme: {
    extend: {
      typography: {
        DEFAULT: {
          css: {
            'code::before': {
              content: '""'
            },
            'code::after': {
              content: '""'
            }
          }
        }
      },
    },
  },
  plugins: [require("@tailwindcss/typography")],
};

@Panda-Program-Web
Copy link

For v3, this works for me.

#135 (comment)

@almai
Copy link

almai commented Oct 17, 2022

I know, I'm a little bit late to the party. But in case someone is interested in this. You can suppress the backticks with prose-code:before:hidden prose-code:after:hidden

cuihtlauac pushed a commit to ocaml/ocaml.org that referenced this issue Nov 14, 2022
By default taiwind css surounds inline code with backticks. In
order to have a more GitHub-like experience, as suggested by
@MisterDA in #612 the
tailwind configuration needs to be changed as explained here:

tailwindlabs/tailwindcss-typography#18
tmattio added a commit to ocaml/ocaml.org that referenced this issue Nov 15, 2022
* Remove backticks around inline code fragments

By default, TailwindCSS surrounds inline code with backticks. In
order to have a more GitHub-like experience, as suggested by
@MisterDA in #612 the
tailwind configuration needs to be changed as explained here:

tailwindlabs/tailwindcss-typography#18

Co-authored-by: Cuihtlauac ALVARADO <cuihtmlauac@tarides.com>
Co-authored-by: Thibaut Mattio <thibaut.mattio@gmail.com>
@peterhijma
Copy link

I know, I'm a little bit late to the party. But in case someone is interested in this. You can suppress the backticks with prose-code:before:hidden prose-code:after:hidden

But not too late! Thanks!

@steven-tey
Copy link

I know, I'm a little bit late to the party. But in case someone is interested in this. You can suppress the backticks with prose-code:before:hidden prose-code:after:hidden

This did the trick! Thank you!

@JosiahParry
Copy link

prose-code:before:hidden prose-code:after:hidden

This worked! Thank you so much!!!!

@LamNguyenz
Copy link

I know, I'm a little bit late to the party. But in case someone is interested in this. You can suppress the backticks with prose-code:before:hidden prose-code:after:hidden

Thanks, you save my life

@kerryj89
Copy link

kerryj89 commented Feb 5, 2025

These classes didn't work for me in v4. Here is what I used instead to kill it from the root:

@utility prose {
  code {
    &::before,
    &::after {
      content: none;
    }
  }
}

@sergiodantasz
Copy link

Perfect, @kerryj89. I'm using v4 too, it worked well.

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