Comments (9)
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.
from pretty-print-json.
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.
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.
Yes prepend each line with a number (can be a span)
I worked on it already, here is the output:
from pretty-print-json.
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.
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.
I feel plain output without lines highlighting was better.
from pretty-print-json.
The feature has been implemented so, closing the issue.
from pretty-print-json.
Related Issues (20)
- Switch task object to es6 object function notation
- Make links clickable HOT 1
- Add support for JSON5 HOT 1
- Upgrade to ES6 spread operator to merge options
- Code cleanup, whitespace issues, introduce prettier? HOT 4
- Travis/Azure/Actions pipeline?
- Switch to trailing comma style in spec/mocha.js HOT 3
- Switch to ES6 object method shorthand in spec/interactive.html
- Add JSHint rule to disallow var declarations HOT 1
- Add JSHint rule to disallow invalid space characters
- 0.4.3 and 0.4.4 are broken for dynamic import HOT 2
- add changelog HOT 2
- Undefined import: prettyPrintJson HOT 6
- Option to enable more compact layout for small objects and arrays HOT 3
- Trouble with properly formatting array in JSON object HOT 2
- Key order not preserved HOT 2
- URL query param support HOT 1
- Toggle dark mode with `prefers-color-scheme` by default
- Add Option for linkUrls for target='_blank' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pretty-print-json.