Skip to content

Code block: Add line numbers #116

Description

@falldowngoboone

Part of #122.

Looks like there's an issue with the Eleventy syntax highlighting plugin. I can add numbers by wrapping every line in a highlight:

// .eleventy.js
eleventyConfig.addPlugin(syntaxHighlighting, {
  alwaysWrapLineHighlights: true,
});

Then I can use the resulting spans to add numbers via CSS counters:

// _vendor-prism-fdgb.scss

pre {
  counter-reset: lineNumber;
}
code .highlight-line:before {
  -webkit-user-select: none;
  border-right: 1px solid #404040;
  color: #858585;
  content: counter(lineNumber);
  counter-increment: lineNumber;
  display: inline-block;
  font-variant-numeric: tabular-nums;
  margin-right: 1.2em;
  padding-right: 1.2em;
  text-align: right;
  width: 2.4em;
}

However, the issue is some brs are being wrapped in a new span, causing the line highlighting to get all fouled up. I've seen this issue so far in scss blocks with a break between selectors:

input:invalid,
[aria-invalid=true] {
  border-color: hsl(351, 100%, 27%);
}

Incorrect formatting of CSS multiple-line selector list

html blocks that break to multiple lines:

<input id="password" type="password" name="password" 
        aria-describedby="password-error" />

Incorrect formatting of multiple line input

jsx blocks with nested JavaScript in brackets:

export default function List({ items = [] }) {
  return (
    <ul class="styled-list">
      {Boolean(items.length) &&
        items.map((item) => <li class="styled-item" {...item} />)}
    </ul>
  );
}

Incorrect formatting of returned JSX block with nested JavaScript

I've noticed changing jsx to js fixes that issue. Not sure about the rest. I would love to have line numbers, but I'm not sure that's currently possible with the Eleventy plugin.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestwontfixThis will not be worked on

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions