Skip to content

This repository contains the `<line-numbers>` web component, designed to enhance code readability in `<pre>` and `<textarea>` elements. Explore the demo and npm package to see how it can streamline your projects! 🐙✨

License

Notifications You must be signed in to change notification settings

iamnakajim/line-numbers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Line Numbers Component 📏

Version License GitHub Release

Welcome to the Line Numbers repository! This project offers a web component that adds line numbers next to various HTML elements. It's perfect for developers looking to enhance code readability or for anyone who needs to display numbered lines in their web applications.

Table of Contents

Features

  • Easy integration into existing HTML structures.
  • Lightweight and efficient.
  • Supports various HTML elements like <div>, <pre>, and more.
  • Customizable styles for line numbers.
  • Responsive design to fit different screen sizes.

Installation

To get started, you need to download the latest release. Visit the releases page to find the necessary files. Download and execute the component in your project.

Usage

After downloading the component, you can easily integrate it into your HTML. Here’s a simple example:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Line Numbers Example</title>
    <link rel="stylesheet" href="path/to/line-numbers.css">
</head>
<body>
    <div class="line-numbers">
        <pre>
            function helloWorld() {
                console.log("Hello, World!");
            }
        </pre>
    </div>
    <script src="path/to/line-numbers.js"></script>
</body>
</html>

This code snippet shows how to include the line numbers component in your project. Make sure to adjust the paths to your local files.

Customization

You can customize the appearance of the line numbers by modifying the CSS. Here are some common styles you might want to change:

.line-numbers {
    counter-reset: line;
}

.line-numbers pre {
    position: relative;
}

.line-numbers pre::before {
    counter-increment: line;
    content: counter(line);
    position: absolute;
    left: -30px; /* Adjust as needed */
    color: #888; /* Change color */
}

Feel free to adapt these styles to match your project's design.

Examples

Basic Example

This example demonstrates a simple usage of the line numbers component with a code block.

<div class="line-numbers">
    <pre>
        // Sample code
        function add(a, b) {
            return a + b;
        }
    </pre>
</div>

Advanced Example

In this advanced example, we will use the component alongside a styled HTML table.

<div class="line-numbers">
    <table>
        <thead>
            <tr>
                <th>Item</th>
                <th>Quantity</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Apples</td>
                <td>5</td>
            </tr>
            <tr>
                <td>Oranges</td>
                <td>10</td>
            </tr>
        </tbody>
    </table>
</div>

This example shows how you can use line numbers with different HTML elements.

Contributing

We welcome contributions! If you would like to help improve the project, please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes.
  4. Submit a pull request.

Make sure to include tests for your changes and update the documentation as needed.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contact

For questions or suggestions, feel free to reach out:

Thank you for checking out the Line Numbers project! For the latest updates and releases, visit the releases page. Your feedback is always welcome!

About

This repository contains the `<line-numbers>` web component, designed to enhance code readability in `<pre>` and `<textarea>` elements. Explore the demo and npm package to see how it can streamline your projects! 🐙✨

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •