Skip to content

Commit

Permalink
Documentation: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
devernay committed Jan 18, 2017
1 parent 4ea9f38 commit 31e9b5a
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 39 deletions.
65 changes: 52 additions & 13 deletions Engine/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4595,7 +4595,7 @@ Node::makeDocumentation(bool genHTML) const
// note that only % units are understood both by pandox and sphinx
ms << "{ width=10% }";
}
ms << "\\ \n\n";
ms << "&nbsp;\n\n"; // &nbsp; required so that there is no legend when converted to rst by pandoc
}
ms << tr("*This documentation is for version %2.%3 of %1.*").arg(pluginLabel).arg(majorVersion).arg(minorVersion) << "\n\n";

Expand Down Expand Up @@ -4658,25 +4658,64 @@ Node::makeDocumentation(bool genHTML) const
if (genHTML) {
// use hoedown to convert to HTML

ts << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">";
ts << "<html><head>";
ts << "<title>" << pluginLabel << " - NATRON_DOCUMENTATION</title>";
ts << "<link rel=\"stylesheet\" href=\"_static/markdown.css\" type=\"text/css\" /><script type=\"text/javascript\" src=\"_static/jquery.js\"></script><script type=\"text/javascript\" src=\"_static/dropdown.js\"></script>";
ts << "</head><body>";
ts << "<div class=\"related\"><h3>" << tr("Navigation") << "</h3><ul>";
ts << "<li><a href=\"/index.html\">NATRON_DOCUMENTATION</a> &raquo;</li>";
ts << "<li><a href=\"/_group.html\">" << tr("Reference Guide") << "</a> &raquo;</li>";
ts << ("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
"\n"
"\n"
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
" <head>\n"
" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n"
" \n"
" <title>") << tr("%1 node").arg(pluginLabel) << " &#8212; NATRON_DOCUMENTATION</title>\n";
ts << (" \n"
" <link rel=\"stylesheet\" href=\"_static/markdown.css\" type=\"text/css\" />\n"
" \n"
" <script type=\"text/javascript\" src=\"_static/jquery.js\"></script>\n"
" <script type=\"text/javascript\" src=\"_static/dropdown.js\"></script>\n"
" <link rel=\"index\" title=\"Index\" href=\"genindex.html\" />\n"
" <link rel=\"search\" title=\"Search\" href=\"search.html\" />\n"
" </head>\n"
" <body role=\"document\">\n"
" <div class=\"related\" role=\"navigation\" aria-label=\"related navigation\">\n"
" <h3>") << tr("Navigation") << "</h3>\n";
ts << (" <ul>\n"
" <li class=\"right\" style=\"margin-right: 10px\">\n"
" <a href=\"genindex.html\" title=\"General Index\"\n"
" accesskey=\"I\">") << tr("index") << "</a></li>\n";
ts << (" <li class=\"right\" >\n"
" <a href=\"py-modindex.html\" title=\"Python Module Index\"\n"
" >") << tr("modules") << "</a> |</li>\n";
ts << (" <li class=\"nav-item nav-item-0\"><a href=\"index.html\">NATRON_DOCUMENTATION</a> &#187;</li>\n"
" <li class=\"nav-item nav-item-1\"><a href=\"_group.html\" >") << tr("Reference Guide") << "</a> &#187;</li>\n";
if ( !pluginGroup.isEmpty() ) {
QString group = pluginGroup.at(0);
if (!group.isEmpty()) {
ts << "<li><a href=\"/_group.html?id=" << group << "\">" << group << "</a> &raquo;</li>";
ts << " <li class=\"nav-item nav-item-2\"><a href=\"_group.html?id=" << group << "\">" << group << " nodes</a> &#187;</li>";
}
}
ts << "</ul></div>";
ts << "<div class=\"document\"><div class=\"documentwrapper\"><div class=\"body\"><div class=\"section\">";
ts << (" </ul>\n"
" </div> \n"
"\n"
" <div class=\"document\">\n"
" <div class=\"documentwrapper\">\n"
" <div class=\"body\" role=\"main\">\n"
" \n"
" <div class=\"section\">\n");
QString html = Markdown::convert2html(markdown);
ts << Markdown::fixNodeHTML(html);
ts << "</div></div></div><div class=\"clearer\"></div></div><div class=\"footer\"></div></body></html>";
ts << ("</div>\n"
"\n"
"\n"
" </div>\n"
" </div>\n"
" <div class=\"clearer\"></div>\n"
" </div>\n"
"\n"
" <div class=\"footer\" role=\"contentinfo\">\n"
" &#169; Copyright 2013-2017 The Natron documentation authors, licensed under CC BY-SA 4.0.\n"
" </div>\n"
" </body>\n"
"</html>");
} else {
// this markdown will be processed externally by pandoc

Expand Down
69 changes: 53 additions & 16 deletions Engine/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "Engine/Plugin.h"
#include "Engine/Project.h"
#include "Engine/StandardPaths.h"
#include "Engine/Utils.h"
#include "Engine/ViewIdx.h"
#include "Engine/ViewerInstance.h"

Expand Down Expand Up @@ -2537,8 +2538,8 @@ Settings::makeHTMLDocumentation(bool genHTML) const
continue;
}
//QString knobScriptName = QString::fromUtf8( (*it)->getName().c_str() );
QString knobLabel = QString::fromUtf8( (*it)->getLabel().c_str() );
QString knobHint = QString::fromUtf8( (*it)->getHintToolTip().c_str() );
QString knobLabel = convertFromPlainTextToMarkdown( QString::fromStdString( (*it)->getLabel() ), genHTML, false );
QString knobHint = convertFromPlainTextToMarkdown( QString::fromStdString( (*it)->getHintToolTip() ), genHTML, false );
KnobPage* isPage = dynamic_cast<KnobPage*>( it->get() );
KnobSeparator* isSep = dynamic_cast<KnobSeparator*>( it->get() );
if (isPage) {
Expand All @@ -2558,22 +2559,58 @@ Settings::makeHTMLDocumentation(bool genHTML) const
}

if (genHTML) {
ts << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n";
ts << "<html>\n<head>\n";
ts << "<title>" << tr("Natron Preferences") << "</title>\n";
ts << "<link rel=\"stylesheet\" href=\"_static/makdown.css\" type=\"text/css\" />\n<script type=\"text/javascript\" src=\"_static/jquery.js\"></script>\n<script type=\"text/javascript\" src=\"_static/dropdown.js\"></script>\n";
ts << "</head>\n<body>\n";
ts << "<div class=\"related\">\n<h3>" << tr("Navigation") << "</h3>\n<ul>\n";
ts << "<li><a href=\"/index.html\">" << tr("%1 %2 documentation").arg( QString::fromUtf8(NATRON_APPLICATION_NAME) ).arg( QString::fromUtf8(NATRON_VERSION_STRING) ) << "</a> &raquo;</li>\n";
ts << "<li><a href=\"/_group.html\">";
ts << tr("Reference Guide");
ts << "</a> &raquo;</li>";
ts << "</ul>\n</div>\n";
ts << "<div class=\"document\">\n<div class=\"documentwrapper\">\n<div class=\"body\">\n";
ts << "<div class=\"section\">\n";
ts << ("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
"\n"
"\n"
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
" <head>\n"
" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n"
" \n"
" <title>") << tr("Preferences") << " &#8212; NATRON_DOCUMENTATION</title>\n";
ts << (" \n"
" <link rel=\"stylesheet\" href=\"_static/markdown.css\" type=\"text/css\" />\n"
" \n"
" <script type=\"text/javascript\" src=\"_static/jquery.js\"></script>\n"
" <script type=\"text/javascript\" src=\"_static/dropdown.js\"></script>\n"
" <link rel=\"index\" title=\"Index\" href=\"genindex.html\" />\n"
" <link rel=\"search\" title=\"Search\" href=\"search.html\" />\n"
" </head>\n"
" <body role=\"document\">\n"
" <div class=\"related\" role=\"navigation\" aria-label=\"related navigation\">\n"
" <h3>") << tr("Navigation") << "</h3>\n";
ts << (" <ul>\n"
" <li class=\"right\" style=\"margin-right: 10px\">\n"
" <a href=\"genindex.html\" title=\"General Index\"\n"
" accesskey=\"I\">") << tr("index") << "</a></li>\n";
ts << (" <li class=\"right\" >\n"
" <a href=\"py-modindex.html\" title=\"Python Module Index\"\n"
" >") << tr("modules") << "</a> |</li>\n";
ts << (" <li class=\"nav-item nav-item-0\"><a href=\"index.html\">NATRON_DOCUMENTATION</a> &#187;</li>\n"
" <li class=\"nav-item nav-item-1\"><a href=\"_group.html\" >") << tr("Reference Guide") << "</a> &#187;</li>\n";
ts << (" </ul>\n"
" </div> \n"
"\n"
" <div class=\"document\">\n"
" <div class=\"documentwrapper\">\n"
" <div class=\"body\" role=\"main\">\n"
" \n"
" <div class=\"section\">\n");
QString html = Markdown::convert2html(markdown);
ts << Markdown::fixSettingsHTML(html);
ts << "</div>\n</div>\n</div>\n<div class=\"clearer\"></div>\n</div>\n<div class=\"footer\"></div>\n</body>\n</html>\n";
ts << ("</div>\n"
"\n"
"\n"
" </div>\n"
" </div>\n"
" <div class=\"clearer\"></div>\n"
" </div>\n"
"\n"
" <div class=\"footer\" role=\"contentinfo\">\n"
" &#169; Copyright 2013-2017 The Natron documentation authors, licensed under CC BY-SA 4.0.\n"
" </div>\n"
" </body>\n"
"</html>");
} else {
ts << markdown;
}
Expand Down
11 changes: 9 additions & 2 deletions Engine/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ convertFromPlainTextToMarkdown(const QString &plain_, bool genHTML, bool isTable
// . dot
// ! exclamation mark

// We must also escape angle brackets < and > , so that they don't become HTML tags

// we do a hack for multiline elements, because the markdown->rst conversion by pandoc doesn't use the line block syntax.
// what we do here is put a supplementary dot at the beginning of each line, which is then converted to a pipe '|' in the
// genStaticDocs.sh script by a simple sed command after converting to RsT
Expand All @@ -150,8 +152,13 @@ convertFromPlainTextToMarkdown(const QString &plain_, bool genHTML, bool isTable
plain[i] == QLatin1Char('.') ||
plain[i] == QLatin1Char('!')) {
escaped += QLatin1Char('\\');
}
if (isTableElement) {
} else if ( plain[i] == QLatin1Char('<') ) {
escaped += QString::fromUtf8("&lt;");
outputChar = false;
} else if ( plain[i] == QLatin1Char('>') ) {
escaped += QString::fromUtf8("&gt;");
outputChar = false;
} else if (isTableElement) {
if (plain[i] == QLatin1Char('|')) {
escaped += QString::fromUtf8("&#124;");
outputChar = false;
Expand Down
29 changes: 21 additions & 8 deletions Gui/DocumentationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ DocumentationManager::handler(QHttpRequest *req,
// plugin pages are generated only if they don't exist
QString staticPage, dynamicPage;
bool isPlugin = false;
bool isPrefs = false;
bool isStatic = false;
if ( page.startsWith( QString::fromUtf8("/plugins/") ) ) {
isPlugin = true;
Expand All @@ -138,7 +139,19 @@ DocumentationManager::handler(QHttpRequest *req,
staticPage += QString::fromUtf8(".html");
dynamicPage = page;
}
if (isPlugin) {
if ( page == QString::fromUtf8("/_prefs.html") ) {
isPrefs = true;
isStatic = true;
staticPage = page;
dynamicPage = QString::fromUtf8("/_prefsLive.html");
}
if ( page == QString::fromUtf8("/_prefsLive.html") ) {
isPrefs = true;
isStatic = false;
staticPage = QString::fromUtf8("/_prefs.html");
dynamicPage = page;
}
if ( !staticPage.isEmpty() ) {
QFileInfo staticFileInfo = docDir + staticPage;
if ( ( isStatic && !staticFileInfo.exists() ) ||
( !isStatic && staticFileInfo.exists() ) ) {
Expand Down Expand Up @@ -272,7 +285,7 @@ DocumentationManager::handler(QHttpRequest *req,
"</html>");
body = parser(notFound, docDir).toUtf8();
}
} else if ( page == QString::fromUtf8("_prefs.html") ) {
} else if ( page == QString::fromUtf8("_prefsLive.html") ) {
SettingsPtr settings = appPTR->getCurrentSettings();
QString html = settings->makeHTMLDocumentation(true);
html = parser(html, docDir);
Expand Down Expand Up @@ -542,21 +555,22 @@ DocumentationManager::parser(QString html,
"</form>"
"</div>")
.arg( tr("Search docs") ) );
menuHTML.append( QString::fromUtf8("<div id=\"mainMenu\">"
"<ul>") );
menuHTML.append( QString::fromUtf8("<div id=\"mainMenu\">") );
if ( indexFile.exists() ) {
if ( indexFile.open(QIODevice::ReadOnly | QIODevice::Text) ) {
QStringList menuResult;
bool getMenu = false;
while ( !indexFile.atEnd() ) {
QString line = QString::fromUtf8( indexFile.readLine() );
if ( line == QString::fromUtf8("<div class=\"toctree-wrapper compound\">\n") ) {
if ( line == QString::fromUtf8("<div class=\"toctree-wrapper compound\">\n"
"<ul>\n") ) {
getMenu = true;
}
if (getMenu) {
menuResult << line;
}
if ( line == QString::fromUtf8("</div>\n") ) {
if ( line == QString::fromUtf8("</ul>\n"
"</div>\n") ) {
getMenu = false;
}
}
Expand All @@ -574,8 +588,7 @@ DocumentationManager::parser(QString html,
"</div>") );
}
} else {
menuHTML.append( QString::fromUtf8("</ul>"
"</div>"
menuHTML.append( QString::fromUtf8("</div>"
"</div>") );
}

Expand Down

0 comments on commit 31e9b5a

Please sign in to comment.