FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Only list Discount as available Markdown processor if MultiMarkdown i… · jackcoolpython/ghostwriter@d96ad5c · GitHub

Repository navigation

Commit d96ad5c

Browse files
committed
Only list Discount as available Markdown processor if MultiMarkdown is not installed.
1 parent 52515ae commit d96ad5c

1 file changed

Lines changed: 28 additions & 5 deletions

File tree

‎src/ExporterFactory.cpp‎

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/***********************************************************************
22
*
3-
* Copyright (C) 2014-2018 wereturtle
3+
* Copyright (C) 2014-2019 wereturtle
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -88,10 +88,20 @@ ExporterFactory::ExporterFactory()
8888
CommandLineExporter* exporter = NULL;
8989
bool pandocIsAvailable = isCommandAvailable("pandoc --version");
9090
bool mmdIsAvailable = isCommandAvailable("multimarkdown --version");
91-
bool discountIsAvailable = isCommandAvailable("markdown -V");
91+
bool discountIsAvailable = false;
9292
bool cmarkIsAvailable = isCommandAvailable("cmark --version");
9393
bool cmarkGfmIsAvailable = isCommandAvailable("cmark-gfm --version");
9494

95+
// MultiMarkdown installs a "markdown" script to launch the "multimarkdown"
96+
// command. Discount's executable also happens to be named "markdown".
97+
// To avoid confusion, check if MultiMarkdown is actually installed, and
98+
// only if it isn't installed should Discount be checked for availability.
99+
//
100+
if (!mmdIsAvailable)
101+
{
102+
discountIsAvailable = isCommandAvailable("markdown -V");
103+
}
104+
95105
SundownExporter* sundownExporter = new SundownExporter();
96106
fileExporters.append(sundownExporter);
97107
htmlExporters.append(sundownExporter);
@@ -328,13 +338,26 @@ QList<int> ExporterFactory::extractVersionNumber(const QString& command) const
328338
}
329339

330340
QString versionStr = QString::fromUtf8(process.readAllStandardOutput().data());
331-
QRegularExpression versionRegex("\\d+(\\.\\d+)*");
341+
QRegularExpression versionRegex1("v(\\d+(\\.\\d+)*)");
342+
QRegularExpression versionRegex2("(\\d+(\\.\\d+)*)");
332343
QRegularExpressionMatch match;
333-
int pos = versionStr.indexOf(versionRegex, 0, &match);
344+
345+
// Prefer searching for "v1.6.3" version format over "1.6.3" format
346+
int pos = versionStr.indexOf(versionRegex1, 0, &match);
334347

335348
if ((pos >= 0) && match.hasMatch())
336349
{
337-
versionStr = match.captured();
350+
versionStr = match.captured(1);
351+
}
352+
// Else try the "1.6.3" format without the "v" in front
353+
else
354+
{
355+
pos = versionStr.indexOf(versionRegex2, 0, &match);
356+
357+
if ((pos >= 0) && match.hasMatch())
358+
{
359+
versionStr = match.captured(1);
360+
}
338361
}
339362

340363
QStringList numbers = versionStr.split('.', QString::SkipEmptyParts);

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL