MCPcopy Create free account
hub / github.com/REditorSupport/vscode-R / getYamlFrontmatter

Method getYamlFrontmatter

src/rmarkdown/knit.ts:89–128  ·  view source on GitHub ↗
(docPath: string)

Source from the content-addressed store, hash-verified

87 }
88
89 private getYamlFrontmatter(docPath: string): IYamlFrontmatter {
90 const text = fs.readFileSync(docPath, 'utf8');
91 const lines = text.split('\n');
92 let startLine = -1;
93 let endLine = -1;
94 for (let i = 0; i < lines.length; i++) {
95 if (/\S/.test(lines[i])) {
96 if (startLine < 0) {
97 if (lines[i].startsWith('---')) {
98 startLine = i;
99 } else {
100 break;
101 }
102 } else {
103 if (lines[i].startsWith('---')) {
104 endLine = i;
105 break;
106 }
107 }
108 }
109 }
110
111 let yamlText: string | undefined = undefined;
112 if (startLine + 1 < endLine) {
113 yamlText = lines.slice(startLine + 1, endLine).join('\n');
114 }
115
116 let paramObj: IYamlFrontmatter = {};
117 if (yamlText) {
118 try {
119 paramObj = yaml.load(
120 yamlText
121 ) as IYamlFrontmatter;
122 } catch (e) {
123 console.error(`Could not parse YAML frontmatter for "${docPath}". Error: ${String(e)}`);
124 }
125 }
126
127 return paramObj;
128 }
129
130 private async getKnitCommand(yamlParams: IYamlFrontmatter, docPath: string, outputFormat?: string): Promise<string | undefined> {
131 let knitCommand: string;

Callers 2

findSiteParamMethod · 0.95
knitRmdMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected