Skip to content

Commit

Permalink
🪟 🎉 Support docusaurus admonitions in markdown docs (#15519)
Browse files Browse the repository at this point in the history
* Support docusaurus admonitions in markdown docs

* Narrow down docs folders in vscod workspace
* Add mdast and remark-directive dependencies
* Add remark-directive to Markdown component plugins
* Add admonitions plugin to support docusaurus admonitions
* Add styles for admonitions in markdown files

* Add storybook component for Markdown and fix issues with code blocks

* Rename Markdown component styles files, improve code blocks style and lower heading font sizes

* Update admonitions tag to div

* Update DocumentationPanel to lazy load

* Add @types/unist to package.json
  • Loading branch information
edmundito authored Aug 12, 2022
1 parent da5b837 commit 90b71b7
Show file tree
Hide file tree
Showing 10 changed files with 1,027 additions and 145 deletions.
7 changes: 6 additions & 1 deletion .vscode/frontend.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
"path": "../airbyte-webapp-e2e-tests"
},
{
"path": "../docs"
"name": "docs/integrations/destinations",
"path": "../docs/integrations/destinations"
},
{
"name": "docs/integrations/sources",
"path": "../docs/integrations/sources"
}
],
"extensions": {
Expand Down
800 changes: 748 additions & 52 deletions airbyte-webapp/package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions airbyte-webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"framer-motion": "^6.3.11",
"launchdarkly-js-client-sdk": "^2.22.1",
"lodash": "^4.17.21",
"mdast": "^3.0.0",
"query-string": "^6.13.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
Expand All @@ -59,13 +60,15 @@
"recharts": "^2.1.10",
"rehype-slug": "^5.0.1",
"rehype-urls": "^1.1.1",
"remark-directive": "^2.0.1",
"remark-frontmatter": "^4.0.1",
"remark-gfm": "^3.0.0",
"rxjs": "^7.5.5",
"sanitize-html": "^2.7.0",
"sass": "^1.52.2",
"styled-components": "^5.3.5",
"typesafe-actions": "^5.1.0",
"unist-util-visit": "^4.1.0",
"yup": "^0.32.11"
},
"devDependencies": {
Expand Down Expand Up @@ -95,6 +98,7 @@
"@types/react-widgets": "^4.4.7",
"@types/sanitize-html": "^2.6.2",
"@types/styled-components": "^5.1.25",
"@types/unist": "^2.0.5",
"@typescript-eslint/eslint-plugin": "^5.27.1",
"@typescript-eslint/parser": "^5.27.1",
"eslint-config-prettier": "^8.5.0",
Expand Down
131 changes: 131 additions & 0 deletions airbyte-webapp/src/components/Markdown/Markdown.styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
@use "../../scss/colors";

.airbyte-markdown {
* {
color: colors.$dark-blue;
line-height: 24px;
font-size: 16px;
font-weight: 400;
}

h1 {
font-size: 32px;
line-height: 56px;
font-weight: bold;
}

h2 {
font-size: 22px;
line-height: 36px;
font-weight: bold;
}

h3 {
font-size: 18px;
font-weight: bold;
}

h4 {
font-weight: bold;
}

a {
color: colors.$blue;
text-decoration: none;
line-height: 24px;

&:hover {
text-decoration: underline;
}
}

table {
border-collapse: collapse;
}

th,
td {
border: 1px solid colors.$grey-100;
margin: 0;
padding: 8px 16px;
}

th {
background: colors.$grey-50;
}

blockquote {
border-left: 4px solid colors.$grey-100;
padding-left: 16px;
margin-left: 25px;
}

strong {
font-weight: bold;
}

code {
white-space: break-spaces;
background: colors.$grey-50;
font-family: Menlo, Monaco, Consolas, monospace;
}

pre > code {
display: block;
padding: 15px;
overflow: auto;
border-radius: 8px;
border-bottom: 2px solid colors.$grey-100;
}

img {
max-width: 100%;
}

.admonition {
border-radius: 8px;
border-left: 8px solid colors.$grey-300;
padding: 1px 16px 1px 48px;
margin: -1px 0 15px;
background-color: colors.$grey-50;
position: relative;

&::before {
content: "ℹ️";
position: absolute;
top: 16px;
left: 16px;
}

&--caution,
&--warning {
background-color: colors.$yellow-50;
border-left-color: colors.$yellow-300;
&::before {
content: "⚠️";
}
}

&--danger {
background-color: colors.$red-50;
border-left-color: colors.$red-300;
&::before {
content: "⚠️";
}
}

&--note::before {
content: "📝";
}

&--tip,
&--info {
background-color: colors.$blue-50;
border-left-color: colors.$blue-300;
}

&--tip::before {
content: "💡";
}
}
}
11 changes: 7 additions & 4 deletions airbyte-webapp/src/components/Markdown/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ import type { PluggableList } from "react-markdown/lib/react-markdown";
import classNames from "classnames";
import React from "react";
import ReactMarkdown from "react-markdown";
import remarkDirective from "remark-directive";
import remarkFrontmatter from "remark-frontmatter";
import remarkGfm from "remark-gfm";

import "./styles.scss";
import { remarkAdmonitionsPlugin } from "./remarkAdmonitionsPlugin";

interface Props {
import "./Markdown.styles.scss";

interface MarkdownProps {
content?: string;
className?: string;
rehypePlugins?: PluggableList;
}

export const Markdown: React.FC<Props> = ({ content, className, rehypePlugins }) => {
export const Markdown: React.VFC<MarkdownProps> = ({ content, className, rehypePlugins }) => {
return (
<ReactMarkdown
// Open everything except fragment only links in a new tab
Expand All @@ -23,7 +26,7 @@ export const Markdown: React.FC<Props> = ({ content, className, rehypePlugins })
skipHtml
// @ts-expect-error remarkFrontmatter currently has type conflicts due to duplicate vfile dependencies
// This is not actually causing any issues, but requires to disable TS on this for now.
remarkPlugins={[remarkFrontmatter, remarkGfm]}
remarkPlugins={[remarkDirective, remarkAdmonitionsPlugin, remarkFrontmatter, remarkGfm]}
rehypePlugins={rehypePlugins}
children={content || ""}
/>
Expand Down
94 changes: 94 additions & 0 deletions airbyte-webapp/src/components/Markdown/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { ComponentStory, ComponentMeta } from "@storybook/react";

import { Markdown } from "./Markdown";

export default {
title: "Ui/Markdown",
component: Markdown,
argTypes: {},
} as ComponentMeta<typeof Markdown>;

const Template: ComponentStory<typeof Markdown> = (args) => (
<div style={{ backgroundColor: "white" }}>
<Markdown {...args} />
</div>
);

const content = `
# Heading 1
## Heading 2
### Heading 3
#### Heading 4
##### Heading 5
###### Heading 6
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
> The quick brown fox jumps over the lazy dog.
[Link](https://www.airbyte.com/)
\`Pre\`
*italic*
**bold**
~strikethrough~
\`\`\`javascript
function codeBlock() {
// comment
}
\`\`\`
| Heading 1 | Heading 2 |
|:----------|:----------|
|Cell 1 | Cell 2 |
|Cell 3 | Cell 4 |
- List item 1
- List item 2
- List item 3
1. List item 1
2. List item 2
3. List item 3
* List item 1
* List item 2
* List item 3
:::note
This is a note admonition
:::
:::tip
This is a tip admonition
:::
:::info
This is a info admonition
:::
:::caution
This is a caution admonition
:::
:::warning
This is a warning admonition
:::
:::danger
This is a danger admonition
:::
`;

export const Primary = Template.bind({});
Primary.args = {
content,
};
21 changes: 21 additions & 0 deletions airbyte-webapp/src/components/Markdown/remarkAdmonitionsPlugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Root } from "mdast";
import { Plugin } from "unified";
import { Node } from "unist";
import { visit } from "unist-util-visit";

const SUPPORTED_ADMONITION_NAMES: Readonly<string[]> = ["note", "tip", "info", "caution", "warning", "danger"];
const SUPPORTED_NODE_TYPES: Readonly<string[]> = ["textDirective", "leafDirective", "containerDirective"];

export const remarkAdmonitionsPlugin: Plugin<[], Root> = () => (tree) => {
visit<Node & { name?: string }>(tree, (node) => {
if (!node.name || !SUPPORTED_ADMONITION_NAMES.includes(node.name) || !SUPPORTED_NODE_TYPES.includes(node.type)) {
return;
}

const data = node.data ?? (node.data = {});
const className = `admonition admonition--${node.name}`;

data.hName = "div";
data.hProperties = { class: className };
});
};
Loading

0 comments on commit 90b71b7

Please sign in to comment.