Skip to content

Commit 3b6679a

Browse files
authored
Add markdown include event (#2284)
1 parent e15e839 commit 3b6679a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/lib/output/events.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ export class PageEvent<out Model = unknown> extends Event {
139139
* An event emitted when markdown is being parsed. Allows other plugins to manipulate the result.
140140
*
141141
* @see {@link MarkdownEvent.PARSE}
142+
* @see {@link MarkdownEvent.INCLUDE}
142143
*/
143144
export class MarkdownEvent extends Event {
144145
/**
@@ -162,6 +163,12 @@ export class MarkdownEvent extends Event {
162163
*/
163164
static readonly PARSE = "parseMarkdown";
164165

166+
/**
167+
* Triggered on the renderer when this plugin includes a markdown file through a markdown include tag.
168+
* @event
169+
*/
170+
static readonly INCLUDE = "includeMarkdown";
171+
165172
constructor(
166173
name: string,
167174
page: PageEvent,

src/lib/output/themes/MarkedPlugin.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,14 @@ output file :
9595
path = Path.join(this.includes!, path.trim());
9696
if (isFile(path)) {
9797
const contents = readFile(path);
98-
return contents;
98+
const event = new MarkdownEvent(
99+
MarkdownEvent.INCLUDE,
100+
page,
101+
contents,
102+
contents
103+
);
104+
this.owner.trigger(event);
105+
return event.parsedText;
99106
} else {
100107
this.application.logger.warn(
101108
"Could not find file to include: " + path

0 commit comments

Comments
 (0)