Skip to content

Commit 3a2a19f

Browse files
committed
local.js: Move markdown_extend out of local config file
1 parent ff282dc commit 3a2a19f

File tree

4 files changed

+38
-40
lines changed

4 files changed

+38
-40
lines changed

.vitepress/local.js.dist

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,3 @@
1212
export const data_paths = {
1313
// doveadm: '../data/doveadm.js',
1414
}
15-
16-
// Enable additional labels to support in Dovecot-specific markdown
17-
// processing (i.e. [[xyz,...]]).
18-
export const markdown_extend = {
19-
20-
// Init function. Return value is configuration options to add to markdown
21-
// object.
22-
// init: () => { return {} },
23-
24-
// Opening tag function. Returns opening tag.
25-
// open: (mode, parts, opts, env) => { return '' },
26-
27-
// Body function. Returns body text.
28-
// body: (mode, env) => { return '' },
29-
30-
// Close tag function. Returns closing tag.
31-
// close: (mode, env) => { return '' },
32-
33-
}

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,29 @@ Paths are relative to project base.
176176

177177
Supports fast-glob: https://github.com/mrmlnc/fast-glob#pattern-syntax
178178

179+
#### markdown_extend
180+
181+
An object containing callbacks that enable additional labels to support in
182+
Dovecot-specific markdown processing (i.e. [[xyz,...]]).
183+
184+
##### open
185+
186+
Opening tag function. Returns opening tag.
187+
188+
Example: `open: (mode, parts, opts, env) => { return '' }`
189+
190+
##### body
191+
192+
Body function. Returns body text.
193+
194+
Example: `body: (mode, env) => { return '' }`
195+
196+
##### close
197+
198+
Close tag function. Returns closing tag.
199+
200+
Example: `close: (mode, env) => { return '' }`
201+
179202
#### plugin_paths
180203

181204
A listing of paths containing plugin files.

lib/markdown.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import fg from 'fast-glob'
33
import deflistPlugin from 'markdown-it-deflist'
44
import path from 'path'
55
import { createMarkdownRenderer } from 'vitepress'
6-
import { dovecotSetting, frontmatterIter, loadData, markdownExtension, resolveURL } from './utility.js'
6+
import { dovecotSetting, frontmatterIter, loadData, resolveURL } from './utility.js'
77

88
let md_conf = null
99
export async function initDovecotMd(base) {
@@ -12,15 +12,12 @@ export async function initDovecotMd(base) {
1212
}
1313

1414
md_conf = {
15-
...{
16-
base: base,
17-
doveadm: (await loadData('doveadm')).doveadm,
18-
events: (await loadData('events')).events,
19-
linkoverrides: (await loadData('links_overrides')).links_overrides,
20-
settings: (await loadData('settings')).settings,
21-
updates: (await loadData('updates')).updates
22-
},
23-
...(await markdownExtension())
15+
base: base,
16+
doveadm: (await loadData('doveadm')).doveadm,
17+
events: (await loadData('events')).events,
18+
linkoverrides: (await loadData('links_overrides')).links_overrides,
19+
settings: (await loadData('settings')).settings,
20+
updates: (await loadData('updates')).updates
2421
}
2522
}
2623

@@ -291,6 +288,8 @@ function dovecot_markdown(md, opts) {
291288
opts.base) + '">'
292289

293290
default:
291+
initMarkdownExtend()
292+
294293
return handle_default(mode,
295294
opts.markdown?.open?.(mode, parts, opts, env))
296295
}
@@ -432,6 +431,12 @@ function dovecot_markdown(md, opts) {
432431
}
433432
}
434433

434+
function initMarkdownExtend() {
435+
if (!opts.markdown) {
436+
opts.markdown = dovecotSetting('markdown_extend') ?? {}
437+
}
438+
}
439+
435440
function initPluginFiles() {
436441
if (!opts.plugins) {
437442
opts.plugins = dovecotSetting('plugin_paths').flatMap((x) =>

lib/utility.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,6 @@ async function loadLocalConf() {
4141
return local_conf
4242
}
4343

44-
export async function markdownExtension() {
45-
const lconf = await loadLocalConf()
46-
47-
return {
48-
...{
49-
markdown: lconf.markdown_extend ?? {},
50-
},
51-
...(lconf.markdown_extend?.init?.() ?? {})
52-
}
53-
}
54-
5544
export async function loadData(id) {
5645
/* Check for config override file. */
5746
const lconf = await loadLocalConf()

0 commit comments

Comments
 (0)