prism-react-renderer icon indicating copy to clipboard operation
prism-react-renderer copied to clipboard

1.1.0 -> 1.1.1 breaks Python highlighting in Docusaurus

Open slorber opened this issue 5 years ago • 5 comments

Hi,

Docusaurus (v2) uses this project for syntax highlighting.

https://v2.docusaurus.io/docs/theme-classic/#codeblock


Let's take this code:

@dataclass
class MySQLConfig:
    host: str = "localhost"
    port: int = 3306

@dataclass
class Config:
    db: MySQLConfig = MySQLConfig()
    verbose: bool = True

cfg_store = ConfigStore.instance()
cfg_store.store(name="config", node=MyConfig)

@hydra.main(config_name="config")
def my_app(cfg: MyConfig) -> None:
    # Python knows that the type of cfg.db is MySQLConfig without any additional hints
    print(f"Host: {cfg.db.host}, port: {cfg.db.port}")

if __name__ == "__main__":
    my_app()

When using:

  "resolutions": {
    "prism-react-renderer": "1.1.0"
  },

Python highlighting works fine for this code:

image


But when using newest version, highlighting is missing for things like decorators (or applied partially):

  "resolutions": {
    "prism-react-renderer": "1.1.1"
  },

image


@kitten as you proposed your help already here: https://github.com/facebook/docusaurus/pull/2666#issuecomment-619602671 wonder if you can help me figure out what's happening.

The code does not seems to change much from 1.1.0 to 1.1.1 so I don't understand.

Anything I don't see in the commits?

Do you think this might affect other languages as Python, and that we should temporarily lock users to 1.1.0?

slorber avatar Jun 29 '20 17:06 slorber

@slorber This may be happening because of a change in the Prism version that's bundled... have you tried a custom version of prismjs instead? if a newer one works I can release a quick patch with an upgrade

kitten avatar Jun 29 '20 18:06 kitten

How can I use or upgrade prism? Should I just hack in the node_modules/prism-react-renderer/prism folder?

slorber avatar Jun 29 '20 18:06 slorber

You can pass in a different instance of Prism as a prop: https://github.com/FormidableLabs/prism-react-renderer#advanced-props

kitten avatar Jun 29 '20 20:06 kitten

Thanks.

How can I know which version is currently vendored in this lib?

The package says "prismjs": "^1.20.0", and it does seem to have changed, and it's the latest version of Prism anyway. Is this the version vendored here?

Here's a PR that fixes a Docusaurus site: https://github.com/facebookresearch/hydra/pull/730/files#diff-133739a86bc2f5157391e0018e5f9d01R7409

The yarn lock versions of prism is still the same before/after

slorber avatar Jun 30 '20 11:06 slorber

Hm, that's odd, it should indeed still be 1.20.0. I may have to look into this a little further

kitten avatar Jun 30 '20 20:06 kitten

Closing, we are using a much newer version of prismjs

carbonrobot avatar Feb 07 '24 15:02 carbonrobot