Skip to content

Commit 0975b29

Browse files
committed
Revert "trying single code block highlight again. why is it blue???"
This reverts commit 35353c7.
1 parent 5bd52be commit 0975b29

File tree

3 files changed

+34
-69
lines changed

3 files changed

+34
-69
lines changed

astro.config.mjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import starlight from "@astrojs/starlight";
22
import { defineConfig } from "astro/config";
33
import { generateCliOptionsIntegration } from "./src/fetchReadme";
44
import smartypants from "remark-smartypants";
5-
import { pluginCodeMarkerAnchors } from "./src/CodeMarkerAnchorPlugin.mjs";
65

76
// https://astro.build/config
87
export default defineConfig({
@@ -18,7 +17,6 @@ export default defineConfig({
1817
generateCliOptionsIntegration("src/content/docs/guides/_cli.md"),
1918
starlight({
2019
expressiveCode: {
21-
plugins: [pluginCodeMarkerAnchors()],
2220
themes: ["catppuccin-frappe", "catppuccin-latte"],
2321
},
2422
title: "Docs",

src/CodeMarkerAnchorPlugin.mjs

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/fetchReadme.ts

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,38 @@ function* generateMarkdown(lines: string[]) {
5353
const bodyRegex = /^ (.*)/;
5454
const defaultValuesRegex = /^\[(default|possible values|env): (.*)\]$/;
5555

56-
const markers: {[l: string]: number} = {};
57-
for (const [i, line] of lines.entries()) {
58-
const match = line.match(optionRegex);
59-
if (match) {
60-
markers[`#${match[0].trim()}`] = i + 1;
61-
}
62-
}
56+
let match;
57+
for (const line of lines) {
58+
if (line.match(usageRegex)) {
59+
yield '```';
60+
yield line;
61+
yield '```';
62+
63+
} else if (line.match(headingRegex)) {
64+
yield "## " + escapeMarkdown(line.replace(/:$/, ''));
65+
66+
} else if (match = line.match(optionRegex)) {
67+
const option = escapeMarkdown(match[0]).trim();
68+
const longOption = line.replace(/-[^-],/, '');
69+
yield `### ${option}`;
70+
yield '';
71+
yield '```bash';
72+
yield `lychee ${longOption.trimStart()}`;
73+
yield '```';
74+
75+
} else if (match = line.match(bodyRegex)) {
76+
const line = match[1];
77+
if (match = line.match(defaultValuesRegex)) {
78+
yield `**${match[1]}**: ${match[2]}`;
79+
yield '';
80+
} else {
81+
yield ' ' + line;
82+
}
6383

64-
for (const line of Object.keys(markers)) {
65-
yield '### ' + line.replace('#', '');
66-
yield '';
84+
} else {
85+
yield line;
86+
}
6787
}
68-
69-
yield '```text ' + Object.entries(markers).map(([l, i]) => JSON.stringify({[l]: i})).join(' ')
70-
yield* lines;
71-
yield '```';
7288
}
7389

7490
export async function generateCliOptionsMarkdown() {
@@ -78,10 +94,10 @@ export async function generateCliOptionsMarkdown() {
7894
const rawUsageText = extractHelpFromReadme(await readme.text());
7995
const usageText = [...generateMarkdown(splitLines(rawUsageText))].join("\n");
8096

81-
// assert(usageText.match('\n## Options\n'), 'options heading missing, check headingRegex');
82-
// assert(usageText.match('\n### --dump\n'), '--dump heading missing, check optionRegex');
83-
// assert(usageText.match('\n### --root-dir\n'), '--root-dir heading missing, check optionRegex');
84-
// assert(usageText.match('\n Inputs for link checking'), 'expected body text missing, check bodyRegex');
97+
assert(usageText.match('\n## Options\n'), 'options heading missing, check headingRegex');
98+
assert(usageText.match('\n### --dump\n'), '--dump heading missing, check optionRegex');
99+
assert(usageText.match('\n### --root-dir\n'), '--root-dir heading missing, check optionRegex');
100+
assert(usageText.match('\n Inputs for link checking'), 'expected body text missing, check bodyRegex');
85101

86102
return usageText;
87103
}

0 commit comments

Comments
 (0)