aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2022-10-23 02:10:32 +0300
committereug-vs <eugene@eug-vs.xyz>2022-10-23 02:10:32 +0300
commit9fe22ea6481754a4d68d9f01beb2c26412a2eb07 (patch)
tree131883704b96b30a8662e4cda61c76837a765068
parent6e6c4860d2dc3ff89b29878f196eda3e62d64486 (diff)
downloadbenzin-next-9fe22ea6481754a4d68d9f01beb2c26412a2eb07.tar.gz
feat: autolink headings
-rw-r--r--package.json2
-rw-r--r--src/pages/[...path].tsx5
-rw-r--r--yarn.lock58
3 files changed, 64 insertions, 1 deletions
diff --git a/package.json b/package.json
index fe6f347..fd93f65 100644
--- a/package.json
+++ b/package.json
@@ -19,6 +19,8 @@
"react-dom": "18.2.0",
"react-markdown": "^8.0.3",
"react-syntax-highlighter": "^15.5.0",
+ "rehype-autolink-headings": "^6.1.1",
+ "rehype-slug": "^5.0.1",
"remark-gemoji": "^7.0.1",
"remark-gfm": "^3.0.1",
"unist-util-visit-parents": "^5.1.1"
diff --git a/src/pages/[...path].tsx b/src/pages/[...path].tsx
index 06ad09d..d37ec91 100644
--- a/src/pages/[...path].tsx
+++ b/src/pages/[...path].tsx
@@ -9,6 +9,8 @@ import remarkGemoji from 'remark-gemoji';
import benzinConfig from '../config';
import Code from '../Code';
import remarkGfm from 'remark-gfm';
+import rehypeSlug from 'rehype-slug';
+import rehypeAutolinkHeadings from 'rehype-autolink-headings';
const transformLinkUri = (uri: string): string => {
return uri.match(/(.*)\.md/)?.[1] || uri;
@@ -65,7 +67,8 @@ const Page: NextPage = ({ markdownSource, emojiFileNames }: any) => {
<ReactMarkdown
transformLinkUri={transformLinkUri}
transformImageUri={transformImageUri}
- rehypePlugins={[emojiPlugin(emojiFileNames), remarkGemoji, remarkGfm]}
+ rehypePlugins={[emojiPlugin(emojiFileNames), rehypeSlug, [rehypeAutolinkHeadings, { behavior: 'wrap' }]]}
+ remarkPlugins={[remarkGemoji, remarkGfm]}
components={{
emoji: Emoji,
img: Image,
diff --git a/yarn.lock b/yarn.lock
index a80309b..6807b8e 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1050,6 +1050,11 @@ get-symbol-description@^1.0.0:
call-bind "^1.0.2"
get-intrinsic "^1.1.1"
+github-slugger@^1.1.1:
+ version "1.4.0"
+ resolved "https://registry.yarnpkg.com/github-slugger/-/github-slugger-1.4.0.tgz#206eb96cdb22ee56fdc53a28d5a302338463444e"
+ integrity sha512-w0dzqw/nt51xMVmlaV1+JRzN+oCa1KfcgGEWhxUG16wbdA+Xnt/yoFO8Z8x/V82ZcZ0wy6ln9QDup5avbhiDhQ==
+
glob-parent@^5.1.2:
version "5.1.2"
resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.2.tgz#869832c58034fe68a4093c17dc15e8340d8401c4"
@@ -1154,11 +1159,38 @@ has@^1.0.3:
dependencies:
function-bind "^1.1.1"
+hast-util-has-property@^2.0.0:
+ version "2.0.0"
+ resolved "https://registry.yarnpkg.com/hast-util-has-property/-/hast-util-has-property-2.0.0.tgz#c15cd6180f3e535540739fcc9787bcffb5708cae"
+ integrity sha512-4Qf++8o5v14us4Muv3HRj+Er6wTNGA/N9uCaZMty4JWvyFKLdhULrv4KE1b65AthsSO9TXSZnjuxS8ecIyhb0w==
+
+hast-util-heading-rank@^2.0.0:
+ version "2.1.0"
+ resolved "https://registry.yarnpkg.com/hast-util-heading-rank/-/hast-util-heading-rank-2.1.0.tgz#c39f34fa8330ebfec03a08b5d5019ed56122029c"
+ integrity sha512-w+Rw20Q/iWp2Bcnr6uTrYU6/ftZLbHKhvc8nM26VIWpDqDMlku2iXUVTeOlsdoih/UKQhY7PHQ+vZ0Aqq8bxtQ==
+ dependencies:
+ "@types/hast" "^2.0.0"
+
+hast-util-is-element@^2.0.0:
+ version "2.1.2"
+ resolved "https://registry.yarnpkg.com/hast-util-is-element/-/hast-util-is-element-2.1.2.tgz#fc0b0dc7cef3895e839b8d66979d57b0338c68f3"
+ integrity sha512-thjnlGAnwP8ef/GSO1Q8BfVk2gundnc2peGQqEg2kUt/IqesiGg/5mSwN2fE7nLzy61pg88NG6xV+UrGOrx9EA==
+ dependencies:
+ "@types/hast" "^2.0.0"
+ "@types/unist" "^2.0.0"
+
hast-util-parse-selector@^2.0.0:
version "2.2.5"
resolved "https://registry.yarnpkg.com/hast-util-parse-selector/-/hast-util-parse-selector-2.2.5.tgz#d57c23f4da16ae3c63b3b6ca4616683313499c3a"
integrity sha512-7j6mrk/qqkSehsM92wQjdIgWM2/BW61u/53G6xmC8i1OmEdKLHbk419QKQUjz6LglWsfqoiHmyMRkP1BGjecNQ==
+hast-util-to-string@^2.0.0:
+ version "2.0.0"
+ resolved "https://registry.yarnpkg.com/hast-util-to-string/-/hast-util-to-string-2.0.0.tgz#b008b0a4ea472bf34dd390b7eea1018726ae152a"
+ integrity sha512-02AQ3vLhuH3FisaMM+i/9sm4OXGSq1UhOOCpTLLQtHdL3tZt7qil69r8M8iDkZYyC0HCFylcYoP+8IO7ddta1A==
+ dependencies:
+ "@types/hast" "^2.0.0"
+
hast-util-whitespace@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/hast-util-whitespace/-/hast-util-whitespace-2.0.0.tgz#4fc1086467cc1ef5ba20673cb6b03cec3a970f1c"
@@ -2268,6 +2300,32 @@ regexpp@^3.2.0:
resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.2.0.tgz#0425a2768d8f23bad70ca4b90461fa2f1213e1b2"
integrity sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg==
+rehype-autolink-headings@^6.1.1:
+ version "6.1.1"
+ resolved "https://registry.yarnpkg.com/rehype-autolink-headings/-/rehype-autolink-headings-6.1.1.tgz#0cb874a56f3de6ead1c2268d7f0fc5006f244db5"
+ integrity sha512-NMYzZIsHM3sA14nC5rAFuUPIOfg+DFmf9EY1YMhaNlB7+3kK/ZlE6kqPfuxr1tsJ1XWkTrMtMoyHosU70d35mA==
+ dependencies:
+ "@types/hast" "^2.0.0"
+ extend "^3.0.0"
+ hast-util-has-property "^2.0.0"
+ hast-util-heading-rank "^2.0.0"
+ hast-util-is-element "^2.0.0"
+ unified "^10.0.0"
+ unist-util-visit "^4.0.0"
+
+rehype-slug@^5.0.1:
+ version "5.0.1"
+ resolved "https://registry.yarnpkg.com/rehype-slug/-/rehype-slug-5.0.1.tgz#6e732d0c55b3b1e34187e74b7363fb53229e5f52"
+ integrity sha512-X5v3wV/meuOX9NFcGhJvUpEjIvQl2gDvjg3z40RVprYFt7q3th4qMmYLULiu3gXvbNX1ppx+oaa6JyY1W67pTA==
+ dependencies:
+ "@types/hast" "^2.0.0"
+ github-slugger "^1.1.1"
+ hast-util-has-property "^2.0.0"
+ hast-util-heading-rank "^2.0.0"
+ hast-util-to-string "^2.0.0"
+ unified "^10.0.0"
+ unist-util-visit "^4.0.0"
+
remark-gemoji@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/remark-gemoji/-/remark-gemoji-7.0.1.tgz#42488adb9a0731dc82cdcde45f8e7bd61d795303"