Skip to content

Commit e6b0a73

Browse files
committed
fix(ddocs): ignore md preambles
* handle preambles delimited by --- lines * make ignore prefixes easier to extend closes #221
1 parent 5f33778 commit e6b0a73

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/util/discordDocs.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ function cleanLine(line: string) {
6666
.trim();
6767
}
6868

69+
const IGNORE_LINE_PREFIXES = ['>', '---', '|'];
70+
6971
export function parseSections(content: string): ParsedSection[] {
7072
const res = [];
7173
const section: ParsedSection = {
@@ -74,10 +76,23 @@ export function parseSections(content: string): ParsedSection[] {
7476
headline: '',
7577
};
7678

79+
let withinPreamble = false;
80+
let index = 0;
7781
for (const line of content.split('\n')) {
7882
const cleanedLine = cleanLine(line);
7983

80-
if (line.startsWith('>')) {
84+
if (line.startsWith('---')) {
85+
if (index === 0) {
86+
withinPreamble = true;
87+
} else if (withinPreamble) {
88+
withinPreamble = false;
89+
}
90+
}
91+
92+
index++;
93+
94+
const startsWithIgnorePrefix = IGNORE_LINE_PREFIXES.some((prefix) => line.startsWith(prefix));
95+
if (withinPreamble || startsWithIgnorePrefix) {
8196
continue;
8297
}
8398

0 commit comments

Comments
 (0)