GithubHelp home page GithubHelp logo

Comments (9)

SomeshThakur avatar SomeshThakur commented on May 26, 2024 1

The attached image is the desired output that needs to be achieved.
Surely the <ol> approach looks more appropriate than adding numbers to HTML. (that will require programmatically counting).

I did an experimental rough code here to achieve the image output in the above comment. (definitely not the final code)

Changes in pretty-print-json.ts

const addLineNum = s => {
      let count = 1;
     // Prepend count as first line doesn't have '\n', 
      return `${count} ${s.replace(/\n/g, () => `\n${++count} `)}`;
};

And then use it as

const result = htmlEntities(json).replace(jsonLine, replacer);
return settings.lineNumber ? addLineNum(result) : result;

from pretty-print-json.

dpilafian avatar dpilafian commented on May 26, 2024 1

Dark mode for line numbers:
interactive

from pretty-print-json.

dpilafian avatar dpilafian commented on May 26, 2024 1

The CSS for the project is designed to be simple to override and customize to fit any design. The recent 5c2298f commit refactored the colors into their own section to make custom theming even easier (in the future it might make sense to have a separate theme folder with a variety of color palettes).

Since the amount of CSS is small and designs vary significantly, I suspect many developers will just copy-n-paste the few CSS lines they need. It seems more convenient to have the line highlighting CSS there than not there.

from pretty-print-json.

dpilafian avatar dpilafian commented on May 26, 2024

You mean prepend each line of HTML with something like:

<span class=line-num>1</span>

Can you add an example of what the output would be to support line numbers?

from pretty-print-json.

SomeshThakur avatar SomeshThakur commented on May 26, 2024

Yes prepend each line with a number (can be a span)

I worked on it already, here is the output:

image

from pretty-print-json.

dpilafian avatar dpilafian commented on May 26, 2024

Oops, I meant the HTML output not the screen output. My bad.

For example, the original HTML:

<span class=json-mark>[</span>
   <span class=json-string>"🐈"</span>
<span class=json-mark>]</span>

could be enhanced with line numbers like this:

<span class=line-number>1</span><span class=json-mark>[</span>
<span class=line-number>2</span>   <span class=json-string>"🐈"</span>
<span class=line-number>3</span><span class=json-mark>]</span>

Another possibility that has arguably better semantics is:

<ol class=json-lines>
   <li><span class=json-mark>[</span></li>
   <li>   <span class=json-string>"🐈"</span></li>
   <li><span class=json-mark>]</span></li>
</ol>

The <ol> approach seems more semantically correct, but it might be more difficult to style. An advantage of the <ol> approach is that it would support line highlighting.

For example:

ol.json-lines >li:nth-child(odd)  { background-color: honeydew; }
ol.json-lines >li:nth-child(even) { background-color: aliceblue; }

from pretty-print-json.

dpilafian avatar dpilafian commented on May 26, 2024

Let's go with the <ol> approach.

Since there will be multiple lines, the plural form lineNumbers is probably the way to go.

from pretty-print-json.

SomeshThakur avatar SomeshThakur commented on May 26, 2024

I feel plain output without lines highlighting was better.

from pretty-print-json.

SomeshThakur avatar SomeshThakur commented on May 26, 2024

The feature has been implemented so, closing the issue.

from pretty-print-json.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.