GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(shared): proposed plan titles ignore code comments and empty head… · patroza/t3code@8bbdd33

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/shared/src
    • proposedPlanText.test.ts
    • proposedPlanText.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/shared/src/proposedPlanText.test.ts‎

Copy file name to clipboard
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { expect, it } from "vite-plus/test";
2+
import { proposedPlanTitle, stripDisplayedPlanMarkdown } from "./proposedPlanText.ts";
3+
4+
it("takes the plan title from headings outside code", () => {
5+
for (const [open, inner, close] of [
6+
["```bash", "~~~", "```"],
7+
["~~~bash", "```", "~~~"],
8+
["````bash", "```", "````"],
9+
]) {
10+
const code = `${open}\n# Back up database\n${inner}\n# Still code\n${close}\n`;
11+
expect(proposedPlanTitle(`${code}\n## Real Plan Title\n`)).toBe("Real Plan Title");
12+
}
13+
expect(proposedPlanTitle("```bash\n# Back up database\n")).toBeNull();
14+
expect(proposedPlanTitle("\t# Back up database\n\n## Real Plan Title")).toBe("Real Plan Title");
15+
});
16+
17+
it("skips empty plan headings without reading into the next line", () => {
18+
const markdown = "# \r\n###\t\r\n## Real Title\r\n\r\n## Summary\r\n\r\nBody text";
19+
expect(proposedPlanTitle(markdown)).toBe("Real Title");
20+
expect(stripDisplayedPlanMarkdown(markdown)).toBe("Body text");
21+
});
22+
23+
it("strips the displayed plan title and summary after leading blank lines", () => {
24+
const markdown = "\r\n# My Plan\r\n\r\n## Summary\r\n\r\nBody text";
25+
expect(proposedPlanTitle(markdown)).toBe("My Plan");
26+
expect(stripDisplayedPlanMarkdown(markdown)).toBe("Body text");
27+
});
Collapse file

‎packages/shared/src/proposedPlanText.ts‎

Copy file name to clipboardExpand all lines: packages/shared/src/proposedPlanText.ts
+22-4Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
export function proposedPlanTitle(planMarkdown: string): string | null {
2-
const heading = planMarkdown.match(/^\s{0,3}#{1,6}\s+(.+)$/m)?.[1]?.trim();
3-
return heading && heading.length > 0 ? heading : null;
2+
let fence = "";
3+
for (const line of planMarkdown.split(/\r?\n/)) {
4+
const [, marker = "", info = ""] = line.match(/^ {0,3}(`{3,}|~{3,})(.*)$/) ?? [];
5+
if (fence) {
6+
if (marker[0] === fence[0] && marker.length >= fence.length && !info.trim()) fence = "";
7+
continue;
8+
}
9+
// CommonMark: a backtick fence's info string cannot contain a backtick.
10+
if (marker && (marker[0] !== "`" || !info.includes("`"))) {
11+
fence = marker;
12+
continue;
13+
}
14+
const heading = line.match(/^ {0,3}#{1,6}[ \t]+(.+)$/)?.[1]?.trim();
15+
if (heading) return heading;
16+
}
17+
return null;
418
}
519

620
export function stripDisplayedPlanMarkdown(planMarkdown: string): string {
721
const lines = planMarkdown.trimEnd().split(/\r?\n/);
8-
let start = lines[0] && /^\s{0,3}#{1,6}\s+/.test(lines[0]) ? 1 : 0;
22+
let start = 0;
23+
while (lines[start]?.trim().length === 0 || /^ {0,3}#{1,6}[ \t]*$/.test(lines[start] ?? "")) {
24+
start += 1;
25+
}
26+
if (/^ {0,3}#{1,6}[ \t]+\S/.test(lines[start] ?? "")) start += 1;
927
while (lines[start]?.trim().length === 0) {
1028
start += 1;
1129
}
12-
const firstHeadingMatch = lines[start]?.match(/^\s{0,3}#{1,6}\s+(.+)$/);
30+
const firstHeadingMatch = lines[start]?.match(/^ {0,3}#{1,6}[ \t]+(.+)$/);
1331
if (firstHeadingMatch?.[1]?.trim().toLowerCase() === "summary") {
1432
start += 1;
1533
while (lines[start]?.trim().length === 0) {

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.