= Exercise 5.3
// Refs:
:url-base: https://github.com/fenegroni/TGPL-exercise-solutions
:url-workflows: {url-base}/workflows
:url-actions: {url-base}/actions
:badge-exercise53: image:{url-workflows}/Exercise 5.3/badge.svg?branch=main[link={url-actions}]
{badge-exercise53}
Write a function to print the contents of all text nodes in an HTML document tree.
Do not descend into <script> or <style> elements,
since their content are not visible in a web browser.
== Test
The new function to be tested is called `PrintAllTextNodesContent`.
The test follows the same pattern as exercises 5.1 and 5.2,
except this time the `want` element of the test is a simple string.
[source,go]
----
struct {
document string
want string
}
----
== Example
To make the output more predictable
I made sure all leading and trailing white space is removed and
empty lines are not printed.
Given this example HTML document as input:
[source,html]
----
<html>
<head></head>
<body>
<style>
p {
color: red;
}
</style>
<h1>title</h1>
<script src="javascript.js">
document.write("hello!")
</script>
<p>line1</p>
<p>line2</p>
</body>
</html>
----
the Example function's `Output` is very simple.
[source,go]
----
// Output:
// title
// line1
// line2
----
PrintAllTextNodesContent prints the contents of all text nodes found in n into out.
It does not descend into <script> or <style> elements,
since their content are not visible in a web browser.
Note: all leading and trailing white space is removed
and empty lines are not printed