Skip to content

Commit a7600e4

Browse files
committed
Added helper script to live edit & view a doxygen comment block
This uses a new -c option to generate HTML output for a single comment
1 parent 8049214 commit a7600e4

File tree

7 files changed

+464
-101
lines changed

7 files changed

+464
-101
lines changed

addon/doxycommentview/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Viewer for Doxygen style comments
2+
3+
## Contents
4+
5+
The directory contains an index.html page and a python3 helper script.
6+
The script can be used to start a local web server that can do life rendering of doxygen comments.
7+
8+
Similar to e.g. https://markdownlivepreview.com/ but using doxygen as render engine.
9+
10+
## To prepare the server
11+
12+
Place a doxygen.css in the same directory as the doxycommentview.py script.
13+
14+
This file can be generated running
15+
16+
doxygen -w html /tmp/header.html /tmp/footer.html doxygen.css path/to/Doxyfile
17+
18+
or, alternatively, copied from an existing HTML output directory generated by doxygen.
19+
20+
## To run the server invoke:
21+
22+
python3 doxycommentview.py --doxyfile /path/to/Doxyfile
23+
24+
The relevant settings, such as alias definitions, will be taken from the Doxyfile.
25+
26+
If desired you can set the port for the webserver using `--port` and
27+
point to the location of the doxygen binary using `--doxygen`
28+
29+
Once the server is started, point your browser to the index page
30+
31+
firefox http://localhost:8000/index.html
32+
33+
You should see a panel to enter text on the left hand side and the output
34+
rendered by doxygen on the right hand side of the page.
35+
36+
You can copy and paste the contents of this README.md file to test it quickly.
37+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env python3
2+
#
3+
# python3 helper script to start a web server that can do life rendering of doxygen comments.
4+
#
5+
# Copyright (C) 1997-2024 by Dimitri van Heesch.
6+
#
7+
# Permission to use, copy, modify, and distribute this software and its
8+
# documentation under the terms of the GNU General Public License is hereby
9+
# granted. No representations are made about the suitability of this software
10+
# for any purpose. It is provided "as is" without express or implied warranty.
11+
# See the GNU General Public License for more details.
12+
#
13+
# Documents produced by Doxygen are derivative works derived from the
14+
# input used in their production; they are not affected by this license.
15+
#
16+
17+
import http.server
18+
import socketserver
19+
import json
20+
import subprocess
21+
import argparse
22+
import signal
23+
import threading
24+
25+
def main():
26+
# Set up argument parser
27+
parser = argparse.ArgumentParser(description="Runs the doxygen comment viewer HTTP server.")
28+
parser.add_argument('--port', type=int, default=8000, help='Port number to run the server on')
29+
parser.add_argument('--doxygen', type=str, default='doxygen', help='Path to doxygen executable')
30+
parser.add_argument('--doxyfile', type=str, default='Doxyfile', help='Path to Doxyfile to use')
31+
args = parser.parse_args()
32+
33+
PORT = args.port
34+
DOXYGEN = args.doxygen
35+
DOXYFILE = args.doxyfile
36+
37+
class RequestHandler(http.server.SimpleHTTPRequestHandler):
38+
def do_POST(self):
39+
if self.path == '/process':
40+
content_length = int(self.headers['Content-Length'])
41+
post_data = self.rfile.read(content_length)
42+
data = json.loads(post_data)
43+
input_text = data['input']
44+
45+
# Run doxygen in single comment mode, reading from stdin and writing to stdout
46+
result = subprocess.run([DOXYGEN, '-c', '-', DOXYFILE], \
47+
input=input_text, capture_output=True, text=True)
48+
49+
# Insert CSS link tag into the HTML output
50+
self.send_response(200)
51+
self.send_header('Content-type', 'text/html')
52+
self.end_headers()
53+
self.wfile.write(result.stdout.encode())
54+
55+
httpd = socketserver.TCPServer(("", PORT), RequestHandler)
56+
57+
def signal_handler(sig, frame):
58+
print('Shutting down the web server...')
59+
threading.Thread(target=httpd.shutdown).start()
60+
61+
signal.signal(signal.SIGINT, signal_handler)
62+
63+
print("Running web server on port", PORT)
64+
httpd.serve_forever()
65+
66+
if __name__ == '__main__':
67+
main()

addon/doxycommentview/index.html

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Doxygen comment viewer</title>
6+
<link rel="stylesheet" type="text/css" href="/doxygen.css"/>
7+
<style>
8+
body {
9+
margin: 0;
10+
padding: 0;
11+
display: flex;
12+
height: 100vh;
13+
}
14+
.panel {
15+
width: 50%;
16+
padding: 20px;
17+
box-sizing: border-box;
18+
}
19+
#input {
20+
width: 100%;
21+
height: 100%;
22+
box-sizing: border-box;
23+
resize: none; /* Prevent resizing */
24+
}
25+
#output {
26+
border-left: 1px solid #ccc;
27+
overflow: auto;
28+
}
29+
</style>
30+
</head>
31+
<body>
32+
<div class="panel">
33+
<textarea id="input"></textarea>
34+
</div>
35+
<div class="panel" id="output">
36+
<!-- Processed output will appear here -->
37+
</div>
38+
<script>
39+
function processInput() {
40+
const input = document.getElementById('input').value;
41+
localStorage.setItem('userInput', input);
42+
fetch('/process', {
43+
method: 'POST',
44+
headers: {
45+
'Content-Type': 'application/json',
46+
},
47+
body: JSON.stringify({ input: input }),
48+
})
49+
.then(response => response.text())
50+
.then(result => {
51+
document.getElementById('output').innerHTML = result;
52+
});
53+
}
54+
55+
document.getElementById('input').addEventListener('input', () => {
56+
processInput();
57+
});
58+
59+
// Load previously saved input from local storage
60+
window.onload = () => {
61+
const savedInput = localStorage.getItem('userInput');
62+
if (savedInput) {
63+
document.getElementById('input').value = savedInput;
64+
processInput();
65+
}
66+
};
67+
</script>
68+
</body>
69+
</html>

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ add_library(doxymain STATIC
310310
rtfstyle.cpp
311311
searchindex.cpp
312312
searchindex_js.cpp
313+
singlecomment.cpp
313314
sitemap.cpp
314315
sqlite3gen.cpp
315316
stlsupport.cpp

0 commit comments

Comments
 (0)