Skip to content

Commit 4518e6d

Browse files
authored
🎨 [Frontend] Prettify markdown's outcome (#6369)
1 parent f272c8f commit 4518e6d

File tree

7 files changed

+23
-47
lines changed

7 files changed

+23
-47
lines changed

services/static-webserver/client/source/class/osparc/editor/MarkdownEditor.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ qx.Class.define("osparc.editor.MarkdownEditor", {
4242
case "preview-markdown": {
4343
control = new osparc.ui.markdown.Markdown().set({
4444
padding: 3,
45-
noMargin: true
4645
});
4746
const textArea = this.getChildControl("text-area");
4847
textArea.bind("value", control, "value");

services/static-webserver/client/source/class/osparc/info/CommentUI.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ qx.Class.define("osparc.info.CommentUI", {
9090
});
9191
break;
9292
case "comment-content":
93-
control = new osparc.ui.markdown.Markdown().set({
94-
noMargin: true
95-
});
93+
control = new osparc.ui.markdown.Markdown();
9694
control.getContentElement().setStyles({
9795
"text-align": this.__isMyComment() ? "right" : "left"
9896
});

services/static-webserver/client/source/class/osparc/info/ServiceUtils.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,7 @@ qx.Class.define("osparc.info.ServiceUtils", {
182182
});
183183
descriptionLayout.add(label);
184184

185-
const description = new osparc.ui.markdown.Markdown().set({
186-
noMargin: true,
187-
});
185+
const description = new osparc.ui.markdown.Markdown();
188186
// display markdown link content if that's the case
189187
if (
190188
osparc.utils.Utils.isValidHttpUrl(serviceData["description"]) &&

services/static-webserver/client/source/class/osparc/info/StudyUtils.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,7 @@ qx.Class.define("osparc.info.StudyUtils", {
166166
* @param maxHeight {Number} description's maxHeight
167167
*/
168168
createDescriptionMD: function(study, maxHeight) {
169-
const description = new osparc.ui.markdown.Markdown().set({
170-
noMargin: true
171-
});
169+
const description = new osparc.ui.markdown.Markdown();
172170
study.bind("description", description, "value", {
173171
converter: desc => desc ? desc : "Add description"
174172
});

services/static-webserver/client/source/class/osparc/metadata/QualityEditor.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ qx.Class.define("osparc.metadata.QualityEditor", {
177177
box.setLayout(new qx.ui.layout.VBox(10));
178178

179179
const helpText = "[10 Simple Rules with Conformance Rubric](https://www.imagwiki.nibib.nih.gov/content/10-simple-rules-conformance-rubric)";
180-
const helpTextMD = new osparc.ui.markdown.Markdown(helpText);
180+
const helpTextMD = new osparc.ui.markdown.Markdown(helpText).set({
181+
noMargin: true,
182+
});
181183
box.add(helpTextMD);
182184

183185
const grid = new qx.ui.layout.Grid(10, 6);
@@ -374,7 +376,9 @@ qx.Class.define("osparc.metadata.QualityEditor", {
374376

375377
// reference
376378
if (currentRule.references !== undefined) {
377-
const referenceMD = new osparc.ui.markdown.Markdown(currentRule.references);
379+
const referenceMD = new osparc.ui.markdown.Markdown(currentRule.references).set({
380+
noMargin: true,
381+
});
378382
this.__tsrGrid.add(referenceMD, {
379383
row,
380384
column: this.self().GridPos.reference

services/static-webserver/client/source/class/osparc/node/slideshow/BaseNodeView.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ qx.Class.define("osparc.node.slideshow.BaseNodeView", {
238238
const descView = new osparc.ui.markdown.Markdown().set({
239239
value: desc,
240240
padding: 3,
241-
noMargin: true,
242241
font: "text-14"
243242
});
244243
const scrollContainer = new qx.ui.container.Scroll();

services/static-webserver/client/source/class/osparc/ui/markdown/Markdown.js

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ qx.Class.define("osparc.ui.markdown.Markdown", {
6767

6868
noMargin: {
6969
check: "Boolean",
70-
init: true
70+
init: false
7171
}
7272
},
7373

@@ -79,40 +79,23 @@ qx.Class.define("osparc.ui.markdown.Markdown", {
7979
*/
8080
__applyMarkdown: function(value = "") {
8181
this.__loadMarked.then(() => {
82-
// trying to prettify:
83-
// - links: color with own colors
84-
// - headers: add margins
85-
// - line height: increase to 1.5
86-
/*
87-
const walkTokens = token => {
88-
// Check if the token is a link
89-
if (token.type === 'link' && token.tokens.length > 0) {
90-
// Check if the link contains an image token
91-
const containsImage = token.tokens.some(t => t.type === "image");
92-
// If the link does not contain an image, modify the text to include color styling
93-
if (!containsImage) {
94-
const linkColor = qx.theme.manager.Color.getInstance().resolve("link");
95-
token.text = `<span style="color: ${linkColor};">${token.text}</span>`;
82+
const renderer = {
83+
link(link) {
84+
const linkColor = qx.theme.manager.Color.getInstance().resolve("link");
85+
let linkHtml = `<a href="${link.href}" title="${link.title || ""}" style="color: ${linkColor};">`
86+
if (link.tokens && link.tokens.length) {
87+
const linkRepresentation = link.tokens[0];
88+
if (linkRepresentation.type === "text") {
89+
linkHtml += linkRepresentation.text;
90+
} else if (linkRepresentation.type === "image") {
91+
linkHtml += `<img src="${linkRepresentation.href}" tile alt="${linkRepresentation.text}"></img>`;
92+
}
9693
}
94+
linkHtml += `</a>`;
95+
return linkHtml;
9796
}
9897
};
99-
marked.use({ walkTokens });
100-
*/
101-
/*
102-
const renderer = new marked.Renderer();
103-
renderer.link = ({href, title, tokens}) => {
104-
// Check if the tokens array contains an image token
105-
const hasImageToken = tokens.some(token => token.type === "image");
106-
if (hasImageToken) {
107-
// Return the link HTML as is for image links (badges)
108-
return `<a href="${href}" title="${title || ''}">${tokens.map(token => token.text || '').join('')}</a>`;
109-
}
110-
// text links
111-
const linkColor = qx.theme.manager.Color.getInstance().resolve("link");
112-
return `<a href="${href}" title="${title || ''}" style="color: ${linkColor};>${tokens.map(token => token.text || '').join('')}</a>`;
113-
};
11498
marked.use({ renderer });
115-
*/
11699

117100
const html = marked.parse(value);
118101

@@ -148,9 +131,6 @@ qx.Class.define("osparc.ui.markdown.Markdown", {
148131
if (domElement === null) {
149132
return;
150133
}
151-
this.getContentElement().setStyle({
152-
"line-height": 1.5
153-
});
154134
if (domElement && domElement.children) {
155135
const elemHeight = this.__getChildrenElementHeight(domElement.children);
156136
if (this.getMaxHeight() && elemHeight > this.getMaxHeight()) {

0 commit comments

Comments
 (0)