8000 Highlight lines without specifying a language · Issue #55 · timlrx/rehype-prism-plus · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Highlight lines without specifying a language #55
Open
@talatkuyuk

Description

@talatkuyuk

When I write down a code block without specifying any language but put line numbers for highlighting like below:

```{2}

it is interpreted as the language is language-{2}.

I know the documentation says that :

Note: This will wrongly assign a language class and the class might appear as language-{1,3} or language-showLineNumbers, but allow the language highlighting and line number function to work. An possible approach would be to add a placeholder like unknown so the div will have class="language-unknown"

I see in the playground that the above code produces the below AST (the rest is omitted)

{
  "type": "code",
  "lang": "{2}",
  "meta": null,
}

Is it possible to put a logic in the plugin like below as a pseudo code:

  • Check if the lang starts with "{"
    • if the meta is null then copy the content of the lang into the meta and make the lang is "unknown" or null,
    • if the meta is not null then prepend the lang into the meta and make the lang again "unknown" or null,

Here is two AST examples before and after :

// ```{2}

// before
{
  "type": "code",
  "lang": "{2}",
  "meta": null,
}

// after
{
  "type": "code",
  "lang": "unknown", // or null, I could not figure out which is better
  "meta": "{2}",
}
// ```{2} showLineNumbers

// before
{
  "type": "code",
  "lang": "{2}",
  "meta":"showLineNumbers,
}

// after
{
  "type": "code",
  "lang": "unknown", // or null, I could not figure out which is better
  "meta": "{2} showLineNumbers",
}

Then maybe we can highlight any line without specifying any language or without the text unknown as a dummy language.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0