Commit 0ae7cd87 authored by Shubham  .'s avatar Shubham .

Create a single script to generate qthelp files, add custom styles and extract the keywords

parent 24bbf9c0
Pipeline #26112 failed with stage
in 3 minutes and 17 seconds
# 1. Creation of `qhp`
It stands for Qt Help Project. This is simiar to xml's file format. It contains the table of contents, indices, and references to the actual documentation files (*.html). This file is later passed to qhcp (Qt Help Collection File). This file contains various tags like table of contents, section tag for defining the actual documentation, keywords tag for defining the indices for the documentation, files tag for listing all the files required. [Click here for more details on qhp](https://doc.qt.io/qt-5/qthelpproject.html)
### Steps to extract the indices from `index.hhk` file to add them to `qhp`
`index.hhk` is an index file shipped with the Maxima documentation. To extract all the indices, run the python script named `index_parser.py` over the index file to get the keywords listed for `qhp` file. Copy and paste the `output.txt` file's content to `qhp` file under keywords section.
# 2. Creation of `qhcp`
It is an XML file that contains references to the compressed help files that should be included in the help collection. This file can be passed to the help generator for creating a `qhc` and `qch` files in one go. [Refer this link for more information](https://doc.qt.io/qt-5/qthelp-framework.html#qt-help-collection-project)
### Steps to generate `qhp` and `qhcp`
Copy the file named `qthelp_generator.py` and custom style sheets named `main.css` to the location where the `Maxima` HTML files exists. Then simply run the command `python qthelp_generator.py`. This script is all-in-one. It does the task of adding custom stylesheets defined in `main.css`, extracting the keywords from `index.hhk` and generation of QtHelp files named `qhp` and `qhcp`.
NOTE: store the `index.hhk`, `main.css` in the same folder as that of the `Maxima` documentation and the script should be placed there as well.
### Creation of `qhc` and `qch`
Use the following command to generate the above said files.
qhelpgenerator doc.qhp -o doc.qch
qhelpgenerator help.qhcp -o help.qhc
# 3. Steps for adding custom style to the Maxima documentation
Add your custom styles to `main.css`. To apply custom them, place the python script named `css_injector.py` in the same location as that of all the Maxima's documentation's HTML files. Then run the script. It will inject code into HTML files to link them to `main.css` file.
### Steps for adding custom style to the Maxima documentation
Add your custom styles to `main.css`. To apply custom them, place the python script named `qthelp_generator.py` in the same location as that of all the Maxima's documentation's HTML files. Then run the script. It will inject code into HTML files to link them to `main.css` file.
import os
files = os.listdir('.')
for fi in files:
if fi.endswith('.html'):
# open file and reach to the 62 line
fp = open(fi, 'r')
lines_list = fp.readlines()
lines_list.insert(61, '<link rel="stylesheet" type="text/css" href="./main.css">')
fp.close()
# link the css file
fp = open(fi, 'w')
fp.writelines(lines_list)
fp.close()
# script to parse index.hhk and generate .xml file
fp = open('./index.hhk', 'r')
fp2 = open('./output.txt', 'w')
for li in fp:
if li.startswith('<li>'):
line2 = fp.next()
line3 = fp.next()
if not line2:
break
else:
ln2_lastindex = line2.rindex('"')
ln3_lastindex = line3.rindex('"')
name = line3[29:ln3_lastindex]
ref = line2[30:ln2_lastindex]
fp2.write('<keyword name = "{}" ref = "{}"/>\n'.format(name, ref))
fp.close()
fp2.close()
This diff is collapsed.
......@@ -85,12 +85,16 @@ DocumentationPanelWidget::DocumentationPanelWidget(Cantor::Session* session, QWi
QByteArray contents;
if(m_backend == QLatin1String("Maxima"))
contents = m_engine->fileData(QUrl(QLatin1String("qthelp://org.kde.cantor/doc/maxima.html#SEC_Top")));
{
contents = m_engine->fileData(QUrl(QLatin1String("qthelp://org.kde.cantor/doc/maxima.html#SEC_Top")));
}
else if(m_backend == QLatin1String("Octave"))
contents = m_engine->fileData(QUrl(QLatin1String("qthelp://org.octave.interpreter-1.0/doc/octave.html/index.html")));
{
contents = m_engine->fileData(QUrl(QLatin1String("qthelp://org.octave.interpreter-1.0/doc/octave.html/index.html")));
}
m_textBrowser->setContent(contents, QLatin1String("text/html;charset=UTF-8"));
m_textBrowser->hide();
m_textBrowser->setContent(contents, QLatin1String("text/html;charset=UTF-8"), QUrl(QLatin1String("qthelp://org.kde.cantor/doc/")));
m_textBrowser->show();
m_splitter = new QSplitter(Qt::Horizontal, this);
m_splitter->addWidget(m_tabWidget);
......@@ -99,6 +103,7 @@ DocumentationPanelWidget::DocumentationPanelWidget(Cantor::Session* session, QWi
QHBoxLayout* layout = new QHBoxLayout(this);
layout->addWidget(m_splitter);
//TODO QHelpIndexWidget::linkActivated is obsolete, use QHelpIndexWidget::documentActivated instead
connect(m_engine->contentWidget(), &QHelpContentWidget::linkActivated, this, &DocumentationPanelWidget::displayHelp);
connect(m_engine->indexWidget(), &QHelpIndexWidget::linkActivated, this, &DocumentationPanelWidget::displayHelp);
//connect(search, SIGNAL(clicked(bool)), this, SLOT(doSearch(QString)));
......@@ -145,6 +150,7 @@ void DocumentationPanelWidget::loadDocumentation()
{
const QString backend = backendName();
const QString fileName = QStandardPaths::locate(QStandardPaths::AppDataLocation, QLatin1String("documentation/") + backend + QLatin1String("/help.qch"));
m_engine->registerDocumentation(fileName);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment