Skip to content

Commit db995a7

Browse files
committed
adding capability of inline code snippets
1 parent aa3bf6f commit db995a7

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "blog",
4-
"version": "0.1.0",
4+
"version": "0.1.1",
55
"license": "MIT",
66
"scripts": {
77
"start": "per-env",

src/routes/blog/formatted-code-block.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ import { h } from 'preact';
22
import { useState } from 'preact/hooks';
33

44
import { vs } from 'react-syntax-highlighter/dist/esm/styles/prism';
5+
import style from './style.css';
56

67
export function FormattedCodeBlock(props) {
78
const [component, setComponent] = useState(null);
89
if (component) {
910
return component;
1011
}
12+
if (!props.class) {
13+
return (<code class={style.inline}>{props.children}</code>);
14+
}
1115
throw new Promise(resolve => {
1216
let language = null;
1317
const highlighter = import('react-syntax-highlighter/dist/esm/prism-light');
@@ -29,6 +33,10 @@ export function FormattedCodeBlock(props) {
2933
language = 'typescript';
3034
languageSyntax = import('react-syntax-highlighter/dist/esm/languages/prism/typescript');
3135
break;
36+
default:
37+
language = 'markdown';
38+
languageSyntax = import('react-syntax-highlighter/dist/esm/languages/prism/markdown');
39+
break;
3240
}
3341
Promise.all([highlighter, languageSyntax]).then(values => {
3442
const [SyntaxHighlighter, languageHighlighter] = values.map(m => m ? m.default: null);

src/routes/blog/style.css

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
text-decoration: underline;
2626
}
2727

28-
.blogbody code {
28+
.blogbody pre code {
2929
display: block;
3030
max-width: 100%;
3131
color: rgb(57, 58, 52);
@@ -39,6 +39,14 @@
3939
line-height: 1.2em;
4040
tab-size: 4;
4141
hyphens: none;
42+
overflow-x: scroll;
43+
}
44+
45+
code.inline {
46+
display: inline;
47+
max-width: none;
48+
background: #ddd;
49+
padding: 0px 4px;
4250
}
4351

4452
.blogbody pre pre {

0 commit comments

Comments
 (0)