use of org.apache.zeppelin.jupyter.nbformat.MarkdownCell in project zeppelin by apache.
the class JupyterUtil method getNote.
public Note getNote(Nbformat nbformat, String id, String codeReplaced, String markdownReplaced) {
Note note = new Note();
String name = nbformat.getMetadata().getTitle();
if (null == name) {
name = "Note converted from Jupyter_" + id;
}
note.setName(name);
String lineSeparator = System.lineSeparator();
Paragraph paragraph;
List<Paragraph> paragraphs = new ArrayList<>();
String interpreterName;
List<TypeData> typeDataList;
for (Cell cell : nbformat.getCells()) {
String status = Result.SUCCESS;
paragraph = new Paragraph();
typeDataList = new ArrayList<>();
Object cellSource = cell.getSource();
List<String> sourceRaws = new ArrayList<>();
if (cellSource instanceof String) {
sourceRaws.add((String) cellSource);
} else {
sourceRaws.addAll((List<String>) cellSource);
}
List<String> source = Output.verifyEndOfLine(sourceRaws);
String codeText = StringUtils.join(source, "");
if (cell instanceof CodeCell) {
interpreterName = codeReplaced;
for (Output output : ((CodeCell) cell).getOutputs()) {
if (output instanceof Error) {
typeDataList.add(output.toZeppelinResult());
} else {
typeDataList.add(output.toZeppelinResult());
if (output instanceof Stream) {
Stream streamOutput = (Stream) output;
if (streamOutput.isError()) {
status = Result.ERROR;
}
}
}
}
} else if (cell instanceof MarkdownCell || cell instanceof HeadingCell) {
interpreterName = markdownReplaced;
String markdownContent = markdownParser.render(codeText);
typeDataList.add(new TypeData(TypeData.HTML, markdownContent));
paragraph.setUpMarkdownConfig(true);
} else {
interpreterName = "";
}
paragraph.setText(interpreterName + lineSeparator + codeText);
paragraph.setResults(new Result(status, typeDataList));
paragraphs.add(paragraph);
}
note.setParagraphs(paragraphs);
return note;
}
Aggregations