Skip to content

Commit

Permalink
Prepare v1.4.0, see CHANGELOG.md for details
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-gromeyer committed Jan 11, 2023
1 parent 2446602 commit 271f51c
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 36 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

[TOC]

## v1.4.0

- Improved CMake support massively!
- Fixed tests
- Added support for CMake 3.8
- Fix Python source package

## v1.3.0

**BREAKING CHANGES!**
Expand Down
59 changes: 42 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
cmake_minimum_required(VERSION 3.12)
project("html2md" VERSION 1.3.0
DESCRIPTION "Transform your HTML into clean, easy-to-read markdown with html2md"
HOMEPAGE_URL "https://tim-gromeyer.github.io/html2md/"
LANGUAGES CXX)

# Build type
if (NOT CMAKE_BUILD_TYPE)
cmake_minimum_required(VERSION 3.8)
project(html2md VERSION 1.4.0
LANGUAGES CXX)

set(PROJECT_HOMEPAGE_URL "https://tim-gromeyer.github.io/html2md/")
set(html2md_HOMEPAGE_URL "${PROJECT_HOMEPAGE_URL}")

set(PROJECT_DESCRIPTION "Transform your HTML into clean, easy-to-read markdown with html2md")
set(html2md_DESCRIPTION "${PROJECT_DESCRIPTION}")

# If build type not specified we use release
if (NOT DEFINED CMAKE_BUILD_TYPE)
message(STATUS "Build type not specified. Release is used.")
set(CMAKE_BUILD_TYPE "Release")
else()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
endif()

# Improve performance
Expand All @@ -18,7 +20,7 @@ if(CMAKE_BUILD_TYPE STREQUAL "Release")
string(REPLACE "-O2" "-O3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()

# Check if it was included
# Check if it was included via `add_subdirectory`
get_directory_property(subproject PARENT_DIRECTORY)

# Create HTML for webassembly
Expand All @@ -29,11 +31,10 @@ endif()
# Some options
if (subproject)
option(BUILD_EXE "Build a executable to convert html to markdown." OFF)
option(BUILD_DOC "Build documentation" OFF)
else()
option(BUILD_EXE "Build a executable to convert html to markdown." ON)
option(BUILD_DOC "Build documentation" ON)
endif()
option(BUILD_DOC "Build documentation" OFF)
option(BUILD_TEST "Build tests" OFF)
option(PYTHON_BINDINGS "Build python bindings" OFF)

Expand Down Expand Up @@ -90,17 +91,41 @@ if(subproject)
endif()

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

install(TARGETS html2md
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/html2md
EXPORT html2mdTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/html2md
)
install(EXPORT html2mdTargets
FILE html2mdTargets.cmake
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/html2md"
)

configure_file(html2md.pc.in html2md.pc @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/html2md.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)

write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)

configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/html2md
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)

install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/html2md
)

if (BUILD_EXE)
install(TARGETS html2md-exe DESTINATION bin)
endif()
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include python/README.md COPYING python/pybind11/LICENSE python/pybind11/CMakeLists.txt CMakeLists.txt
include python/README.md COPYING python/pybind11/LICENSE python/pybind11/CMakeLists.txt CMakeLists.txt python/bindings.cpp
graft python/pybind11/include
graft python/pybind11/tools
graft src
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ html2md is a fast and reliable C++ library for converting HTML content into mark

## How to use this library

### CMake

Install html2md. Use eighter the prebild packages from [GitHub releases](https://github.com/tim-gromeyer/html2md/releases) or build and install it yourself.

Afterwards:

```cmake
find_package(html2md)
target_link_library(your_target PRIVATE html2md)
```

### Manually

To use html2md, follow these steps:

1. Clone the library: `git clone https://github.com/tim-gromeyer/html2md`
Expand Down
1 change: 0 additions & 1 deletion cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ int main(int argc, const char* argv[]) {
continue;
}
}

}

fstream out;
Expand Down
14 changes: 14 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ html2md is a fast and reliable C++ library for converting HTML content into mark

## How to use this library

### CMake

Install html2md. Either use the pre-built packages found on [GitHub releases](https://github.com/tim-gromeyer/html2md/releases) or build and install it yourself.


Afterwards:

```cmake
find_package(html2md)
target_link_library(your_target PRIVATE html2md)
```

### Manually

To use html2md, follow these steps:

1. Clone the library: `git clone https://github.com/tim-gromeyer/html2md`
Expand Down
6 changes: 6 additions & 0 deletions html2mdConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")

set(@PROJECT_NAME@_FOUND TRUE)

2 changes: 1 addition & 1 deletion include/html2md.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ class Converter {

std::map<std::string, Tag*> tags_;

explicit Converter(std::string *html, Options *options = nullptr);
explicit Converter(std::string *html, struct Options *options = nullptr);

void PrepareHtml();

Expand Down
6 changes: 0 additions & 6 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ You can install using pip:
pip3 install pyhtml2md
```

### Manually

1. Make sure you have a compiler with c++11 and CMake installed on you system
2. Clone html2md: `git clone https://github.com/tim-gromeyer/html2md --recurse-submodules --depth=1`
3. Build and install the python package: `pip3 install ./html2md/`

## Basic usage

Here is an example of how to use the pyhtml2md to convert HTML to markdown:
Expand Down
5 changes: 1 addition & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ def build_extension(self, ext: CMakeExtension) -> None:
if "CMAKE_ARGS" in os.environ:
cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item]

# In this example, we pass in the version to C++. You might not need to.
cmake_args += [f"-DEXAMPLE_VERSION_INFO={self.distribution.get_version()}"] # type: ignore[attr-defined]

if self.compiler.compiler_type != "msvc":
# Using Ninja-build since it a) is available as a wheel and b)
# multithreads automatically. MSVC would require all variables be
Expand Down Expand Up @@ -133,7 +130,7 @@ def build_extension(self, ext: CMakeExtension) -> None:
# logic and declaration, and simpler if you include description/version in a file.
setup(
name="pyhtml2md",
version="1.3.0",
version="1.4.0",
author="Tim Gromeyer",
author_email="[email protected]",
description="Transform your HTML into clean, easy-to-read markdown with pyhtml2md.",
Expand Down
2 changes: 1 addition & 1 deletion src/html2md.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static string Repeat(const string &str, size_t amount) {
namespace html2md {

Converter::Converter(string *html, Options *options)
: html_(*html), option(options) {
: html_(*html) {
options ? option = options
: option = new struct Options();

Expand Down
5 changes: 5 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ target_compile_definitions(test-exe PUBLIC DIR="${CMAKE_CURRENT_LIST_DIR}")
set_target_properties(test-exe PROPERTIES OUTPUT_NAME "tests")
target_compile_features(test-exe PUBLIC cxx_std_17) # Require at least c++17


if (CMAKE_VERSION VERSION_LESS 3.11.0)
return()
endif()

add_custom_target(test
COMMAND $<TARGET_FILE:test-exe>
COMMENT Runing tests..
Expand Down
10 changes: 6 additions & 4 deletions tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ string toHTML(const string &md) {
};

string fromHTML(string &html) {
html2md::options options;
static html2md::Options options;
options.splitLines = false;

html2md::Converter c(html, &options);
return c.Convert2Md();
return c.convert();
}
}

Expand Down Expand Up @@ -102,7 +102,7 @@ void runTest(const string& file, short *errorCount) {
}
}

int main(int argc, char **argv){
int main(int argc, const char **argv){
// List to store all markdown files in this dir
vector<string> files;

Expand Down Expand Up @@ -132,7 +132,9 @@ int main(int argc, char **argv){

// Redirect errors to error.log
FILE* errorFile = freopen(errorFileName, "w", stderr);
if (errorFile) {}
if (!errorFile)
cerr << "Failed to open " << errorFileName << " for whatever reason!\n"
"Errors will be printed to the terminal instead of written to the mentioned file above.";

// For measuring time.
auto t1 = high_resolution_clock::now();
Expand Down

0 comments on commit 271f51c

Please sign in to comment.