mirror of
https://github.com/alrayyes/wiki.git
synced 2025-05-02 23:08:14 +00:00
heading linking
This commit is contained in:
parent
04eeb2d10c
commit
fcd81353f8
7 changed files with 104 additions and 11 deletions
|
@ -2,13 +2,17 @@ import { PluggableList } from "unified"
|
|||
import remarkGfm from "remark-gfm"
|
||||
import smartypants from 'remark-smartypants'
|
||||
import { QuartzTransformerPlugin } from "../types"
|
||||
import rehypeSlug from "rehype-slug"
|
||||
import rehypeAutolinkHeadings from "rehype-autolink-headings/lib"
|
||||
|
||||
export interface Options {
|
||||
enableSmartyPants: boolean
|
||||
linkHeadings: boolean
|
||||
}
|
||||
|
||||
const defaultOptions: Options = {
|
||||
enableSmartyPants: true
|
||||
enableSmartyPants: true,
|
||||
linkHeadings: true
|
||||
}
|
||||
|
||||
export class GitHubFlavoredMarkdown extends QuartzTransformerPlugin {
|
||||
|
@ -25,6 +29,13 @@ export class GitHubFlavoredMarkdown extends QuartzTransformerPlugin {
|
|||
}
|
||||
|
||||
htmlPlugins(): PluggableList {
|
||||
return []
|
||||
return this.opts.linkHeadings
|
||||
? [rehypeSlug, [rehypeAutolinkHeadings, {
|
||||
behavior: 'append', content: {
|
||||
type: 'text',
|
||||
value: '§'
|
||||
}
|
||||
}]]
|
||||
: []
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,9 +42,9 @@ export class ObsidianFlavoredMarkdown extends QuartzTransformerPlugin {
|
|||
|
||||
} else {
|
||||
const [path, rawHeader, rawAlias] = capture
|
||||
const header = rawHeader?.slice(1).trim() ?? ""
|
||||
const anchor = rawHeader?.slice(1).trim() ?? ""
|
||||
const alias = rawAlias?.slice(1).trim() ?? path
|
||||
const url = slugify(path.trim() + header)
|
||||
const url = slugify(path.trim() + anchor)
|
||||
return {
|
||||
type: 'link',
|
||||
url,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue