Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Issue 250 - Support for rendering links inside dcc.Markdown as dcc.Link #711

Merged
merged 24 commits into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
- [#711](https://github.com/plotly/dash-core-components/pull/711) Added support for `dcc.Link` react component inside of `dcc.Markdown`

## [1.6.0] - 2019-11-27
### Updated
- Upgraded plotly.js to 1.51.2 [#708](https://github.com/plotly/dash-core-components/pull/708)
Expand Down
26 changes: 25 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"prettier": "^1.14.2",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-jsx-parser": "^1.21.0",
"style-loader": "^0.23.1",
"styled-jsx": "^3.1.1",
"webpack": "^4.37.0",
Expand All @@ -91,4 +92,4 @@
"react": "^16.0.0",
"react-dom": "^16.0.0"
}
}
}
15 changes: 15 additions & 0 deletions src/fragments/Markdown.react.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import React, {Component} from 'react';
import {type} from 'ramda';
import JsxParser from 'react-jsx-parser';
import Markdown from 'react-markdown';

import {propTypes, defaultProps} from '../components/Markdown.react';
import '../components/css/highlight.css';

import DccLink from './../components/Link.react';

export default class DashMarkdown extends Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -85,6 +88,10 @@ export default class DashMarkdown extends Component {
const displayText =
dedent && textProp ? this.dedent(textProp) : textProp;

const componentTransforms = {
DccLink: props => <DccLink {...props} />,
};
Copy link
Contributor Author

@Marc-Andre-Rivet Marc-Andre-Rivet Dec 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we define the list of components we want to support are their name in markdown + props customization as needed.


return (
<div
id={id}
Expand All @@ -110,6 +117,14 @@ export default class DashMarkdown extends Component {
<Markdown
source={displayText}
escapeHtml={!dangerously_allow_html}
renderers={{
html: props => (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we toss in a danderous HTML / XSS test for future sanity?

<JsxParser
jsx={props.value}
components={componentTransforms}
/>
),
}}
/>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module.exports = (env, argv) => {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
exclude: /node_modules\/(?!react-jsx-parser\/)/,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly not transpiled to ES5 so needs to be re-transpiled.

use: {
loader: 'babel-loader',
},
Expand Down