Skip to content

Commit

Permalink
Merge branch 'main' of github.com:quarto-dev/quarto-cli into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Aug 30, 2021
2 parents 51ad172 + b4f66f0 commit 38dc472
Show file tree
Hide file tree
Showing 11 changed files with 1,066 additions and 220 deletions.
10 changes: 9 additions & 1 deletion src/core/break-quarto-md.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export interface QuartoMdCell {
cell_type: CodeCellType | "markdown" | "raw" | "math";
options?: Record<string, unknown>;
source: string[];

startingLoc: number;
}

export interface QuartoMdChunks {
Expand All @@ -46,6 +48,8 @@ export function breakQuartoMd(
const delimitMathBlockRegEx = /^\$\$/;
let language = ""; // current language block

let loc = 0;
let blockStartingLoc = 1;
// line buffer
const lineBuffer: string[] = [];
const flushLineBuffer = (
Expand All @@ -65,16 +69,18 @@ export function breakQuartoMd(
source: lineBuffer.map((line, index) => {
return line + (index < (lineBuffer.length - 1) ? "\n" : "");
}),
startingLoc: blockStartingLoc,
};

if (cell_type === "code" && (language === "ojs" || language === "dot")) {
// see if there is embedded metadata we should forward into the cell metadata
const { yaml, source } = partitionCellOptions(
const { yaml, source, yamlLength } = partitionCellOptions(
"js",
cell.source,
);
cell.source = source;
cell.options = yaml;
cell.startingLoc += yamlLength;
}

// if the source is empty then don't add it
Expand All @@ -84,6 +90,7 @@ export function breakQuartoMd(
}

lineBuffer.splice(0, lineBuffer.length);
blockStartingLoc = loc;
}
};

Expand All @@ -93,6 +100,7 @@ export function breakQuartoMd(
inCodeCell = false,
inCode = false;
for (const line of lines(src)) {
loc += 1;
// yaml front matter
if (yamlRegEx.test(line) && !inCodeCell && !inCode && !inMathBlock) {
if (inYaml) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/partition-cell-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export function partitionCellOptions(
const commentChars = langCommentChars(language);
const optionPrefix = optionCommentPrefix(commentChars[0]);
const optionSuffix = commentChars[1] || "";

// find the yaml lines
const yamlLines: string[] = [];
for (const line of source) {
Expand Down Expand Up @@ -52,6 +51,7 @@ export function partitionCellOptions(
return {
yaml: yaml as Record<string, unknown> | undefined,
source: source.slice(yamlLines.length),
yamlLength: yamlLines.length
};
}

Expand Down
Loading

0 comments on commit 38dc472

Please sign in to comment.