Skip to content

Commit abf1b99

Browse files
Fixes #211 and #212 where anchor link and markdown indentation didn't work as intended
1 parent a027937 commit abf1b99

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/LaravelRequestDocs.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ public function lrdDocComment(string $docComment): string
295295
}
296296
if ($counter == 1 && !Str::contains($comment, '@lrd')) {
297297
if (Str::startsWith($comment, '*')) {
298-
$comment = trim(substr($comment, 1));
298+
$comment = substr($comment, 1);
299299
}
300300
// remove first character from string
301301
$lrdComment .= $comment . "\n";

ui/src/components/App.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ export default function App() {
5959
generateDocs(api)
6060
}, [])
6161

62+
const scrollToAnchorOnHistory = () => {
63+
// get the anchor link and scroll to it
64+
const anchor = window.location.hash;
65+
if (anchor) {
66+
const anchorId = anchor.replace('#', '');
67+
const element = document.getElementById(anchorId);
68+
console.log(element)
69+
if (element) {
70+
element.scrollIntoView();
71+
}
72+
}
73+
}
74+
6275
const generateDocs = (url: string) => {
6376
setSendingRequest(true)
6477
const response = fetch(url);
@@ -75,6 +88,9 @@ export default function App() {
7588
setLrdDocsJson(lrdDocsJson)
7689
setLrdDocsJsonCopy(lrdDocsJson)
7790
setSendingRequest(false)
91+
setTimeout(() => {
92+
scrollToAnchorOnHistory()
93+
}, 10) // greater than 1 is fine
7894
}).catch((error) => {
7995
setError(error.message)
8096
setSendingRequest(false)

ui/src/components/Sidebar.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ export default function Sidebar(props: Props) {
2828
</li>
2929
)}
3030
<li>
31-
<AnchorLink href={'#' + lrdDocsItem.http_method + lrdDocsItem.uri} className="flex flex-row px-0 py-1">
31+
<AnchorLink href={'#' + lrdDocsItem.http_method + lrdDocsItem.uri}
32+
onClick={() => {
33+
window.history.pushState({}, '', '#' + lrdDocsItem.http_method + lrdDocsItem.uri);
34+
}}
35+
className="flex flex-row px-0 py-1">
3236
<span className={`method-${lrdDocsItem.http_method} uppercase text-xs w-12 p-0 flex flex-row-reverse`}>
3337
{lrdDocsItem.http_method}
3438
</span>

0 commit comments

Comments
 (0)