Skip to content

Commit 63cd82e

Browse files
committed
Copy Markdown
1 parent bc47206 commit 63cd82e

13 files changed

Lines changed: 649 additions & 525 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ExDoc is a tool to generate documentation for Erlang and Elixir projects. To see
88

99
ExDoc ships with many features:
1010

11-
* Automatically generates offline-accessible HTML, Markdown, and EPUB documents from your API documentation.
11+
* Automatically generates offline-accessible HTML, Markdown (including `llms.txt`), and EPUB documents from your API documentation.
1212
* When hosted, ExDoc relies on browser's page transitions for better UX, caching, and enhanced accessibility.
1313
* Responsive design, covering phones and tablets.
1414
* Support for custom pages, guides, livebooks and cheatsheets.

assets/css/content/admonition.css

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,11 @@
2222
}
2323

2424
.content-inner section.admonition {
25-
/* Default icon */
26-
& .admonition-title::before {
27-
content: var(--icon-error-warning);
28-
}
29-
3025
&.warning {
3126
background-color: var(--warningBackground);
3227
& .admonition-title {
3328
&, &::before {
29+
content: var(--icon-error-warning);
3430
color: var(--warningHeading);
3531
}
3632
}
@@ -39,6 +35,7 @@
3935
background-color: var(--errorBackground);
4036
& .admonition-title {
4137
&, &::before {
38+
content: var(--icon-error-warning);
4239
color: var(--errorHeading);
4340
}
4441
}
@@ -47,6 +44,7 @@
4744
background-color: var(--infoBackground);
4845
& .admonition-title {
4946
&, &::before {
47+
content: var(--icon-information);
5048
color: var(--infoHeading);
5149
}
5250
}
@@ -64,6 +62,7 @@
6462
background-color: var(--tipBackground);
6563
& .admonition-title {
6664
&, &::before {
65+
content: var(--icon-information);
6766
color: var(--tipHeading);
6867
}
6968
}

assets/css/toast.css

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,37 @@
22
visibility: hidden;
33
opacity: 0;
44
position: fixed;
5-
z-index: 1;
6-
left: 50%;
7-
bottom: 1rem;
5+
z-index: 1000;
6+
right: 10px;
7+
top: 0px;
8+
font-size: 0.9rem;
89
min-width: 3rem;
9-
margin: 0 -1.2rem;
10-
padding: .7rem 1.2rem;
11-
text-align: center;
12-
font-weight: 700;
10+
padding: .7rem 1.2rem .7rem 2.8rem;
11+
text-align: left;
12+
font-weight: 400;
1313
border-radius: var(--borderRadius-base);
14-
border: 1px solid var(--codeBorder);
15-
background-color: var(--codeBackground);
16-
color: var(--textBody);
14+
border: 1px solid hsl(from var(--tipHeading) h s l / 15%);
15+
background-color: var(--tipBackground);
16+
color: var(--tipHeading);
1717
transition: opacity .4s ease-in-out, transform .3s ease-out;
1818
cursor: default;
1919
}
2020

21+
#toast::before {
22+
content: var(--icon-information);
23+
position: absolute;
24+
left: 1rem;
25+
font-size: 1.2rem;
26+
font-family: 'remixicon';
27+
font-style: normal;
28+
-webkit-font-smoothing: antialiased;
29+
-moz-osx-font-smoothing: grayscale;
30+
}
31+
2132
#toast.show {
2233
visibility: visible;
2334
opacity: 1;
24-
transform: translateY(-.75rem);
35+
transform: translateY(.75rem);
2536
}
2637

2738
@media (prefers-reduced-motion: reduce) {

assets/js/copy-markdown.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { qsAll } from './helpers'
2+
import { showToast } from './toast'
3+
4+
/**
5+
* Initializes copy markdown links.
6+
*/
7+
8+
window.addEventListener('exdoc:loaded', initialize)
9+
10+
function initialize () {
11+
if (!('clipboard' in navigator)) return
12+
13+
qsAll('a.copy-markdown').forEach(link => {
14+
link.addEventListener('click', handleCopyMarkdownClick)
15+
})
16+
}
17+
18+
/**
19+
* Handles clicks on copy markdown links.
20+
*
21+
* If Ctrl/Cmd is held, allows normal link behavior.
22+
* Otherwise, attempts to fetch and copy the markdown to clipboard.
23+
*
24+
* @param {MouseEvent} event
25+
*/
26+
function handleCopyMarkdownClick (event) {
27+
if (event.ctrlKey || event.metaKey) {
28+
return
29+
}
30+
31+
event.preventDefault()
32+
const link = event.currentTarget
33+
const markdownUrl = link.href
34+
35+
// Use ClipboardItem with a promise for Safari compatibility as it
36+
// requires the clipboard API to be called synchronously during user gesture
37+
const clipboardItem = new ClipboardItem({
38+
'text/plain': fetch(markdownUrl)
39+
.then(response => {
40+
if (!response.ok) {
41+
throw new Error('Failed to fetch markdown')
42+
}
43+
return response.text()
44+
})
45+
.then(markdown => {
46+
return new Blob([markdown], { type: 'text/plain' })
47+
})
48+
})
49+
50+
navigator.clipboard.write([clipboardItem])
51+
.then(() => {
52+
showToast('Page copied as Markdown to clipboard')
53+
})
54+
.catch((error) => {
55+
console.log('Copying Markdown failed:', error)
56+
57+
const shouldOpen = window.confirm(
58+
'Could not copy to clipboard. Do you want to open the Markdown page instead?'
59+
)
60+
if (shouldOpen) {
61+
window.location.href = markdownUrl
62+
}
63+
})
64+
}

assets/js/entry/html.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import '../makeup'
1111
import '../search-bar'
1212
import '../tooltips/tooltips'
1313
import '../copy-button'
14+
import '../copy-markdown'
1415
import '../search-page'
1516
import '../settings'
1617
import '../keyboard-shortcuts'

0 commit comments

Comments
 (0)