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

Issue 596 - Add Markdown presentation #606

Merged
merged 49 commits into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
d4ad80b
- add basic markdown support
Sep 30, 2019
48c763b
Merge branch 'dev' into 596-markdowns
Marc-Andre-Rivet Oct 8, 2019
3f1794a
Merge branch 'dev' into 596-markdowns
Nov 20, 2019
44cf937
Ensure that cell focus and navigation operate the same way for MD cells.
Nov 20, 2019
528331a
Add visual tests for Markdown rendering.
Nov 20, 2019
9a5e6a2
Align text to the left and use sans-serif for markdown cells.
Nov 20, 2019
a781765
Add markdown table for standalone tests.
Nov 21, 2019
254ef01
Fix typo.
Nov 28, 2019
d4d683b
Test navigation for markdown cells.
Dec 3, 2019
7bc2fce
Make selectors for tables more specific.
Dec 2, 2019
41b9b5b
Add sorting tests.
Dec 3, 2019
64e7e72
Add filtering tests.
Dec 3, 2019
bec6ca2
Add test for clicking links.
Dec 3, 2019
0b026e9
Cast supplied values to string for markdown cells.
Dec 3, 2019
5669baf
Add Dash app for markdown tables.
Dec 3, 2019
3f6bc4b
Add copy paste tests for markdown cells.
Dec 3, 2019
79a0227
Load highlight.js asynchronously.
Dec 6, 2019
b45f0c1
Add highlight.js and github style to third-party resources.
Dec 9, 2019
4d2e5b3
Use third-party folder for highlight.js and corresponding stylesheet.
Dec 9, 2019
a5ad414
Check whether exports is an empty object.
Dec 9, 2019
f3ac52a
Fix filtering test.
Dec 9, 2019
b8131fe
Add types to modules.d.ts for percy.
Dec 10, 2019
6f56403
Add plaintext option for highlightjs.
Dec 10, 2019
3460fb4
Use plaintext for code without highlights.
Dec 10, 2019
f9a031d
Preserve whitespace in block quotes.
Dec 10, 2019
4bfbd74
Fix column widths for selectable and deletable cells.
Dec 11, 2019
8dae616
Use npm package for highlightjs.
Dec 11, 2019
300d9b3
Update package-lock.
Dec 12, 2019
296d90a
Change getCell to getCellById.
Dec 12, 2019
60a7f50
fix tests
Dec 13, 2019
86ef776
Move highlightjs functionality to separate file.
Dec 13, 2019
c0b72d7
Add test that checks for window hljs variable.
Dec 13, 2019
1863e56
Add highlight.js to Python js_dist.
Dec 16, 2019
20e1085
Use window hljs if defined.
Dec 16, 2019
ec295ef
Rename markdown test and add setup for code highlighting.
Dec 16, 2019
8ff279b
Add test for using window.hljs if defined.
Dec 16, 2019
7a60c3a
Match languages to those defined in dcc.
Dec 16, 2019
3cc38a5
Move highlight.js to devDependencies.
Dec 17, 2019
badb14b
Refactor async package info to be similar to other Dash libraries.
Dec 17, 2019
ede6b5e
Move third-party highlight.js file.
Dec 17, 2019
fc63409
Move Highlight file to utils and rename to MarkdownHighlighter.
Dec 17, 2019
e23c36d
Merge branch 'dev' into 596-markdowns
Dec 20, 2019
0b892e1
Fix tslint.
Dec 20, 2019
aa4d394
Update CHANGELOG.
Dec 20, 2019
a2af831
handle focus in markdown cell the same way its handled in dropdown cell
Dec 20, 2019
abe0c31
Fix Percy Storybook Usage (#674)
Marc-Andre-Rivet Jan 7, 2020
aa26f48
Fix navigation issue.
Jan 7, 2020
1a6338c
Add sample table for mixed MD/non-MD cells.
Jan 7, 2020
38f8ea5
Add test for navigation between non-MD and MD cells.
Jan 7, 2020
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
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ jobs:
- run:
name: Run visual tests
command: npm run test.visual

- store_artifacts:
path: storybook-static

"node":
docker:
Expand Down
3 changes: 3 additions & 0 deletions .storybook/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
let babel = require('./babel.config.js');
let config = require('./../.config/webpack/base.js')({
babel,
ts: {
transpileOnly: true
},
preprocessor: {
variables: {
mode: 'eager'
Expand Down
6 changes: 3 additions & 3 deletions @Types/modules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ declare module 'fast-isnumeric' {
}

declare class Remarkable {
constructor();
constructor(options?: any);
render(value: string): any;
}

declare interface RemarkableCtor {
new(): Remarkable;
new(options?: any): Remarkable;
}

declare module 'remarkable' {
export const Remarkable: RemarkableCtor;
}
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Added
- [#606](https://github.com/plotly/dash-table/pull/606) Add markdown support for table cells. Cells will be rendered as markdown if the column `presentation` is specified as `markdown`.
- Add highlight.js for syntax highlighting. If `window.hljs` is specified, that will be used for highlighting instead.

### Fixed
- [#670](https://github.com/plotly/dash-table/pull/670) Fix a bug where `derived_filter_query_structure` was not getting updated properly

Expand Down
63 changes: 29 additions & 34 deletions dash_table_base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,35 @@

_this_module = _sys.modules[__name__]

async_resources = [
'export',
'table',
'highlight'
]

_js_dist = []

_js_dist.extend([{
'relative_package_path': 'async~{}.js'.format(async_resource),
'external_url': (
'https://unpkg.com/dash-table@{}'
'/dash_table/async~{}.js'
).format(__version__, async_resource),
'namespace': package_name,
'async': True
} for async_resource in async_resources])

_js_dist.extend([{
'relative_package_path': 'async~{}.js.map'.format(async_resource),
'external_url': (
'https://unpkg.com/dash-table@{}'
'/dash_table/async~{}.js.map'
).format(__version__, async_resource),
'namespace': package_name,
'dynamic': True
} for async_resource in async_resources])

_js_dist = [
_js_dist.extend([
{
'relative_package_path': 'bundle.js',
'external_url': (
Expand All @@ -44,40 +71,8 @@
).format(__version__),
'namespace': package_name,
'dynamic': True
},
{
'relative_package_path': 'async~export.js',
'external_url': (
'https://unpkg.com/dash-table@{}/dash_table/async~export.js'
).format(__version__),
'namespace': package_name,
'async': True
},
{
'relative_package_path': 'async~export.js.map',
'external_url': (
'https://unpkg.com/dash-table@{}/dash_table/async~export.js.map'
).format(__version__),
'namespace': package_name,
'dynamic': True
},
{
'relative_package_path': 'async~table.js',
'external_url': (
'https://unpkg.com/dash-table@{}/dash_table/async~table.js'
).format(__version__),
'namespace': package_name,
'async': True
},
{
'relative_package_path': 'async~table.js.map',
'external_url': (
'https://unpkg.com/dash-table@{}/dash_table/async~table.js.map'
).format(__version__),
'namespace': package_name,
'dynamic': True
}
]
])

_css_dist = []

Expand Down
24 changes: 23 additions & 1 deletion demo/AppMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as R from 'ramda';

import Environment from 'core/environment';

import { generateMockData, IDataMock, generateSpaceMockData } from './data';
import { generateMockData, IDataMock, generateSpaceMockData, generateMarkdownMockData, generateMixedMarkdownMockData } from './data';
import {
PropsWithDefaults,
ChangeAction,
Expand All @@ -19,6 +19,8 @@ export enum AppMode {
Date = 'date',
Default = 'default',
Formatting = 'formatting',
Markdown = 'markdown',
MixedMarkdown = 'mixedmarkdown',
ReadOnly = 'readonly',
SomeReadOnly = 'someReadonly',
ColumnsInSpace = 'columnsInSpace',
Expand Down Expand Up @@ -123,6 +125,22 @@ function getDefaultState(
};
}

function getDefaultMarkdownState() {
const state = getDefaultState(generateMarkdownMockData);
state.tableProps.editable = false;
state.tableProps.style_cell = {};
state.tableProps.style_cell_conditional = [];
return state;
}

function getDefaultMixedMarkdownState() {
const state = getDefaultState(generateMixedMarkdownMockData);
state.tableProps.editable = false;
state.tableProps.style_cell = {};
state.tableProps.style_cell_conditional = [];
return state;
}

function getReadonlyState() {
const state = getDefaultState();
state.tableProps.editable = false;
Expand Down Expand Up @@ -347,6 +365,10 @@ function getModeState(mode: string | null) {
return getDateState();
case AppMode.Formatting:
return getFormattingState();
case AppMode.Markdown:
return getDefaultMarkdownState();
case AppMode.MixedMarkdown:
return getDefaultMixedMarkdownState();
case AppMode.ReadOnly:
return getReadonlyState();
case AppMode.SomeReadOnly:
Expand Down
102 changes: 102 additions & 0 deletions demo/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,108 @@ export const generateMockData = (rows: number) => unpackIntoColumnsAndData([
}
]);

export const generateMarkdownMockData = (rows: number) => unpackIntoColumnsAndData([
{
id: 'markdown-headers',
name: ['', 'Headers'],
presentation: 'markdown',
data: gendata(i => '#'.repeat(i % 6) + ' row ' + i, rows)
},
{
id: 'markdown-italics',
name: ['Emphasis', 'Italics'],
presentation: 'markdown',
data: gendata(i => (i % 2) ? '*' + i + '*' : '_' + i + '_', rows)
},
{
id: 'markdown-links',
name: ['', 'Links'],
presentation: 'markdown',
data: gendata(i => '[Learn about ' + i + '](http://en.wikipedia.org/wiki/' + i + ')', rows)
},
{
id: 'markdown-lists',
name: ['', 'Lists'],
presentation: 'markdown',
data: gendata(i => [
'1. Row number ' + i,
' - subitem ' + i,
' - subsubitem ' + i,
' - subitem two ' + i,
'2. Next row ' + (i + 1)].join('\n'),
rows)
},
{
id: 'markdown-tables',
name: ['', 'Tables'],
presentation: 'markdown',
data: gendata(i => [
'Current | Next',
'--- | ---',
i + ' | ' + (i + 1)].join('\n'),
rows)
},
{
id: 'markdown-quotes',
name: ['', 'Quotes'],
presentation: 'markdown',
data: gendata(i => '> A quote for row number ' + i, rows)
},
{
id: 'markdown-inline-code',
name: ['', 'Inline code'],
presentation: 'markdown',
data: gendata(i => 'This is row `' + i + '` in this table.', rows)
},
{
id: 'markdown-code-blocks',
name: ['', 'Code blocks'],
presentation: 'markdown',
data: gendata(i => [
'```python',
'def hello_table(i=' + i + '):',
' print("hello, " + i)'].join('\n'), rows)
},
{
id: 'markdown-images',
name: ['', 'Images'],
presentation: 'markdown',
data: gendata(i => '![image ' + i + ' alt text](https://dash.plot.ly/assets/images/logo.png)', rows)
}

]);

export const generateMixedMarkdownMockData = (rows: number) => unpackIntoColumnsAndData([
{
id: 'not-markdown-column',
name: ['Not Markdown'],
editable: true,
data: gendata(_ => 'this is not a markdown cell', rows)
},
{
id: 'markdown-column',
name: ['Markdown'],
type: ColumnType.Text,
presentation: 'markdown',
data: gendata(_ => [
'```javascript',
'console.warn("this is a markdown cell")',
'```'].join('\n'), rows)
},
{
id: 'also-not-markdown-column',
name: ['Also Not Markdown'],
editable: false,
data: gendata(i => i, rows)
},
{
id: 'also-also-not-markdown-column',
name: ['Also Also Not Markdown'],
editable: true,
data: gendata(_ => 'this is also also not a markdown cell', rows)
}
]);

export const generateSpaceMockData = (rows: number) => unpackIntoColumnsAndData([
{
id: 'rows',
Expand Down
Loading