Skip to content

Commit

Permalink
make yaml title rules ignore code blocks (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
haloislet authored Apr 1, 2022
1 parent 31b4dbf commit f841184
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -799,16 +799,14 @@ export const rules: Rule[] = [
RuleType.YAML,
(text: string, options = {}) => {
text = initYAML(text);

// find first H1
const h1_match = /^#\s(.*)$/gm;
const h1_match_str = h1_match.exec(text);
let title = '';
if (h1_match_str) {
title = h1_match_str[1];
} else {
title = options['metadata: file name'];
}
let title = ignoreCodeBlocksAndYAML(text, (text) => {
const result = text.match(/^#\s+(.*)/m);
if (result) {
return result[1];
}
return '';
});
title = title || options['metadata: file name'];

return formatYAML(text, (text) => {
const title_match_str = `\n${options['Title Key']}.*\n`;
Expand Down

0 comments on commit f841184

Please sign in to comment.