# Adapter and Writer

Besides `TagVisitor`, you can use also one of the following classes.

* `EmptyTagVisitor` - default implementation that does nothing. You will probably use it, as you can override just the methods you need.
* `TagVisitors` - is a simple composite of many `TagVisitor`s implementations. They will be invoked in the given order.
* `TagAdapter` - is an adapter over target `TagVisitor`. With such adapter you can change the behavior of an existing visitor.

### Enclosed adapters

You can use the following adapters:

* `StripHtmlTagAdapter` - strips all the unnecessary whitespaces from text blocks and also removes all the comments. For example, multiple spaces would be replaced with a single space, etc.&#x20;
* `UrlRewriterTagAdapter` - as the name implies, you may change the `<a href` link values.

### Writer

`TagWriter` is a simple `TagVisitor` that *builds* HTML from the events. Usually, you can use it as target of some adapter. This way you can modify input HTML by parsing it, adapt it, and then write it again to an `Appendable` content.

### Example

```java
TagWriter tagWriter = new TagWriter();
StripHtmlTagAdapter adapter = new StripHtmlTagAdapter(tagWriter);
LagartoParser lagartoParser = new LagartoParser(
        "<html> <h1>  Hello  </h1> </html>");

lagartoParser.parse(adapter);

System.out.println(tagWriter.getOutput().toString());
```

The resulting string would be:

```
<html><h1> Hello </h1></html>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lagarto.jodd.org/lagarto-parser/adapter-and-writer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
