Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Network
KIO Extras
Commits
a197b68a
Commit
a197b68a
authored
Aug 25, 2021
by
Jonathan Marten
Browse files
man: Format internally generated pages in the same way as man output
With the standard header, styles etc as provided by kdoctools.
parent
29b29b37
Pipeline
#95737
passed with stage
in 1 minute and 52 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
man/kio_man.cpp
View file @
a197b68a
...
...
@@ -610,25 +610,52 @@ char *MANProtocol::readManPage(const char *_filename)
//---------------------------------------------------------------------
// This opens one <div> to format the HTML body, so when the document
// is finished it needs to be closed by outputFooter().
void
MANProtocol
::
outputHeader
(
QTextStream
&
os
,
const
QString
&
header
,
const
QString
&
title
)
{
const
QString
pageTitle
=
(
!
title
.
isEmpty
()
?
title
:
header
);
os
.
setCodec
(
"UTF-8"
);
os
<<
"<!DOCTYPE HTML PUBLIC
\"
-//W3C//DTD HTML 4.01 Strict//EN
\"
>
\n
"
;
os
<<
"<html><head>
\n
"
;
os
<<
"<meta http-equiv=
\"
Content-Type
\"
content=
\"
text/html; charset=utf-8
\"
>
\n
"
;
os
<<
"<title>"
<<
(
!
title
.
isEmpty
()
?
title
:
header
)
<<
"</title>
\n
"
;
// The same header and styling as generated by man2html
os
<<
"<!DOCTYPE html PUBLIC
\"
-//W3C//DTD HTML 4.01 Transitional//EN
\"
>
\n
"
;
os
<<
"<meta http-equiv=
\"
Content-Type
\"
content=
\"
text/html; charset=UTF-8
\"
>
\n
"
;
os
<<
"<title>"
<<
pageTitle
<<
"</title>
\n
"
;
os
<<
"<link rel=
\"
stylesheet
\"
href=
\"
help:/kdoctools5-common/kde-default.css
\"
type=
\"
text/css
\"
>
\n
"
;
if
(
!
m_manCSSFile
.
isEmpty
())
{
os
<<
"<link href=
\"
"
<<
m_manCSSFile
<<
"
\"
type=
\"
text/css
\"
rel=
\"
stylesheet
\"
>
\n
"
;
os
<<
"<link
rel=
\"
stylesheet
\"
href=
\"
"
<<
m_manCSSFile
<<
"
\"
type=
\"
text/css
\"
>
\n
"
;
}
os
<<
"</head>
\n\n
"
;
os
<<
"<style type=
\"
text/css
\"
>
\n
"
;
os
<<
"#header_top { background-image: url(
\"
help:/kdoctools5-common/top.jpg
\"
); }
\n
"
;
os
<<
"#header_top div { background-image: url(
\"
help:/kdoctools5-common/top-left.jpg
\"
); }
\n
"
;
os
<<
"#header_top div div { background-image: url(
\"
help:/kdoctools5-common/top-right.jpg
\"
); }
\n
"
;
os
<<
"</style>
\n
"
;
os
<<
"</head>
\n
"
;
os
<<
"<body>
\n
"
;
os
<<
"<div id=
\"
header
\"
><div id=
\"
header_top
\"
><div><div>
\n
"
;
os
<<
"<img src=
\"
help:/kdoctools5-common/top-kde.jpg
\"
alt=
\"
top-kde
\"
>
\n
"
;
os
<<
pageTitle
<<
"
\n
"
;
os
<<
"</div></div></div></div>
\n
"
;
os
<<
"<div style=
\"
margin-left: 5em; margin-right: 5em;
\"
>
\n
"
;
os
<<
"<h1>"
<<
header
<<
"</h1>
\n
"
;
os
.
flush
();
}
void
MANProtocol
::
outputFooter
(
QTextStream
&
os
)
{
os
<<
"</div>
\n
"
;
// closes "<div style="margin-left: 5em; margin-right: 5em;"
os
<<
"</body>
\n
"
;
os
<<
"</html>
\n
"
;
os
.
flush
();
}
// This calls SlaveBase::finished(), so do not call any other
// SlaveBase functions afterwards. It is assumed that mimeType()
// has already been called at the start of get().
...
...
@@ -639,10 +666,8 @@ void MANProtocol::outputError(const QString& errmsg)
outputHeader
(
os
,
i18n
(
"Manual Page Viewer Error"
));
os
<<
errmsg
<<
"
\n
"
;
os
<<
"</body>
\n
"
;
os
<<
"</html>
\n
"
;
outputFooter
(
os
);
os
.
flush
();
data
(
array
);
data
(
QByteArray
());
finished
();
...
...
@@ -670,9 +695,7 @@ void MANProtocol::outputMatchingPages(const QStringList &matchingPages)
" be aware it can contain some mistakes or be obsolete."
" In case of doubt, you should have a look at the English version."
)
<<
"</p>"
;
os
<<
"</body>
\n
"
;
os
<<
"</html>
\n
"
;
os
.
flush
();
outputFooter
(
os
);
data
(
array
);
// Do not call finished(), the caller will do that
}
...
...
@@ -816,9 +839,7 @@ void MANProtocol::showMainIndex()
}
os
<<
"</table>
\n
"
;
os
<<
"</body>
\n
"
;
os
<<
"</html>
\n
"
;
os
.
flush
();
outputFooter
(
os
);
data
(
array
);
data
(
QByteArray
());
// Do not call finished(), the caller will do that
...
...
@@ -1118,8 +1139,7 @@ void MANProtocol::showIndex(const QString& section)
if
(
pages
.
isEmpty
())
// not a single page found
{
// print footer
os
<<
"</div></body></html>
\n
"
;
os
.
flush
();
outputFooter
(
os
);
os_h
.
flush
();
infoMessage
(
QString
());
...
...
@@ -1288,11 +1308,10 @@ void MANProtocol::showIndex(const QString& section)
os
<<
indexLine
<<
'\n'
;
// print footer
o
s
<<
"</body></html>
\n
"
;
o
utputFooter
(
os
)
;
// set the links "toolbar" also at the top
os_h
<<
indexLine
<<
'\n'
;
os
.
flush
();
os_h
.
flush
();
infoMessage
(
QString
());
...
...
man/kio_man.h
View file @
a197b68a
...
...
@@ -54,6 +54,7 @@ private:
QStringList
findManPagesInSection
(
const
QString
&
dir
,
const
QString
&
title
,
bool
full_path
);
void
outputHeader
(
QTextStream
&
os
,
const
QString
&
header
,
const
QString
&
title
=
QString
());
void
outputFooter
(
QTextStream
&
os
);
bool
getProgramPath
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment