-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathshortcodes.ts
56 lines (46 loc) · 1.6 KB
/
shortcodes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import markdown from './markdown';
import { stripIndents } from 'common-tags';
export const note = (content: string, { type = 'Note' } = {}): string =>
`<section class='note' aria-label='${type}' aria-role='note'>${markdown.render(
content,
)}</section>`;
export const callout = (content: string): string =>
`<section class='callout' aria-role='note'>${markdown.render(content)}</section>`;
interface BibleRef {
source: {
book: string;
translation: string;
passage: string;
};
}
interface Quote {
source: {
author?: string;
title: string;
};
location?: string;
}
type Reference = Quote | BibleRef;
export const quote = (content: string, ref: Reference): string => {
let citation = isBibleRef(ref) ? bibleRef(ref) : basicCitation(ref);
// Because it's really important here *not* to include indentation so
// this can run *before* Markdown parsing runs on the rest of it.
return stripIndents`<figure class='quotation'>
<blockquote>
${markdown.render(content)}
</blockquote>
<figcaption>—${citation}</figcaption>
</figure>
`;
function bibleRef({ source: bible }: BibleRef): string {
return `${bible.book} ${bible.passage} (${bible.translation})`;
}
function basicCitation(quote: Quote): string {
let author = quote.source.author ? `${quote.source.author}, ` : '';
let location = quote.location ? `, ${quote.location}` : '';
return `${author}<cite>${quote.source.title}</cite>${location}`;
}
};
function isBibleRef(ref: Reference): ref is BibleRef {
return 'book' in ref.source;
}