[ https://issues.apache.org/jira/browse/FLINK-9792?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16541251#comment-16541251
]
ASF GitHub Bot commented on FLINK-9792:
---------------------------------------
Github user zentol commented on a diff in the pull request:
https://github.com/apache/flink/pull/6312#discussion_r201932360
--- Diff: flink-core/src/main/java/org/apache/flink/configuration/description/LineBreakElement.java
---
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.configuration.description;
+
+/**
+ * Represents a line break in the {@link Description}.
+ */
+public class LineBreakElement implements BlockElement {
+
+ /**
+ * Creates a line break in the description.
+ */
+ public static LineBreakElement linebreak() {
+ return new LineBreakElement();
+ }
+
+ private LineBreakElement() {
+ }
+
+ @Override
+ public String format(Formatter formatter) {
+ return formatter.format(this);
--- End diff --
this was only a rough draft, you could have inlineElement always return empty lists for
getChildren and blockelement override getValue() and mark those as final. Finally `getChildren`
could be changed to only return `InlineElement`, voila no infinite nesting. (see below for
an updated draft)
Note that your approach currently has infinite nesting capabilities due to `Text`, which
accepts a number of `InlineElements`, which again can be `Text`. (hence why i added the separate
Sequence type)
The whole idea here is to _not_ allow elements to do super custom stuff. If we want to
shorten links for the documentation we could have the formatter always show them as `here`.
```
public enum ElementType {
TEXT,
LINK,
LIST,
LINE_BREAK,
ARRAY,
SEQUENCE
}
public interface Element {
String getValue()
List<InlineElement> getChildren()
ElementType getType()
}
class InlineElement implements Element {
@Override
final List<InlineElement> getChildren() {
return Collections.emptyList;
}
}
class BlockElement implements Element {
@Override
final String getValue() {
return null;
}
}
class HtmlFormatter implements Formatter {
format(Description description) {
description.getElements().stream()
.forEach(this::format)
.collect(Collectors.joining())
}
String format(Element element) {
switch (element.getType()) {
case TEXT:
return element.getValue()
case LIST:
StringBuilder sb = new StringBuilder()
for (Element item : element.getChildren()) {
sb.append(<whatver html/formatting prefix you use for lists>)
sb.append(format(item))
sb.append(<whatver html/formatting suffix you use for lists>)
}
return sb.toString()
case LINK:
return "<a href=" + element.getValue + ">"
case LINE_BREAK:
reutrn "<br>"
case SEQUENCE:
StringBuilder sb = new StringBuilder()
for (Element item : element.getChildren()) {
sb.append(format(item))
}
return sb.toString()
}
}
}
class Link extends InlineElement {
private final String value
Link(String text) {
this.value = text
}
getValue() {
return this.value
}
getType() {
return LINK
}
}
class Text extends InlineElement {
private final String value
Text(String text) {
this.value = text
}
getValue() {
retu this.value;
}
getType() {
return TEXT
}
}
class List extends BlockElement {
private final List<InlineElement> elements
List(InlineElement ... elements) {
this.elements = Arrays.asList(elements)
}
getChildren() {
return elements
}
getType() {
return LIST
}
}
class LineBreak extends InlineElement {
getValue() {
return null
}
getType() {
return LINE_BREAK
}
}
class ComboArrayWhatever extends BlockElement {
private final List<InlineElement> elements
List(InlineElement ... elements) {
this.elements = Arrays.asList(elements)
}
getChildren() {
return Collections.emptyList
}
getType() {
return SEQUENCE
}
}
```
> Cannot add html tags in options description
> -------------------------------------------
>
> Key: FLINK-9792
> URL: https://issues.apache.org/jira/browse/FLINK-9792
> Project: Flink
> Issue Type: Bug
> Components: Documentation
> Affects Versions: 1.5.1, 1.6.0
> Reporter: Dawid Wysakowicz
> Assignee: Dawid Wysakowicz
> Priority: Major
> Labels: pull-request-available
>
> Right now it is impossible to add any html tags in options description, because all "<"
and ">" are escaped. Therefore some links there do not work.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
|