Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨Render python component descriptions as markdown #171

Merged
merged 8 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"@projectstorm/react-diagrams-routing": "^6.6.1",
"dagre": "^0.8.5",
"krc-pagination": "^1.0.1",
"marked": "^4.0.18",
"node": "^16.9.1",
"pathfinding": "^0.4.18",
"paths-js": "^0.4.11",
Expand All @@ -85,6 +86,7 @@
"@babel/core": "^7.12.10",
"@jupyterlab/builder": "^3.1.0",
"@types/dagre": "^0.7.44",
"@types/marked": "^4.0.3",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@typescript-eslint/eslint-plugin": "^4.8.1",
Expand Down
27 changes: 24 additions & 3 deletions src/components/CustomNodeWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { formDialogWidget } from '../dialog/formDialogwidget';
import { showFormDialog } from '../dialog/FormDialog';
import { CommentDialog } from '../dialog/CommentDialog';
import ReactTooltip from 'react-tooltip';
import { marked } from 'marked';

var S;
(function (S) {
Expand Down Expand Up @@ -111,6 +112,7 @@ export class CustomNodeWidget extends React.Component<DefaultNodeProps> {
nodeDeletable: false,
commentInput: this.props.node['extras']['commentInput'],
showDescription: false,
descriptionStr: "",

imageGalleryItems:[
{
Expand Down Expand Up @@ -205,7 +207,26 @@ export class CustomNodeWidget extends React.Component<DefaultNodeProps> {
*/
async handleDescription() {
await this.setState({ showDescription: !this.state.showDescription });
ReactTooltip.show(this.element as Element)
this.getDescriptionStr();
ReactTooltip.show(this.element as Element);
}

renderText = text => {
var renderer = new marked.Renderer();
renderer.link = function(href, title, text) {
var link = marked.Renderer.prototype.link.apply(this, arguments);
return link.replace("<a","<a target='_blank'");
};
marked.setOptions({
renderer: renderer
});
const __html = marked(text)
return { __html }
}

getDescriptionStr() {
let dscrptStr = this.props.node['extras']['description'] ?? '***No description provided***';
this.setState({ descriptionStr: dscrptStr });
}

// Hide Error Tooltip
Expand Down Expand Up @@ -260,7 +281,7 @@ export class CustomNodeWidget extends React.Component<DefaultNodeProps> {
onDoubleClick={this.handleEditLiteral.bind(this)}>
<S.Title>
<S.TitleName>{this.props.node.getOptions().name}</S.TitleName>
<label>
<label data-no-drag>
<Toggle
className='lock'
checked={this.props.node.isLocked()}
Expand Down Expand Up @@ -302,7 +323,7 @@ export class CustomNodeWidget extends React.Component<DefaultNodeProps> {
<S.DescriptionName color={this.props.node.getOptions().color}>{this.props.node.getOptions()["name"]}</S.DescriptionName>
<p className='description-title'>Description:</p>
<div className='description-container'>
<pre className='description-text'>{this.props.node['extras']['description'] ?? <i>No description provided</i>}</pre>
<div className='markdown-body' dangerouslySetInnerHTML={this.renderText(this.state.descriptionStr)} />
</div>
</div>}
overridePosition={(
Expand Down
2 changes: 2 additions & 0 deletions src/components/state/MoveItemsState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export class MoveItemsState<E extends CanvasEngine = CanvasEngine> extends Abstr
new Action({
type: InputType.MOUSE_UP,
fire: () => {
// When node's position is empty, just return
if (this.initialPosition == null || this.finalPosition == null) return;
// When node in the same position, just return
if (
this.initialPosition.x === this.finalPosition.x &&
Expand Down
9 changes: 0 additions & 9 deletions style/ComponentInfo.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
position: relative;
}

.description-text{
text-align: justify;
font-family: sans-serif;
font-weight: 500;
font-size: 12px;
white-space: pre-wrap;
color: rgb(0, 0, 0);
}

.description-title{
text-align: justify;
font-family: 'Roboto', sans-serif;
Expand Down
Loading