Merge pull request #3290 from rcurtin/fix-sidebar-anchors
Fix Markdown sidebar anchors
This commit is contained in:
@@ -24,8 +24,6 @@ set(SOURCES
|
||||
"binding_info.hpp"
|
||||
"binding_info.cpp"
|
||||
"default_param.hpp"
|
||||
"get_binding_name.hpp"
|
||||
"get_binding_name.cpp"
|
||||
"get_param.hpp"
|
||||
"get_printable_param.hpp"
|
||||
"get_printable_param_name.hpp"
|
||||
@@ -208,8 +206,6 @@ function (post_markdown_setup)
|
||||
"${BINDING_SOURCE_DIR}/binding_info.hpp"
|
||||
"${BINDING_SOURCE_DIR}/binding_info.cpp"
|
||||
"${BINDING_SOURCE_DIR}/default_param.hpp"
|
||||
"${BINDING_SOURCE_DIR}/get_binding_name.hpp"
|
||||
"${BINDING_SOURCE_DIR}/get_binding_name.cpp"
|
||||
"${BINDING_SOURCE_DIR}/get_param.hpp"
|
||||
"${BINDING_SOURCE_DIR}/get_printable_param.hpp"
|
||||
"${BINDING_SOURCE_DIR}/get_printable_param_name.hpp"
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "generate_markdown.${BINDING}.hpp"
|
||||
#include "binding_info.hpp"
|
||||
#include "print_docs.hpp"
|
||||
#include "get_binding_name.hpp"
|
||||
|
||||
${INCLUDE_MAIN_FILES}
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#define MLPACK_BINDINGS_MARKDOWN_GENERATE_MARKDOWN_${BINDING}_HPP
|
||||
|
||||
#include "print_docs.hpp"
|
||||
#include "get_binding_name.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/**
|
||||
* @file bindings/markdown/get_binding_name.cpp
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Given the name of a binding as it appears in CMake, return the corresponding
|
||||
* name of the binding that is generated for a given language.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#include "get_binding_name.hpp"
|
||||
|
||||
namespace mlpack {
|
||||
namespace bindings {
|
||||
namespace markdown {
|
||||
|
||||
std::string GetBindingName(const std::string& language,
|
||||
const std::string& name)
|
||||
{
|
||||
// Unfortunately, every time a new binding is added, this code will need to be
|
||||
// modified.
|
||||
if (language == "cli")
|
||||
{
|
||||
// For command-line programs, all bindings have 'mlpack_' prepended to the
|
||||
// name.
|
||||
return "mlpack_" + name;
|
||||
}
|
||||
else if (language == "python")
|
||||
{
|
||||
// For Python bindings, the name is unchanged.
|
||||
return name;
|
||||
}
|
||||
else if (language == "julia")
|
||||
{
|
||||
// For Julia bindings, the name is unchanged.
|
||||
return name;
|
||||
}
|
||||
else if (language == "go")
|
||||
{
|
||||
// For Go bindings, the name is unchanged.
|
||||
return name;
|
||||
}
|
||||
else if (language == "r")
|
||||
{
|
||||
// For R bindings, the name is unchanged.
|
||||
return name;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::invalid_argument("Don't know how to compute binding name for "
|
||||
"language \"" + language + "\"! Is the language specified in "
|
||||
"src/mlpack/bindings/markdown/get_binding_name.cpp?");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace markdown
|
||||
} // namespace bindings
|
||||
} // namespace mlpack
|
||||
@@ -1,35 +0,0 @@
|
||||
/**
|
||||
* @file bindings/markdown/get_binding_name.hpp
|
||||
* @author Ryan Curtin
|
||||
*
|
||||
* Given the name of a binding as it appears in CMake, return the corresponding
|
||||
* name of the binding that is generated for a given language.
|
||||
*
|
||||
* mlpack is free software; you may redistribute it and/or modify it under the
|
||||
* terms of the 3-clause BSD license. You should have received a copy of the
|
||||
* 3-clause BSD license along with mlpack. If not, see
|
||||
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
|
||||
*/
|
||||
#ifndef MLPACK_BINDINGS_MARKDOWN_GET_BINDING_NAME_HPP
|
||||
#define MLPACK_BINDINGS_MARKDOWN_GET_BINDING_NAME_HPP
|
||||
|
||||
#include <mlpack/prereqs.hpp>
|
||||
|
||||
namespace mlpack {
|
||||
namespace bindings {
|
||||
namespace markdown {
|
||||
|
||||
/**
|
||||
* Given a language name and a binding name, return the name of that binding for
|
||||
* that language. Note that if a new language is added to the mlpack bindings,
|
||||
* this method will need to be updated so that documentation can be successfully
|
||||
* generated for that language.
|
||||
*/
|
||||
std::string GetBindingName(const std::string& language,
|
||||
const std::string& name);
|
||||
|
||||
} // namespace markdown
|
||||
} // namespace bindings
|
||||
} // namespace mlpack
|
||||
|
||||
#endif
|
||||
@@ -45,24 +45,17 @@ void PrintHeaders(const string& bindingName,
|
||||
|
||||
// Get the name of the binding in the target language, and convert it to
|
||||
// lowercase (since the anchor link will be in lowercase).
|
||||
const string langBindingName =
|
||||
const string langBindingName =
|
||||
addWrapperDocs[i] ? GetWrapperName(bindingName) :
|
||||
GetBindingName(bindingName);
|
||||
|
||||
string anchorName = GetBindingName(bindingName);
|
||||
transform(anchorName.begin(), anchorName.end(), anchorName.begin(),
|
||||
[](unsigned char c) { return tolower(c); });
|
||||
// Strip '()' from the end if needed.
|
||||
if (anchorName.substr(anchorName.size() - 2, 2) == "()")
|
||||
anchorName = anchorName.substr(0, anchorName.size() - 2);
|
||||
|
||||
cout << " - [" << langBindingName << "](#" << languages[i]
|
||||
<< "_";
|
||||
|
||||
if (addWrapperDocs[i])
|
||||
cout << GetWrapperLink(bindingName);
|
||||
else
|
||||
cout << anchorName;
|
||||
cout << bindingName;
|
||||
|
||||
cout << "){: .language-link #" << languages[i] << " }"
|
||||
<< endl;
|
||||
|
||||
Reference in New Issue
Block a user