MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / render

Method render

src/main/java/fielded/boxbrowser/BoxBrowser.java:188–270  ·  view source on GitHub ↗
(Box box, Object source, Dict.Prop property)

Source from the content-addressed store, hash-verified

186 String a;
187 int comment = 0;
188 }
189
190 private String render(Box box, Object source, Dict.Prop property) {
191 // extract comment blocks and render as markdown
192
193 if (property.getAttributes()
194 .has(toMarkdown)) {
195 String md = property.getAttributes()
196 .get(toMarkdown)
197 .apply(box, source);
198
199 String html = "<p>" + Errors.INSTANCE.handle(() -> MarkdownToHTML.convert(md), t -> "A error was thrown while rendering this property as markdown: <code>" + t + "</code>") + "</p>";
200 return html;
201 }
202 if (property.getAttributes()
203 .has(toHTML)) {
204 String md = property.getAttributes()
205 .get(toHTML)
206 .apply(box, source);
207
208 String html = md;
209 return html;
210 }
211
212 if (source instanceof HasMarkdownInformation) {
213 String html = "<p>" + Errors.INSTANCE.handle(() -> ((HasMarkdownInformation) source).generateMarkdown(box, property), t -> "An error was thrown while rendering this object as HTML: <code>" + t + "</code>") + "</p>";
214 return html;
215 }
216
217 // todo, these are language specific
218 String commentStart = "/*";
219 String commentEnd = "*/";
220
221 String[] ss = ("" + source).split("\n");
222
223 List<Section> sections = new ArrayList<>();
224 Section s = new Section();
225 s.a = "";
226 sections.add(s);
227
228 for (int i = 0; i < ss.length; i++) {
229
230 String z = ss[i]/*.trim()*/;
231 if (z.startsWith("//")) {
232 Section s2 = new Section();
233 s2.a = z.substring(2);
234 s2.comment = s.comment + 1;
235 sections.add(s2);
236 s2 = new Section();
237 s2.a = "";
238 s2.comment = s.comment;
239 sections.add(s2);
240 s = s2;
241 } else if (z.equals(commentStart)) {
242 Section s2 = new Section();
243 s2.a = "";
244 s2.comment = s.comment + 1;
245 sections.add(s2);

Callers 2

handleBoxMethod · 0.95

Calls 15

convertMethod · 0.95
ensureSentenceCaseMethod · 0.95
getAttributesMethod · 0.80
applyMethod · 0.65
getMethod · 0.65
handleMethod · 0.65
generateMarkdownMethod · 0.65
hasMethod · 0.45
splitMethod · 0.45
addMethod · 0.45
equalsMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected