= Exercise 5.3
// Refs:
:url-base: https://github.com/fenegroni/TGPL-exercise-solutions
:workflow: workflows/Exercise 5.3
:action: actions/workflows/ch5ex3.yml
:url-workflow: {url-base}/{workflow}
:url-action: {url-base}/{action}
:badge-exercise: image:{url-workflow}/badge.svg?branch=main[link={url-action}]
{badge-exercise}
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