19
19
package org.dbdoclet.trafo.html.docbook.editor;
21
import org.dbdoclet.service.StringServices;
22
import org.dbdoclet.trafo.html.docbook.DbtConstants;
23
import org.dbdoclet.trafo.script.Script;
21
24
import org.dbdoclet.trafo.tag.docbook.DocBookElement;
22
25
import org.dbdoclet.trafo.tag.docbook.DocBookTagFactory;
23
26
import org.dbdoclet.trafo.tag.docbook.Para;
27
import org.dbdoclet.trafo.tag.html.Br;
24
28
import org.dbdoclet.xiphias.dom.TextImpl;
29
import org.w3c.dom.Node;
30
import org.w3c.dom.Text;
26
32
public class BrEditor extends Editor {
29
public EditorInstruction edit(EditorInstruction values) throws EditorException {
31
setValues(super.edit(values));
32
DocBookTagFactory dbfactory = values.getTagFactory();
36
if (getCurrent() instanceof Para) {
38
DocBookElement parent = (DocBookElement) getCurrent().getParentNode();
42
Para para = dbfactory.createPara();
43
parent.appendChild(para);
51
getCurrent().appendChild(new TextImpl("\n"));
54
return finalizeValues();
35
public EditorInstruction edit(EditorInstruction values)
36
throws EditorException {
38
setValues(super.edit(values));
39
DocBookTagFactory dbfactory = values.getTagFactory();
42
Br brElement = (Br) values.getHtmlElement();
44
Script script = getScript();
45
boolean detectTrappedBrEnabled = script.isParameterOn(
46
DbtConstants.SECTION_DOCBOOK,
47
DbtConstants.PARAM_DOCBOOK_DETECT_TRAPPED_BR, true);
49
if (detectTrappedBrEnabled && isTrapped(brElement, values.getCurrent())) {
50
return finalizeValues();
53
if (getCurrent() instanceof Para) {
55
DocBookElement parent = (DocBookElement) getCurrent()
60
Para para = dbfactory.createPara();
61
parent.appendChild(para);
69
getCurrent().appendChild(new TextImpl("\n"));
72
return finalizeValues();
75
private boolean isTrapped(Br brElement, DocBookElement current) {
77
Node prevSibling = brElement.getPreviousSibling();
78
Node nextSibling = brElement.getNextSibling();
80
if (prevSibling == null || nextSibling == null) {
84
if (prevSibling instanceof Text == false
85
|| nextSibling instanceof Text == false) {
89
String prevText = prevSibling.getTextContent();
90
String nextText = nextSibling.getTextContent();
92
if (prevText == null || nextText == null) {
96
if (nextText.matches("(?s)^[\\w\\u00A0].*$") == false) {
100
if (prevText.matches("(?s)^.*[\\w\\u00A0-]$") == false) {
104
if (prevText.endsWith("-")) {
106
Node lastChild = current.getLastChild();
108
if (lastChild instanceof Text) {
110
Text lastChildText = (Text) lastChild;
111
String buffer = lastChildText.getTextContent();
113
if (buffer != null && buffer.endsWith("-")) {
114
buffer = StringServices.cutSuffix(buffer, "-");
115
lastChildText.setTextContent(buffer);