Creates a pretty formatted version of doc. Note: does not remove line breaks!

@param doc
@return
436173
public static Node normalizeFormatting(final Node doc) throws CouldNotProcessException {
        try {
            return createDocumentFromString(normalizeFormattingAsString(doc));
        } catch (XMLParsingException ex) {
            throw new CouldNotProcessException("Couldn't normalize formatting. Returning old document.", ex);
        }
    }
726729
public Document buildPage(Map<String, Object> content) {
    Document doc = documentBuilder.newDocument();
    Element jcrRoot = createJcrRoot(doc, NT_PAGE);
    Element jcrContent = createJcrContent(doc, jcrRoot, NT_PAGE_CONTENT);

    exportPayload(doc, jcrContent, content);

    return doc;
  }
337339
public static Document toDocument(JAXBElement<?> jaxbElement,
			boolean prettyPrint) {

		Document document = null;

		try {
			DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
					.newInstance();
			documentBuilderFactory.setNamespaceAware(true);
			documentBuilderFactory.setIgnoringElementContentWhitespace(true);
			documentBuilderFactory.isIgnoringComments();
			documentBuilderFactory.setCoalescing(true);

			document = documentBuilderFactory.newDocumentBuilder()
					.newDocument();

			String packName = jaxbElement.getDeclaredType().getPackage().getName();
			JAXBContext jaxbContext;
			if (packName.startsWith("org.mitre")){
				jaxbContext = stixJaxbContext();
			} else {
				jaxbContext = JAXBContext.newInstance(packName);
			}

			Marshaller marshaller = jaxbContext.createMarshaller();

			marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
					prettyPrint);

			marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");

			try {
				marshaller.marshal(jaxbElement, document);
			} catch (JAXBException e) {
				// otherwise handle non-XMLRootElements
				QName qualifiedName = new QName(
						STIXSchema.getNamespaceURI(jaxbElement), jaxbElement
								.getClass().getSimpleName());

				@SuppressWarnings({ "rawtypes", "unchecked" })
				JAXBElement root = new JAXBElement(qualifiedName,
						jaxbElement.getClass(), jaxbElement);

				marshaller.marshal(root, document);
			}

			removeUnusedNamespaces(document);

		} catch (ParserConfigurationException e) {
			throw new RuntimeException(e);
		} catch (JAXBException e) {
			throw new RuntimeException(e);
		}

		return document;
	}
791363
def doc_to_lines(self, doc, format_func=None):
        
        if format_func:
            for l in format_func(doc).splitlines():
                yield l
        elif self.pretty_print:
            for l in pprint.pformat(doc).splitlines():
                yield l
        else:
            for l in str(doc).splitlines():
                yield l
1042177
public static String toStr(Document doc, String charset, boolean isPretty) {
		final StringWriter writer = StrUtil.getWriter();
		try {
			write(doc, writer, charset, isPretty ? INDENT_DEFAULT : 0);
		} catch (Exception e) {
			throw new UtilException(e, "Trans xml document to string error!");
		}
		return writer.toString();
	}
752172
public static String convertDOMToXML(Node doc)
    {
        StringWriter out = new StringWriter();
        Util.convertDOMToXML(doc, out);
        return out.toString();
    }
292673
protected void _format(SarlAgent agent, IFormattableDocument document) {
		formatAnnotations(agent, document, XbaseFormatterPreferenceKeys.newLineAfterClassAnnotations);
		formatModifiers(agent, document);

		final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(agent);
		document.append(regionFor.keyword(this.keywords.getAgentKeyword()), ONE_SPACE);

		document.surround(regionFor.keyword(this.keywords.getExtendsKeyword()), ONE_SPACE);
		document.format(agent.getExtends());

		formatBody(agent, document);
	}
112985
public static String format(final String xml) {
        try {
            final DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            final Document doc = db.parse(new InputSource(new StringReader(xml)));
            final Transformer transformer = TransformerFactory.newInstance().newTransformer();
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
            final StreamResult result = new StreamResult(new StringWriter());
            final DOMSource source = new DOMSource(doc);
            transformer.transform(source, result);

            return result.getWriter().toString();
        } catch (final Exception e) {
            LOGGER.log(Level.WARN, "Formats pretty XML failed: " + e.getMessage());

            return xml;
        }
    }
1016261
function (doc) {
        [
            'Returns',
            'Emits',
            'Access',
            'Kind'
        ].forEach(function removeLine(preTag) {
            preTag = '**' + preTag;

            var start = doc.indexOf(preTag);
            if (start !== -1) {
                var end = doc.indexOf('\n', start) + 1;

                doc = doc.substring(0, start) + doc.substring(end);
            }
        });

        return doc;
    }
194006
private static function clean($doc)
    {
        if ($doc === null) {
            return null;
        }

        $result = null;
        $lines = preg_split('/\r/', $doc);
        foreach ($lines as $line) {

            $line = preg_replace('/^\s*\* /', '', trim($line, "\n/* \t\x0B\0"));
            if ($line === '') {
                continue;
            }

            if ($result != null) {
                $result .= ' ';
            }
            $result .= $line;
        }

        return $result;
    }
304497
private InputStream formatRawContent(final Document document) throws IOException {
        final String body = "<h1>" + escapeAndAddLineBreaks(resolveTitle(document)) + "</h1>"
                + "<p>" + escapeAndAddLineBreaks(document.getContent()) + "</p>";

        return IOUtils.toInputStream(body, StandardCharsets.UTF_8);
    }
1315614
@SuppressWarnings("unchecked")
    protected Map<String, byte[]> documentToBytesMap(Map<String, Object> doc) {
        if (doc == null || doc.size() == 0) {
            return Collections.EMPTY_MAP;
        }
        Map<String, byte[]> data = new HashMap<>();
        doc.forEach((k, v) -> {
            byte[] value = SerializationUtils.toByteArrayFst(v);
            if (value != null) {
                data.put(k, value);
            }
        });
        return data;
    }
442064
protected void _format(SarlEvent event, IFormattableDocument document) {
		formatAnnotations(event, document, XbaseFormatterPreferenceKeys.newLineAfterClassAnnotations);
		formatModifiers(event, document);

		final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(event);
		document.append(regionFor.keyword(this.keywords.getEventKeyword()), ONE_SPACE);

		document.surround(regionFor.keyword(this.keywords.getExtendsKeyword()), ONE_SPACE);
		document.format(event.getExtends());

		formatBody(event, document);
	}
1244264
public static boolean serialInclude(Doc doc) {
        if (doc == null) {
            return false;
        }
        return doc.isClass() ?
            serialClassInclude((ClassDoc)doc) :
            serialDocInclude(doc);
    }
1214205
function DocParser(){
  return {
    doc: makeBlock('Document', 1, 1),
    tip: this.doc,
    refmap: {},
    inlineParser: new InlineParser(),
    breakOutOfLists: breakOutOfLists,
    addLine: addLine,
    addChild: addChild,
    incorporateLine: incorporateLine,
    finalize: finalize,
    processInlines: processInlines,
    parse: parse
  };
}
249871
public static String documentToPrettyString(Document document) {
        StringWriter stringWriter = new StringWriter();
        OutputFormat prettyPrintFormat = OutputFormat.createPrettyPrint();
        XMLWriter xmlWriter = new XMLWriter(stringWriter, prettyPrintFormat);

        try {
            xmlWriter.write(document);
        } catch (IOException e) {
            // Ignore, shouldn't happen.
        }

        return stringWriter.toString();
    }
601055
def _from_docstring_md(doc):
    

    def format_fn(line, status):
        """ format function """

        def fix_tags(line):
            # In markdown we need to escape < > and & for display
            # but we don't want to do this is the value is quoted
            # by backticks ``

            def fn(match):
                # swap matched chars
                found = match.group(1)
                if found == "<":
                    return "&lt;"
                if found == ">":
                    return "&gt;"
                if found == "&":
                    return "&amp;"
                return match.group(0)

            return re_from_tag.sub(fn, line)

        if re_from_data.match(line):
            line = re_from_data.sub(r"**\1** ", line)
            status["add_line"] = True
        line = re_from_defaults.sub(r"*\1*", line)
        if status["listing"]:
            # parameters
            if re_from_param.match(line):
                m = re_from_param.match(line)
                line = "  - `{}` {}".format(m.group(1), fix_tags(m.group(3)))
            # status items
            elif re_from_status.match(line):
                m = re_from_status.match(line)
                line = "  - `{}` {}".format(m.group(1), fix_tags(m.group(3)))
            # bullets
            elif re_from_item.match(line):
                line = re_from_item.sub(r"  -", fix_tags(line))
            # is continuation line
            else:
                line = fix_tags(line)
                line = " " * 4 + line.lstrip()
        else:
            line = fix_tags(line)
        return line

    return _reformat_docstring(doc, format_fn, code_newline="\n")