PrismJS / PrismJS/prism

linenumbers grouped to actual lines in sourcecode

Open
#1,469 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement plugins
Dominant language
JavaScript
Stars
13k
Forks
1.4k
Avg merge
15h 36m
Merged PRs (30d)
3

Description

i had trouble with proper aligning of linenumbers and the actual code and tried to fix the css, but with limited sucess.

after some hours of trail and error i quit the approach and fixed it with the given solution:

Prism.languages.insertBefore('plsql','keyword',{
    aline: {
        pattern: /(.*)\n/,
        inside: Prism.languages.plsql,
        greedy: true

    }
} )

with this little language extention is was able to encapsulate lines with spans to represent actual lines.

this approach brought a couple of advantages. it could use a per line hightligthing on hover with:

.aline:hover {
    background-color: #222;
}

and added the linenumbers to the .aline elements:

pre.line-numbers .aline::before  {
    content: counter(lines);
    counter-increment: lines;
    position: absolute;
    left: 0em;
    text-align: right;
    display: block;
    width: 2em;
    padding-right: .3em;
    border-right: 1px solid;
    height: 100%;
    background-color: black;
}

pre.line-numbers .aline::after  {
    content: "⤷";
    font-size: 16px;
    position: absolute;
    left: -0.3em;
    text-align: right;
    display: block;
    width: 2em;
    height: 1em;
    top: 14px;
}

then downside of this approach is the mixing of the token elements and misuse of the token aline.
on the upside, this approach yield way better results, than the current line number plugin.

is there any chance, that we might reconsider the prism architecture to incorperate the grouped lines for better styling options?

an example screenshot:
example

PS: i love your project, thank you every much for the ongoing effort!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing Prism's tokenization architecture and the current line number plugin, as well as the proposed CSS for grouped lines. Define whether source lines can be grouped without misusing token elements, then verify that line numbering and per-line styling work correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
css, javascript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.