-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Markdown support to table cell
closes #428
- Loading branch information
Showing
11 changed files
with
188 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Table / Markdown | ||
# Creates a table with relative and absolute links. | ||
# #table #markdown | ||
# --- | ||
|
||
from h2o_wave import main, Q, ui, app | ||
|
||
|
||
@app('/demo') | ||
async def serve(q: Q): | ||
|
||
q.page['example'] = ui.form_card(box='1 1 5 3', items=[ | ||
ui.text_xl(content='Table with Markdown links'), | ||
ui.table( | ||
name='table', | ||
columns=[ | ||
ui.table_column(name='description', label='Description', min_width="200"), | ||
ui.table_column(name='newtab', label='Open in new tab'), | ||
ui.table_column(name='markdown', label='Link', | ||
cell_type=ui.markdown_table_cell_type()) | ||
], | ||
rows=[ | ||
ui.table_row(name='row1', cells=['Absolute URL', 'Yes', '[Wave](http://wave.h2o.ai/)']), | ||
ui.table_row(name='row2', cells=['Relative URL', 'No', '[Go to /wave](wave)']), | ||
] | ||
) | ||
]) | ||
|
||
await q.page.save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2020 H2O.ai, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import { S } from 'h2o-wave' | ||
import React from 'react' | ||
import { XLink } from './link' | ||
import { Markdown } from './markdown' | ||
|
||
export interface MarkdownTableCellType { | ||
/** An identifying name for this component. */ | ||
name?: S | ||
} | ||
|
||
export const XMarkdownTableCellType = ({ content }: { content: S}) => { | ||
const [, label, path] = /\[(.*)\]\((.+)\)/.exec(content) || [] | ||
if (path) { | ||
const isPathAbsolute = /https*:\/\//.exec(path) | ||
return <XLink model={{ label, path, target: isPathAbsolute ? '_blank' : undefined }} /> | ||
} else { | ||
return ( | ||
<Markdown source={content} /> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters