-
Notifications
You must be signed in to change notification settings - Fork 307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: docs preprocessor line numbers and errors #1883
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
const { match } = require("assert"); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
|
@@ -168,19 +167,10 @@ function extractCodeSnippet(filePath, identifier) { | |
// We have our code snippet! | ||
let codeSnippet = lines.join("\n"); | ||
|
||
let startCharIndex = startMatch.index; | ||
let endCharIndex = endMatch.index; | ||
|
||
const startLine = getLineNumberFromIndex(codeSnippet, startCharIndex) + 1; | ||
const endLine = | ||
getLineNumberFromIndex(codeSnippet, endCharIndex) - | ||
1 - | ||
linesToRemove.length; | ||
|
||
Comment on lines
-171
to
-179
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was incorrect. I've removed it. We already had startLineNum and endLineNum in this function, which give the right values. |
||
// The code snippet might contain some docusaurus highlighting comments for other identifiers. We should remove those. | ||
codeSnippet = processHighlighting(codeSnippet, identifier); | ||
|
||
return [codeSnippet, startLine, endLine]; | ||
return [codeSnippet, startLineNum, endLineNum]; | ||
} | ||
|
||
async function processMarkdownFilesInDir(rootDir, docsDir, regex) { | ||
|
@@ -207,10 +197,16 @@ async function processMarkdownFilesInDir(rootDir, docsDir, regex) { | |
matchesFound = true; | ||
const fullMatch = match[0]; | ||
const identifier = match[1]; | ||
const codeFilePath = match[2]; // Absolute path to the code file from the root of the Docusaurus project | ||
let codeFilePath = match[2]; | ||
const language = match[3]; | ||
const opts = match[4] || ""; | ||
|
||
if (codeFilePath.slice(0) != "/") { | ||
// Absolute path to the code file from the root of the Docusaurus project | ||
// Note: without prefixing with `/`, the later call to `path.resolve()` gives an incorrect path (absolute instead of relative) | ||
codeFilePath = `/${codeFilePath}`; | ||
iAmMichaelConnor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
const noTitle = opts.includes("noTitle"); | ||
const noLineNumbers = opts.includes("noLineNumbers"); | ||
const noSourceLink = opts.includes("noSourceLink"); | ||
|
@@ -224,10 +220,9 @@ async function processMarkdownFilesInDir(rootDir, docsDir, regex) { | |
identifier | ||
); | ||
|
||
const url = `https://github.com/AztecProtocol/aztec-packages/blob/master/${path.resolve( | ||
rootDir, | ||
codeFilePath | ||
)}#L${startLine}-L${endLine}`; | ||
const relativeCodeFilePath = path.resolve(rootDir, codeFilePath); | ||
|
||
const url = `https://github.com/AztecProtocol/aztec-packages/blob/master/${relativeCodeFilePath}#L${startLine}-L${endLine}`; | ||
|
||
const title = noTitle ? "" : `title="${identifier}"`; | ||
const lineNumbers = noLineNumbers ? "" : "showLineNumbers"; | ||
|
@@ -242,14 +237,8 @@ async function processMarkdownFilesInDir(rootDir, docsDir, regex) { | |
const lineNum = getLineNumberFromIndex(markdownContent, match.index); | ||
let wrapped_msg = `Error processing "${filePath}:${lineNum}": ${error.message}.`; | ||
|
||
// Let's just output a warning, so we don't ruin our development experience. | ||
// throw new Error(wrapped_msg); | ||
console.warn( | ||
"\n\x1b[33m%s\x1b[0m%s", | ||
"[WARNING] ", | ||
wrapped_msg, | ||
"\n" | ||
); | ||
// We were warning here, but code snippets were being broken. So making this throw an error instead: | ||
throw new Error(`${wrapped_msg}\n`); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this, because Sean's recent PR hides all of this from the user, so it doesn't need an explanation anymore.