adf0d17497
publish / version_or_publish (push) Has been cancelled
storybook-build / changes (push) Has been cancelled
storybook-build / :storybook-build (push) Has been cancelled
Sync Gradio Skills to Hugging Face / sync-skills (push) Has been cancelled
functional / changes (push) Has been cancelled
functional / build-frontend (push) Has been cancelled
functional / functional-test-SSR=false (push) Has been cancelled
functional / functional-reload (push) Has been cancelled
js / changes (push) Has been cancelled
js / js-test (push) Has been cancelled
docs-build / changes (push) Has been cancelled
docs-build / docs-build (push) Has been cancelled
docs-build / website-build (push) Has been cancelled
functional / functional-test-SSR=true (push) Has been cancelled
hygiene / hygiene-test (push) Has been cancelled
python / changes (push) Has been cancelled
python / build (push) Has been cancelled
python / test-ubuntu-latest-flaky (push) Has been cancelled
python / test-ubuntu-latest-not-flaky (push) Has been cancelled
python / test-windows-latest-flaky (push) Has been cancelled
python / test-windows-latest-not-flaky (push) Has been cancelled
28 lines
707 B
TypeScript
28 lines
707 B
TypeScript
const RE_HEADING = /^(#\s*)(.+)$/m;
|
|
|
|
export function inject(text: string): [string | false, string | false] {
|
|
const trimmed_text = text.trim();
|
|
|
|
const heading_match = trimmed_text.match(RE_HEADING);
|
|
if (!heading_match) {
|
|
return [false, trimmed_text || false];
|
|
}
|
|
|
|
const [full_match, , heading_content] = heading_match;
|
|
const _heading = heading_content.trim();
|
|
|
|
if (trimmed_text === full_match) {
|
|
return [_heading, false];
|
|
}
|
|
|
|
const heading_end_index =
|
|
heading_match.index !== undefined
|
|
? heading_match.index + full_match.length
|
|
: 0;
|
|
const remaining_text = trimmed_text.substring(heading_end_index).trim();
|
|
|
|
const _paragraph = remaining_text || false;
|
|
|
|
return [_heading, _paragraph];
|
|
}
|