docs: publish package usage examples for 0.2.24
This commit is contained in:
@@ -171,8 +171,11 @@ function markdown(source: string): { html: string; headings: DocHeading[] } {
|
||||
}
|
||||
|
||||
function examplesFrom(readme: string, name: string): string {
|
||||
const usage = /^## Usage\s*$([\s\S]*?)(?=^##\s|\s*$)/m.exec(readme)?.[1];
|
||||
if (!usage) throw new Error(`@wrnexus/${name} README must contain a Usage section`);
|
||||
const usageHeading = /^## Usage[ \t]*\r?$/m.exec(readme);
|
||||
if (!usageHeading) throw new Error(`@wrnexus/${name} README must contain a Usage section`);
|
||||
const afterHeading = readme.slice(usageHeading.index + usageHeading[0].length);
|
||||
const nextSection = /^##[ \t]+/m.exec(afterHeading);
|
||||
const usage = afterHeading.slice(0, nextSection?.index ?? afterHeading.length);
|
||||
|
||||
const examples: { title: string; language: string; code: string }[] = [];
|
||||
const lines = usage.replace(/\r/g, "").split("\n");
|
||||
|
||||
Reference in New Issue
Block a user