简体   繁体   English

重新格式化JavaScript功能以进行打印

[英]Reformatting a javascript function for printing

So, deciding to be right on the edges of my competency, I have decided to give Nashorn a try, because I have a use case where it would be useful to allow user the ability to write their own filters for a Java app. 因此,我决定尝试自己的能力,决定尝试Nashorn,因为我有一个用例,在这种情况下,使用户能够为Java应用程序编写自己的过滤器将非常有用。

I can pretty much make everything work end to end (web page with textarea -> saved Couchbase object -> script engine within Java), but for the UI piece I would like to be able to prettify/format the user defined text field (not necessarily in real time, but maybe upon saving). 我几乎可以使一切工作都端到端(带有textarea的网页->保存的Couchbase对象-> Java中的脚本引擎),但是对于UI块,我希望能够美化/格式化用户定义的文本字段(而不是一定是实时的,但可能需要保存)。

I originally thought it would be relatively simple to use JSON.stringify, but apparently life isn't that convenient. 我原本以为使用JSON.stringify会相对简单,但是显然生活并不那么方便。 Is there a javascript native/library based approach to taking the string representation of a function and applying lipstick to my user generated pigs? 是否有基于javascript本机/库的方法来获取函数的字符串表示形式并将口红应用于用户生成的猪?

Dave 戴夫

http://jsbeautifier.org library will format your javascript functions. http://jsbeautifier.org库将格式化您的JavaScript函数。 JSON.stringify 3rd argument allows you to pretty up your JSON. JSON.stringify第3个参数允许您修饰JSON。

You can use the js-beautify module that does the beautifying at http://jsbeautifier.org . 您可以在http://jsbeautifier.org上使用进行美化js-beautify模块。 Usage: 用法:

var beautifiedJsString = js_beautify('[YourJsString]', options);

List of options here . 选项列表在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM