pretty-print

Overloading output operator for arrays

北城以北 提交于 2019-12-23 07:38:27
问题 According to this answer, the correct way to overload output operator << for C-style arrays is this -: #include <iostream> using namespace std; template <size_t arrSize> std::ostream& operator<<( std::ostream& out, const char( &arr )[arrSize] ) { return out << static_cast<const char*>( arr ); // use the original version } // Print an array template<typename T1, size_t arrSize> std::ostream& operator <<( std::ostream& out, const T1( & arr )[arrSize] ) { out << "["; if ( arrSize ) { const char*

Source code pretty printer with DocBook or XML output?

邮差的信 提交于 2019-12-23 00:29:31
问题 Is there some source code pretty printer out there that is able to generate DocBook, or at least XML output from my C sources? I want to include some good looking source code examples in my DocBook document. 回答1: I'm not sure what you mean by a pretty-printer that generates XML, but if you want code examples in DocBook documents to be nicely colourized when transformed to HTML or FO/PDF output, take a look at XSLTHL. This is an XSLT extension module (written in Java) that decorates the

Node.toprettyxml() adds newlines to DOCTYPE in Python

ⅰ亾dé卋堺 提交于 2019-12-22 08:18:41
问题 When using prettify my DOCTYPE is broken into three lines. How can I keep it on one line? The "broken" output: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE smil PUBLIC '-//W3C//DTD SMIL 2.0//EN' 'http://www.w3.org/2001/SMIL20/SMIL20.dtd'> <smil xmlns="http://www.w3.org/2001/SMIL20/Language"> <head> <meta base="rtmp://cp23636.edgefcs.net/ondemand"/> </head> <body> <switch> <video src="mp4:soundcheck/1/clay_aiken/02_sc_ca_sorry_256.mp4" system-bitrate="336000"/> <video src="mp4:soundcheck/1

Pretty HTML snippet output

回眸只為那壹抹淺笑 提交于 2019-12-22 04:01:06
问题 I've a snippet of HTML <div><p>text1</p></div><div><p>text1</p></div> I want to make it pretty like this <div> <p>text1</p> </div> <div> <p>text1</p> </div> What would be most simple way to do it? (I've looked on transform and jsoup) but not sure what would be really smart to use. Thanks! 回答1: jTidy could fit for this task - http://jtidy.sourceforge.net/howto.html public String prettyPrintHTML(String rawHTML) { Tidy tidy = new Tidy(); tidy.setXHTML(true); tidy.setIndentContent(true); tidy

Pretty printing XML with Jackson library

北城余情 提交于 2019-12-22 03:40:47
问题 I am trying to use Jackson library to serialize Java objects into XML by using JAXB annotations. However, I face an issue in pretty-printing the XML output. Here is my sample code usage: ObjectMapper mapper = new XmlMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); String xml = mapper.writeValueAsString(person); And, I'm seeing the below exception. The issue here is Jackson uses Stax2Writer as XML writer and Stax2 doesn't seem to support writing raw strings (in this case

how to pretty print source code of common languages in browser html output with javascript?

我怕爱的太早我们不能终老 提交于 2019-12-21 13:35:33
问题 how to pretty print source code of common languages in browser html output with javascript? I mean so that there is some indentation and code formatting. Currently i only got http://alexgorbatchev.com/SyntaxHighlighter/ for coloring the syntax. But i would also like some indentation and other formatting. Example: user puts in some code. system formats and highlights code in the browser view. so-> is there a general code formatter for formatting code? best in javascript I am grateful for any

Pretty-print haskell source code with comments

不羁岁月 提交于 2019-12-21 10:15:05
问题 I'm trying to reformat/reprint haskell source code (remove/add whitespace, linebreaks, change indention style...). I've found the package haskell-src-exts which can parse and pretty-print haskell source code. Using the function parseFileWithComments :: ParseMode -> FilePath -> IO (ParseResult (Module, [Comment])) I also get the comments included in the source code. Now I want to print the Module/AST with the comments at the original positions, but I cannot find a function which will do that.

How do I pretty-print productions and line numbers, using ANTLR4?

我的梦境 提交于 2019-12-21 04:27:08
问题 I'm trying to write a piece of code that will take an ANTLR4 parser and use it to generate ASTs for inputs similar to the ones given by the -tree option on grun ( misc.TestRig ). However, I'd additionally like for the output to include all the line number/offset information. For example, instead of printing (add (int 5) '+' (int 6)) I'd like to get (add (int 5 [line 3, offset 6:7]) '+' (int 6 [line 3, offset 8:9]) [line 3, offset 5:10]) Or something similar. There aren't a tremendous number

Showing a Haskell list of tuples with custom syntax

点点圈 提交于 2019-12-20 04:22:47
问题 I have a list of tuples [(1,'a','%',"yes"),(2,'b','[',"no"),(3,'c',']',"ok")] . How can I show this list as output in the form of [(1,a,%,yes),(2,b,[,no),(3,c,],ok)] ? 回答1: Looks like the transformation you wish to make is to strip out quote characters? If so, filtering the results of calling show on your data will be enough: > let x = [(1,'a','%',"yes"),(2,'b','[',"no"),(3,'c',']',"ok")] Then apply a filter, > putStrLn . filter (`notElem` "'\"") . show $ x [(1,a,%,yes),(2,b,[,no),(3,c,],ok)]

XML pretty print fails in Python lxml

一个人想着一个人 提交于 2019-12-20 03:42:09
问题 I am trying to read, modify, and write an XML file with lxml 4.1.1 in Python 2.7.6. My code: import lxml.etree as et fn_xml_in = 'in.xml' parser = et.XMLParser(remove_blank_text=True) xml_doc = et.parse(fn_xml_in, parser) xml_doc.getroot().find('b').append(et.Element('c')) xml_doc.write('out.xml', method='html', pretty_print=True) The input file in.xml looks like this: <a> <b/> </a> And the produced output file out.xml : <a> <b><c></c></b> </a> Or when I set remove_blank_text=True : <a><b><c>