Skip to content

Commit

Permalink
Markdown file as internet link
Browse files Browse the repository at this point in the history
See a link in case of a md file only as local link if it doesn't start with a supported protocol.
Example found was:
```
[Ansibullbot](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
```
  • Loading branch information
albert-github committed Apr 5, 2019
1 parent 16d025c commit 6441903
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/markdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,9 @@ static int processLink(GrowBuf &out,const char *data,int,int size)
{
SrcLangExt lang = getLanguageFromFileName(link);
int lp=-1;
if ((lp=link.find("@ref "))!=-1 || (lp=link.find("\\ref "))!=-1 || lang==SrcLangExt_Markdown)
printf("==> %d #%s#\n",isURL(link),link.data());
printf("==> %d \n", ((lp=link.find("@ref "))!=-1 || (lp=link.find("\\ref "))!=-1 || (lang==SrcLangExt_Markdown && !isURL(link))) );
if ((lp=link.find("@ref "))!=-1 || (lp=link.find("\\ref "))!=-1 || (lang==SrcLangExt_Markdown && !isURL(link)))
// assume doxygen symbol link
{
if (lp==-1) // link to markdown page
Expand Down
12 changes: 8 additions & 4 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8452,16 +8452,20 @@ QCString getLanguageSpecificSeparator(SrcLangExt lang,bool classScope)
return "::";
}
}

/** Checks whether the given url starts with a supported protocol */
bool isURL(const QCString &url)
{
QCString loc_url = url.stripWhiteSpace();
return loc_url.left(5)=="http:" || loc_url.left(6)=="https:" ||
loc_url.left(4)=="ftp:" || loc_url.left(5)=="file:";
}
/** Corrects URL \a url according to the relative path \a relPath.
* Returns the corrected URL. For absolute URLs no correction will be done.
*/
QCString correctURL(const QCString &url,const QCString &relPath)
{
QCString result = url;
if (!relPath.isEmpty() &&
url.left(5)!="http:" && url.left(6)!="https:" &&
url.left(4)!="ftp:" && url.left(5)!="file:")
if (!relPath.isEmpty() && !isURL(url))
{
result.prepend(relPath);
}
Expand Down
2 changes: 2 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,8 @@ bool copyFile(const QCString &src,const QCString &dest);
QCString extractBlock(const QCString text,const QCString marker);
int lineBlock(const QCString text,const QCString marker);

bool isURL(const QCString &url);

QCString correctURL(const QCString &url,const QCString &relPath);

QCString processMarkup(const QCString &s);
Expand Down

0 comments on commit 6441903

Please sign in to comment.