Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub alert block quotes #118

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"markdown-it-deflist": "^3.0.0",
"markdown-it-emoji": "^3.0.0",
"markdown-it-footnote": "^4.0.0",
"markdown-it-github-alerts": "^0.3.0",
"markdown-it-inject-linenumbers": "^0.3.0",
"markdown-it-mark": "^4.0.0",
"markdown-it-sub": "^2.0.0",
Expand Down
24 changes: 13 additions & 11 deletions src/parser/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import MarkdownIt from 'markdown-it';
import anchor from 'markdown-it-anchor';
import highlight from './highlight.js';
import graphviz from './dot.js';
import githubAlerts from 'markdown-it-github-alerts';
import config from './config.js';
import { Renderer } from './parser.js';

Expand All @@ -15,40 +16,40 @@ const mdit = new MarkdownIt({
// ts-expect-error for blocks so this is ugly:
// https://github.com/Microsoft/TypeScript/issues/19573

/* @ts-expect-error: markdown-it modules aren't typed */
/* @ts-expect-error: module not typed */
import { full as emoji } from 'markdown-it-emoji';
mdit.use(emoji);
/* @ts-expect-error: markdown-it modules aren't typed */
/* @ts-expect-error: module not typed */
import taskLists from 'markdown-it-task-lists';
mdit.use(taskLists);
/* @ts-expect-error: markdown-it modules aren't typed */
/* @ts-expect-error: module not typed */
import footNote from 'markdown-it-footnote';
mdit.use(footNote);
/* @ts-expect-error: markdown-it modules aren't typed */
/* @ts-expect-error: most module not typed */
import lineNumbers from 'markdown-it-inject-linenumbers';
mdit.use(lineNumbers);
/* @ts-expect-error: markdown-it modules aren't typed */
/* @ts-expect-error: module not typed */
import texMath from 'markdown-it-texmath';
/* @ts-expect-error: markdown-it modules aren't typed */
/* @ts-expect-error: module not typed */
import katex from 'katex';
mdit.use(texMath, {
engine: katex,
delimiters: 'dollars',
katexOptions: config.katexOptions,
});
/* @ts-expect-error: markdown-it modules aren't typed */
/* @ts-expect-error: module not typed */
import defList from 'markdown-it-deflist';
mdit.use(defList);
/* @ts-expect-error: markdown-it modules aren't typed */
/* @ts-expect-error: module not typed */
import sub from 'markdown-it-sub';
mdit.use(sub);
/* @ts-expect-error: markdown-it modules aren't typed */
/* @ts-expect-error: module not typed */
import sup from 'markdown-it-sup';
mdit.use(sup);
/* @ts-expect-error: markdown-it modules aren't typed */
/* @ts-expect-error: module not typed */
import mark from 'markdown-it-mark';
mdit.use(mark);
/* @ts-expect-error: markdown-it modules aren't typed */
/* @ts-expect-error: module not typed */
import attributes from 'markdown-it-attrs';
mdit.use(attributes);

Expand All @@ -61,6 +62,7 @@ mdit.use(anchor, {
}),
});
mdit.use(graphviz);
mdit.use(githubAlerts);

const renderMarkdown: Renderer = (content: string) => {
return mdit.render(content);
Expand Down
89 changes: 79 additions & 10 deletions static/style.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
:root {
--color-alert-note: #a5d5fe;
--color-alert-tip: #b4fa72;
--color-alert-important: #ff8ffd;
--color-alert-warning: #ffaf00;
--color-alert-caution: #ff5f5f;
}

html {
background-color: black;
color: #aaa;
Expand Down Expand Up @@ -122,7 +130,6 @@ section.footnotes {

/* --------------------------------------------------------------------------
* DEFIITION LISTS ---------------------------------------------------------- */

dl {
display: flex;
flex-flow: row wrap;
Expand Down Expand Up @@ -158,20 +165,75 @@ dt + dt + dd {
margin-top: -2.25em; /* Align definition with last term */
} /* Self height - margin - padding */

/* --------------------------------------------------------------------------
* QUOTES AND ALERTS--------------------------------------------------------- */
blockquote {
padding: 0 1rem;
color: #6a6a6a;
border-left: .25rem solid #353535;
margin-left: 0;
}
/* GitHub-style alerts */
.markdown-alert {
padding: 0.5rem 1rem;
margin-bottom: 1rem;
}
.markdown-alert > :first-child {
margin-top: 0;
}
.markdown-alert > :last-child {
margin-bottom: 0;
}
.markdown-alert .markdown-alert-title {
display: flex;
font-weight: 500;
align-items: center;
line-height: 1;
}
.markdown-alert .markdown-alert-title .octicon {
margin-right: 0.5rem;
display: inline-block;
overflow: visible !important;
vertical-align: text-bottom;
fill: currentColor;
}
.markdown-alert-note {
border-left: .25rem solid var(--color-alert-note);
}
.markdown-alert-note .markdown-alert-title {
color: var(--color-alert-note);
}
.markdown-alert-tip {
border-left: .25rem solid var(--color-alert-tip);
}
.markdown-alert-tip .markdown-alert-title {
color: var(--color-alert-tip);
}
.markdown-alert-important {
border-left: .25rem solid var(--color-alert-important);
}
.markdown-alert-important .markdown-alert-title {
color: var(--color-alert-important);
}
.markdown-alert-warning {
border-left: .25rem solid var(--color-alert-warning);
}
.markdown-alert-warning .markdown-alert-title {
color: var(--color-alert-warning);
}
.markdown-alert-caution {
border-left: .25rem solid var(--color-alert-caution);
}
.markdown-alert-caution .markdown-alert-title {
color: var(--color-alert-caution);
}
/* --------------------------------------------------------------------------
* MISCELLANEOUS ------------------------------------------------------------ */
/* headings */
h1, h2 {
border-bottom: 0.2px solid #444;
padding-bottom: 0.75rem;
}
/* quotes */
blockquote {
padding: 0 1em;
color: #6a6a6a;
border-left: .25em solid #353535;
margin-left: 0
}
/* images */
img, svg { max-width: 100%; }

Expand All @@ -186,13 +248,20 @@ kbd {

/* highlight/mark */
mark {
background-color: rgba(255, 255, 175, 0.8);
color: #222;
background-color: rgba(255, 255, 175, 0.8);
color: #222;
}

/* --------------------------------------------------------------------------
* LIGHT MODE --------------------------------------------------------------- */
@media (prefers-color-scheme: light) {
:root {
--color-alert-note: #0969da;
--color-alert-tip: #1a7f37;
--color-alert-important: #8250df;
--color-alert-warning: #bf8700;
--color-alert-caution: #cf222e;
}
html {
background-color: white;
color: #1f2328;
Expand Down
22 changes: 22 additions & 0 deletions tests/markdown-additional.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,25 @@ Press <kbd>Ctrl</kbd> + <kbd>C</kbd> to copy, and <kbd>Ctrl</kbd> + <kbd>V</kbd>
## Custom attributes

This paragraph has a red background color.{style=background-color:red}

## Github alert blockquote

> [!NOTE]
> Something to take into account

> [!TIP]
> Did you know you can do this and that

> [!IMPORTANT]
> Crucial information here

> [!WARNING]
> Critical content demanding immediate attention

> [!CAUTION]
> Do not do this and that!

With a custom title:

> [!NOTE] Foo bar
> Hello
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1762,6 +1762,11 @@ markdown-it-footnote@^4.0.0:
resolved "https://registry.yarnpkg.com/markdown-it-footnote/-/markdown-it-footnote-4.0.0.tgz#02ede0cb68a42d7e7774c3abdc72d77aaa24c531"
integrity sha512-WYJ7urf+khJYl3DqofQpYfEYkZKbmXmwxQV8c8mO/hGIhgZ1wOe7R4HLFNwqx7TjILbnC98fuyeSsin19JdFcQ==

markdown-it-github-alerts@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/markdown-it-github-alerts/-/markdown-it-github-alerts-0.3.0.tgz#acab7db57f4e204c8d1c987403c367738d7026b0"
integrity sha512-qyIuDyfdrVGHhY+E/44yMyNA3ZnayaT/KKT2VgkIz1nmrgiuPkdgPUh4YBZwgJ9VKEGJvGd82Ndrc4oGftrJWg==

markdown-it-inject-linenumbers@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/markdown-it-inject-linenumbers/-/markdown-it-inject-linenumbers-0.3.0.tgz#654364fa7a2dcb5f4461ef6d29d2603b74b29fd7"
Expand Down