Skip to content

Commit 64e9459

Browse files
slusarzcmouse
authored andcommitted
utility.js: resolveURL() is now only used in markdown.js
opts.removeURL() is now an alias to the function, so configs that use markdown_extend config can access it
1 parent dd32692 commit 64e9459

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ Dovecot-specific markdown processing (i.e. [[xyz,...]]).
208208

209209
Opening tag function. Returns opening tag.
210210

211+
The opts argument contains a "resolveURL" key that allows access to the
212+
internal Dovecot Markdown `resolveURL()` function.
213+
211214
Example: `open: (mode, parts, opts, env) => { return '' }`
212215

213216
##### body

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, resolveURL } from './utility.js'
6+
import { dovecotSetting, frontmatterIter, loadData } from './utility.js'
77

88
let md_conf = null
99
export async function dovecotMdExtend(md) {
@@ -174,8 +174,8 @@ function dovecot_markdown(md, opts) {
174174
}
175175

176176
return '<code><a href="' +
177-
resolveURL('core/summaries/' + page + '.html#' + env.inner,
178-
opts.base) + '">'
177+
resolveURL('core/summaries/' + page + '.html#' + env.inner) +
178+
'">'
179179

180180
case 'link':
181181
let url = '#'
@@ -206,8 +206,8 @@ function dovecot_markdown(md, opts) {
206206
}
207207

208208
return '<code><a href="' +
209-
resolveURL('core/man/' + env.inner + '.' + env.args,
210-
opts.base) + '.html' + (hash ? '#' + hash : '') + '">'
209+
resolveURL('core/man/' + env.inner + '.' + env.args) +
210+
'.html' + (hash ? '#' + hash : '') + '">'
211211

212212
case 'plugin':
213213
env.inner = parts[1]
@@ -222,8 +222,7 @@ function dovecot_markdown(md, opts) {
222222
}
223223

224224
return '<a href="' +
225-
resolveURL('core/plugins/' + plugin + '.html', opts.base) +
226-
'">'
225+
resolveURL('core/plugins/' + plugin + '.html') + '">'
227226

228227
case 'removed':
229228
env.args = parts[1]
@@ -275,8 +274,7 @@ function dovecot_markdown(md, opts) {
275274
}
276275

277276
return '<code><a href="' +
278-
resolveURL('core/settings/variables.html' + hash,
279-
opts.base) + '">'
277+
resolveURL('core/settings/variables.html' + hash) + '">'
280278

281279
default:
282280
initMarkdownExtend()
@@ -394,7 +392,7 @@ function dovecot_markdown(md, opts) {
394392
}
395393

396394
links[k] = {
397-
url: resolveURL(rewrites[f].substring(0, rewrites[f].lastIndexOf('.')) + '.html', opts.base)
395+
url: resolveURL(rewrites[f].substring(0, rewrites[f].lastIndexOf('.')) + '.html')
398396
}
399397

400398
if ((typeof v) == 'object') {
@@ -436,8 +434,15 @@ function dovecot_markdown(md, opts) {
436434
}
437435
}
438436

437+
function resolveURL(url) {
438+
return (opts.base.endsWith('/') ? opts.base.slice(0, -1) : opts.base) +
439+
'/' + url
440+
}
441+
439442
md.inline.ruler.after('emphasis', 'dovecot_brackets', process_brackets)
440443
md.renderer.rules.dovecot_open = dovecot_open
441444
md.renderer.rules.dovecot_body = dovecot_body
442445
md.renderer.rules.dovecot_close = dovecot_close
446+
447+
opts.resolveURL = resolveURL
443448
}

lib/utility.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,3 @@ export function frontmatterIter(files, callback) {
9393
}
9494
}
9595
}
96-
97-
export function resolveURL(url, base) {
98-
return (base.endsWith('/') ? base.slice(0, -1) : base) + '/' + url
99-
}

0 commit comments

Comments
 (0)