Skip to content

Commit

Permalink
fix(ddocs): ignore md preambles
Browse files Browse the repository at this point in the history
* handle preambles delimited by --- lines
* make ignore prefixes easier to extend

closes #221
  • Loading branch information
almostSouji committed Oct 12, 2024
1 parent 5f33778 commit e6b0a73
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/util/discordDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ function cleanLine(line: string) {
.trim();
}

const IGNORE_LINE_PREFIXES = ['>', '---', '|'];

export function parseSections(content: string): ParsedSection[] {
const res = [];
const section: ParsedSection = {
Expand All @@ -74,10 +76,23 @@ export function parseSections(content: string): ParsedSection[] {
headline: '',
};

let withinPreamble = false;
let index = 0;
for (const line of content.split('\n')) {
const cleanedLine = cleanLine(line);

if (line.startsWith('>')) {
if (line.startsWith('---')) {
if (index === 0) {
withinPreamble = true;
} else if (withinPreamble) {
withinPreamble = false;
}
}

index++;

const startsWithIgnorePrefix = IGNORE_LINE_PREFIXES.some((prefix) => line.startsWith(prefix));
if (withinPreamble || startsWithIgnorePrefix) {
continue;
}

Expand Down

0 comments on commit e6b0a73

Please sign in to comment.