pretty-print

Which pretty print library? [closed]

冷暖自知 提交于 2019-12-03 06:30:15
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . So from a glance at hackage I can see 5 pretty printing libraries: good old HughesPJ in pretty wl-pprint-extras wl-pprint-terminfo wl-pprint ansi-wl-pprint wl-pprint-text Oh wait, was that 6? 6 pretty printing libraries... no wait, we'll come in again. Anyway, they're all Wadler-Leijen except of course HughesPJ.

pretty print to a file in ruby

こ雲淡風輕ζ 提交于 2019-12-03 05:34:14
I am trying to pretty print a hash to a file. I tried unix redirects [added different flags to it incrementally] : `echo #{pp mymap} | tee summary.out 2>&1` and File IO my_file = File.new(@dir_+"/myfile.out",'w+') my_file.puts `#{pp get_submap_from_final(all_mapping_file,final_map)}` It always prints to console and doesnt write to a file. Also there has to be an easier way to write to file in one line in ruby ? instead of doing File.new and then writing to a file ? Huy Le require 'pp' File.open("test.txt","w") do |f| PP.pp(self,f) end The use of backticks here is perplexing since those are

Formatting Ruby's prettyprint

*爱你&永不变心* 提交于 2019-12-03 05:26:00
问题 Is it possible to change the width that prettyprint ( require 'pp' ) uses when formatting output? For example: "mooth"=>["booth", "month", "mooch", "morth", "mouth", "mowth", "sooth", "tooth"] "morth"=>["forth", "mirth", "month", "mooth", "morph", "mouth", "mowth", "north", "worth"] The first array is printed inline because it fits within the column width prettyprint allows (79 characters)... the second is split onto multiple lines, because it does not. But I can find no method for changing

Prettyprint to a file?

两盒软妹~` 提交于 2019-12-03 04:33:50
I'm using this gist's tree, and now I'm trying to figure out how to prettyprint to a file. Any tips? What you need is Pretty Print pprint module: from pprint import pprint # Build the tree somehow with open('output.txt', 'wt') as out: pprint(myTree, stream=out) If I understand correctly, you just need to provide the file to the stream keyword on pprint : with open(outputfilename,'w') as fout: pprint(tree,stream=fout,**other_kwargs) 来源: https://stackoverflow.com/questions/17280534/prettyprint-to-a-file

Nice bit of code to format an xml string

亡梦爱人 提交于 2019-12-03 03:01:08
Anyone got a ready made function that will take an XML string and return a correctly indented string? eg <XML><TAG1>A</TAG1><TAG2><Tag3></Tag3></TAG2></XML> and will return nicely formatted String in return after inserting linebreaks and tabs or spaces? The RTL has FormatXMLData in XMLDoc.pas that accepts and returns strings. Using OmniXML : program TestIndentXML; {$APPTYPE CONSOLE} uses SysUtils, OmniXML, OmniXMLUtils; function IndentXML(const xml: string): string; var xmlDoc: IXMLDocument; begin Result := ''; xmlDoc := CreateXMLDoc; if not XMLLoadFromAnsiString(xmlDoc, xml) then Exit; Result

best way to implement custom pretty-printers

自作多情 提交于 2019-12-03 01:27:21
Customizing pprint.PrettyPrinter The documentation for the pprint module mentions that the method PrettyPrinter.format is intended to make it possible to customize formatting. I gather that it's possible to override this method in a subclass, but this doesn't seem to provide a way to have the base class methods apply line wrapping and indentation. Am I missing something here? Is there a better way to do this (e.g. another module)? Alternatives? I've checked out the pretty module, which looks interesting, but doesn't seem to provide a way to customize formatting of classes from other modules

Pretty Printing AST with Minimal Parentheses

梦想的初衷 提交于 2019-12-02 23:49:32
I'm implementing a pretty-printer for a JavaScript AST and I wanted to ask if someone is aware of a "proper" algorithm to automatically parenthesize expressions with minimal parentheses based on operator precedence and associativity . I haven't found any useful material on the google. What seems obvious is that an operator whose parent has a higher precedence should be parenthesized, e.g.: (x + y) * z // x + y has lower precedence However, there are also some operators which are not associative, in which case parentheses are still are needed, e.g.: x - (y - z) // both operators have the same

Which pretty print library? [closed]

主宰稳场 提交于 2019-12-02 20:03:27
Closed. This question is off-topic. It is not currently accepting answers. Learn more . Want to improve this question? Update the question so it's on-topic for Stack Overflow. So from a glance at hackage I can see 5 pretty printing libraries: good old HughesPJ in pretty wl-pprint-extras wl-pprint-terminfo wl-pprint ansi-wl-pprint wl-pprint-text Oh wait, was that 6? 6 pretty printing libraries... no wait, we'll come in again. Anyway, they're all Wadler-Leijen except of course HughesPJ. My understanding is that WL is simpler and faster, so is probably preferred for new code. wl-pprint and wl

How to print from GitHub

天涯浪子 提交于 2019-12-02 13:58:29
If I want to print a markdown file from GitHub as it appears on screen, for example: https://github.com/RestKit/RestKit/blob/master/Docs/Object%20Mapping.md Then how can I accomplish that? What code do I need to change in the resulting github html page (that I save) such that the printout will honor the look & feel of the markdown? So far the only clue I have is this one: https://makandracards.com/makandra/4947-how-to-print-github-wiki-pages But it is more of a utilitarian (non-programmatic) workaround which doesn't really work because the markdown interpreter in use isn't as forgiving as the

Tab and pre wrapped around JSON output in Chrome

落爺英雄遲暮 提交于 2019-12-02 08:38:51
I am using this simple code to print an array as a JSON structure. header('Content-Type: application/json'); echo json_encode($this->data, JSON_PRETTY_PRINT); I'm using Chrome Version 28.0.1500.95 m. For some odd reason the output is wrapped in a pre tag with a tab character (i.e. \t ) at the beginning. JSON seems to be parsing okay but I still get that tab character when no data is sent. How can I fix this ? <pre style="word-wrap: break-word; white-space: pre-wrap;"> { "title": "Node", "items": [ { "label": "Do stuff", "icon": "..\/ui\/images\/icons\/16x16\/icon.png", "action": "dostuff" } ]