Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an optional function for custom formatting #17

Open
ChrisCinelli opened this issue Apr 21, 2016 · 2 comments
Open

Add an optional function for custom formatting #17

ChrisCinelli opened this issue Apr 21, 2016 · 2 comments

Comments

@ChrisCinelli
Copy link

ChrisCinelli commented Apr 21, 2016

I would like to be able for example to display ok in green in {"status": "ok"} and error in red in {"status": "error"}.

I think we could have an optional format field in config with a callback that has value and type as arguments. The return value can alter the output (maybe adding a CSS class).

@aj599t
Copy link

aj599t commented Jun 29, 2017

ALso, the CSS for the values in the json. Currently, json-formatter-string class has a property white-space: pre which prevent wrapping the content. Can this issue be addressed?

@mohsen1
Copy link
Owner

mohsen1 commented Jul 6, 2019

@aj599t with the proposed API it should be possible. What I'm thinking is this:

function format(type: string, value: string, node: HTMLSpanElement): HTMLSpanElement {
  // Here you can apply styles or append classes to the element
  // or even inject new elements inside the span

  node.classList.add('myClass');
  node.style.fontSize = '12px'
  const span = document.createElement('span');
  span.innerText = 'hi';
  node.appendChild(span);
  return node;
}

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

No branches or pull requests

3 participants