Skip to content

Commit

Permalink
Merge branch 'next'
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyjosephprice committed Oct 22, 2024
2 parents 9b9671e + af6e306 commit fa00fd3
Show file tree
Hide file tree
Showing 15 changed files with 1,870 additions and 355 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions __tests__/compilers/compatability.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,23 +151,23 @@ This is some in progress <!-- commented out stuff -->
`);
});

it('closes un-closed self closing tags', () => {
it.skip('closes un-closed self closing tags', () => {
const md = `
This is a break: <br>
`;

expect(mdx(rdmd.mdast(md)).trim()).toBe('This is a break: <br />');
});

it('closes un-closed self closing tags with a space', () => {
it.skip('closes un-closed self closing tags with a space', () => {
const md = `
This is a break: <br >
`;

expect(mdx(rdmd.mdast(md)).trim()).toBe('This is a break: <br />');
});

it('closes complex un-closed self closing tags', () => {
it.skip('closes complex un-closed self closing tags', () => {
const md = `
This is an image: <img src="http://example.com/#\\>" >
`;
Expand Down
4 changes: 4 additions & 0 deletions components/Code/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ const Code = (props: CodeProps) => {
const code = value ?? (Array.isArray(children) ? children[0] : children) ?? '';
const highlightedCode = syntaxHighlighter && code ? syntaxHighlighter(code, language, codeOpts, { mdx: true }) : code;

if (language === 'mermaid') {
return code;
}

return (
<>
{copyButtons && <CopyCode className="fa" codeRef={codeRef} />}
Expand Down
6 changes: 6 additions & 0 deletions components/Code/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@
word-wrap: normal;
}

pre.mermaid {
&_single {
background: var(--color-bg-page, white);
}
}

kbd {
background-color: $background;
background-color: var(--d-code-background, $background);
Expand Down
27 changes: 25 additions & 2 deletions components/CodeTabs/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { uppercase } from '@readme/syntax-highlighter';
import React from 'react';
import React, { useEffect } from 'react';
import mermaid from 'mermaid';

const CodeTabs = props => {
const { children, theme } = props;

// set Mermaid theme
useEffect(() => {
mermaid.initialize({
theme: theme === 'dark' ? 'dark' : 'default',
});
}, [theme])

function handleClick({ target }, index: number) {
const $wrap = target.parentElement.parentElement;
const $open = [].slice.call($wrap.querySelectorAll('.CodeTabs_active'));
Expand All @@ -14,6 +22,21 @@ const CodeTabs = props => {
codeblocks[index].classList.add('CodeTabs_active');

target.classList.add('CodeTabs_active');

if (target.value === 'mermaid') {
const $openMermaid = [].slice.call($wrap.querySelectorAll('.mermaid'));
$openMermaid.forEach((el: Element) => el.classList.remove('mermaid'));
codeblocks[index].classList.add('mermaid');
mermaid.contentLoaded();
}
}

// render single Mermaid diagram
if (!Array.isArray(children) && children.props?.children.props.lang === 'mermaid') {
const value = children.props.children.props.value;
return (
<pre className="mermaid mermaid_single">{value}</pre>
)
}

return (
Expand All @@ -24,7 +47,7 @@ const CodeTabs = props => {

/* istanbul ignore next */
return (
<button key={i} onClick={e => handleClick(e, i)} type="button">
<button key={i} onClick={e => handleClick(e, i)} type="button" value={lang}>
{meta || `${!lang ? 'Text' : uppercase(lang)}`}
</button>
);
Expand Down
5 changes: 1 addition & 4 deletions components/Image/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,13 @@
content: '\f00d';
cursor: pointer;
display: inline-block;
font: normal normal normal 2em/1 FontAwesome;
font-family: var(--fa-style-family, 'Font Awesome 6 Pro');
font-size: inherit;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
opacity: 1;
position: fixed;
right: 1em;
text-rendering: auto;
top: 1em;
transform: translate(0, 0);
transform: scale(1.5);
transition: 0.3s 0.3s ease-in;
}
Expand Down
37 changes: 37 additions & 0 deletions docs/built-in-components.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## Built-In Components

### Accordion

<Accordion title="My Accordion Title" icon="fa fa-info-circle" iconColor="#018ef5">
Lorem ipsum dolor sit amet, **consectetur adipiscing elit.** Ut enim ad minim veniam, quis nostrud exercitation
ullamco. Excepteur sint occaecat cupidatat non proident!
</Accordion>

---

### Cards

<Cards columns={2}>
<Card title="First Card" href="https://readme.com" icon="fa fa-home" iconColor="#018ef5" target="_blank">
Neque porro quisquam est qui dolorem ipsum quia
</Card>
<Card title="Second Card" icon="fa fa-user" iconColor="#018ef5">
*Lorem ipsum dolor sit amet, consectetur adipiscing elit*
</Card>
<Card title="Third Card" icon="fa fa-star" iconColor="#018ef5">
> Ut enim ad minim veniam, quis nostrud ullamco
</Card>
<Card title="Fourth Card" icon="fa fa-question" iconColor="#018ef5">
**Excepteur sint occaecat cupidatat non proident**
</Card>
</Cards>

---

### Tabs

<Tabs>
<Tab title="First Tab">Welcome to the content that you can only see inside the first Tab.</Tab>
<Tab title="Second Tab">Here's content that's only inside the second Tab.</Tab>
<Tab title="Third Tab">Here's content that's only inside the third Tab.</Tab>
</Tabs>
2 changes: 1 addition & 1 deletion docs/callouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ summary {
<details>
<summary><em>Setting the Custom Icon Font</em></summary><br />

The custom icon font defaults to `FontAwesome`, but you can use any font family available on the page by setting the `--icon-font` variable!
The custom icon font defaults to `Font Awesome 6 Pro`.

```css
.callout[theme='📷'] {
Expand Down
1 change: 1 addition & 0 deletions docs/code-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ We support syntax highlighting on a number of languages:
| Liquid | `liquid` |
| Lua | `lua` |
| Markdown | `markdown` |
| Mermaid | `mermaid` |
| Objective-C | `objc`, `objectivec`, |
| Objective-C++ | `objc++`, `objcpp`, `objectivecpp`, `objectivecplusplus`, |
| OCaml | `ocaml`, `ml` |
Expand Down
100 changes: 100 additions & 0 deletions docs/mermaid.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
title: 'Mermaid Diagrams'
category: 5fdf7610134322007389a6ed
hidden: false
---

## Examples

### Single Diagram

```mermaid
graph LR
A --- B
B-->C[fa:fa-ban forbidden]
B-->D(fa:fa-spinner);
```

```mermaid
sequenceDiagram
participant Alice
participant Bob
Alice->>John: Hello John, how are you?
loop HealthCheck
John->>John: Fight against hypochondria
end
Note right of John: Rational thoughts <br/>prevail!
John-->>Alice: Great!
John->>Bob: How about you?
Bob-->>John: Jolly good!
```

### Multiple Tabs

```mermaid
---
title: Animal example
---
classDiagram
note "From Duck till Zebra"
Animal <|-- Duck
note for Duck "can fly\ncan swim\ncan dive\ncan help in debugging"
Animal <|-- Fish
Animal <|-- Zebra
Animal : +int age
Animal : +String gender
Animal: +isMammal()
Animal: +mate()
class Duck{
+String beakColor
+swim()
+quack()
}
class Fish{
-int sizeInFeet
-canEat()
}
class Zebra{
+bool is_wild
+run()
}
```
```mermaid
stateDiagram-v2
[*] --> Still
Still --> [*]
Still --> Moving
Moving --> Still
Moving --> Crash
Crash --> [*]
```
```mermaid
pie title Pets adopted by volunteers
"Dogs" : 386
"Cats" : 85
"Rats" : 15
```

```mermaid diagram
journey
title My working day
section Go to work
Make tea: 5: Me
Go upstairs: 3: Me
Do work: 1: Me, Cat
section Go home
Go downstairs: 5: Me
Sit down: 5: Me
```
```syntax
journey
title My working day
section Go to work
Make tea: 5: Me
Go upstairs: 3: Me
Do work: 1: Me, Cat
section Go home
Go downstairs: 5: Me
Sit down: 5: Me
```
6 changes: 6 additions & 0 deletions example/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import lists from '../docs/lists.md';
// @ts-ignore
import mdxComponents from '../docs/mdx-components.mdx';
// @ts-ignore
import builtInComponents from '../docs/built-in-components.mdx';
// @ts-ignore
import mermaid from '../docs/mermaid.md';
// @ts-ignore
import sanitizingTests from '../docs/sanitizing-tests.md';
// @ts-ignore
import tableOfContentsTests from '../docs/table-of-contents-tests.md';
Expand All @@ -47,6 +51,8 @@ const fixtures = Object.entries({
imageTests,
lists,
mdxComponents,
builtInComponents,
mermaid,
sanitizingTests,
tableOfContentsTests,
tables,
Expand Down
Loading

0 comments on commit fa00fd3

Please sign in to comment.