Skip to content

Commit 7d4d03e

Browse files
committed
markdown.js: Allow Dovecot markdown generated URLs to be rewritten
1 parent 079dc56 commit 7d4d03e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,13 @@ Paths are relative to project base.
216216

217217
Supports fast-glob: https://github.com/mrmlnc/fast-glob#pattern-syntax
218218

219+
#### url_rewrite
220+
221+
A callback where Markdown generated URLs can be rewritten.
222+
Function is called the original URL and returns the (modified) URL.
223+
224+
Example: `url_rewrite: (url) => { return url + '.foo' }`
225+
219226
#### watch_paths
220227

221228
An array of file patterns to watch to refresh data loaders in dev mode.

lib/markdown.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,14 @@ function dovecot_markdown(md, opts) {
435435
}
436436

437437
function resolveURL(url) {
438-
return (opts.base.endsWith('/') ? opts.base.slice(0, -1) : opts.base) +
438+
if (!('url_rewrite' in opts)) {
439+
opts.url_rewrite = dovecotSetting('url_rewrite')
440+
}
441+
442+
const url =
443+
(opts.base.endsWith('/') ? opts.base.slice(0, -1) : opts.base) +
439444
'/' + url
445+
return (opts.url_rewrite) ? opts.url_rewrite(url) : url
440446
}
441447

442448
md.inline.ruler.after('emphasis', 'dovecot_brackets', process_brackets)

0 commit comments

Comments
 (0)