mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-03 07:57:22 +00:00
ReadWebpageTool: fix newlines in codeblocks
This commit is contained in:
2 files changed
+9
-9
No files matched your search
@@ -1,5 +1,5 @@
|
|||||||
import fs from 'fs';
|
import fs from 'node:fs';
|
||||||
import path from 'path';
|
import path from 'node:path';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
meta: {
|
meta: {
|
||||||
@@ -19,7 +19,7 @@ export default {
|
|||||||
|
|
||||||
create(context) {
|
create(context) {
|
||||||
const filename = context.getFilename();
|
const filename = context.getFilename();
|
||||||
|
|
||||||
// Only run this rule on HTML files
|
// Only run this rule on HTML files
|
||||||
if (!filename.endsWith('.html')) {
|
if (!filename.endsWith('.html')) {
|
||||||
return {};
|
return {};
|
||||||
@@ -29,11 +29,11 @@ export default {
|
|||||||
Program(node) {
|
Program(node) {
|
||||||
const sourceCode = context.getSourceCode();
|
const sourceCode = context.getSourceCode();
|
||||||
const htmlContent = sourceCode.getText();
|
const htmlContent = sourceCode.getText();
|
||||||
|
|
||||||
// Check for manifest link tag in HTML
|
// Check for manifest link tag in HTML
|
||||||
const manifestLinkRegex = /<link[^>]*rel=["']manifest["'][^>]*>/i;
|
const manifestLinkRegex = /<link[^>]*rel=["']manifest["'][^>]*>/i;
|
||||||
const manifestMatch = htmlContent.match(manifestLinkRegex);
|
const manifestMatch = htmlContent.match(manifestLinkRegex);
|
||||||
|
|
||||||
if (!manifestMatch) {
|
if (!manifestMatch) {
|
||||||
context.report({
|
context.report({
|
||||||
node,
|
node,
|
||||||
@@ -53,11 +53,11 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const manifestPath = hrefMatch[1];
|
const manifestPath = hrefMatch[1];
|
||||||
|
|
||||||
// Resolve the manifest file path relative to the project root
|
// Resolve the manifest file path relative to the project root
|
||||||
const htmlDir = path.dirname(filename);
|
const htmlDir = path.dirname(filename);
|
||||||
let resolvedManifestPath;
|
let resolvedManifestPath;
|
||||||
|
|
||||||
if (manifestPath.startsWith('/')) {
|
if (manifestPath.startsWith('/')) {
|
||||||
// Absolute path - check in public directory first, then project root
|
// Absolute path - check in public directory first, then project root
|
||||||
const publicPath = path.resolve(htmlDir, 'public' + manifestPath);
|
const publicPath = path.resolve(htmlDir, 'public' + manifestPath);
|
||||||
@@ -67,7 +67,7 @@ export default {
|
|||||||
// Relative path
|
// Relative path
|
||||||
resolvedManifestPath = path.resolve(htmlDir, manifestPath);
|
resolvedManifestPath = path.resolve(htmlDir, manifestPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the manifest file exists
|
// Check if the manifest file exists
|
||||||
if (!fs.existsSync(resolvedManifestPath)) {
|
if (!fs.existsSync(resolvedManifestPath)) {
|
||||||
context.report({
|
context.report({
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ export class ReadWebpageTool implements Tool<ReadWebpageParams> {
|
|||||||
const codeElement = node.querySelector("code");
|
const codeElement = node.querySelector("code");
|
||||||
if (codeElement) {
|
if (codeElement) {
|
||||||
const language = codeElement.className.match(/language-(\w+)/)?.[1] || "";
|
const language = codeElement.className.match(/language-(\w+)/)?.[1] || "";
|
||||||
return `\n\n\`\`\`${language}\n${codeElement.textContent || content}\n\`\`\`\n\n`;
|
return `\n\n\`\`\`${language}\n${content}\n\`\`\`\n\n`;
|
||||||
}
|
}
|
||||||
return `\n\n\`\`\`\n${content}\n\`\`\`\n\n`;
|
return `\n\n\`\`\`\n${content}\n\`\`\`\n\n`;
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in new issue
Block a user