Skip to content

Commit

Permalink
Add options for hard and soft break (implements #102)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-gromeyer committed May 31, 2024
1 parent 44f3c8c commit e9d3bee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
17 changes: 16 additions & 1 deletion include/html2md.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,23 @@ namespace html2md {
struct Options {
/*!
* \brief Add new line when a certain number of characters is reached
*
* \see softBreak
* \see hardBreak
*/
bool splitLines = true;

/*!
* \brief softBreak Wrap after ... characters when the next space is reached
* and as long as it's not in a list, table, image or anchor (link).
*/
int softBreak = 80;

/*!
* \brief hardBreak Force a break after ... characters in a line
*/
int hardBreak = 100;

/*!
* \brief The char used for unordered lists
*
Expand Down Expand Up @@ -94,7 +108,8 @@ struct Options {

inline bool operator==(html2md::Options o) const {
return splitLines == o.splitLines && unorderedList == o.unorderedList &&
orderedList == o.orderedList && includeTitle == o.includeTitle;
orderedList == o.orderedList && includeTitle == o.includeTitle &&
softBreak == o.softBreak && hardBreak == o.hardBreak;
};
};

Expand Down
4 changes: 2 additions & 2 deletions src/html2md.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,13 +514,13 @@ bool Converter::ParseCharInTagContent(char ch) {
break;
}

if (chars_in_curr_line_ > 80 && !is_in_table_ && !is_in_list_ &&
if (chars_in_curr_line_ > option.softBreak && !is_in_table_ && !is_in_list_ &&
current_tag_ != kTagImg && current_tag_ != kTagAnchor &&
option.splitLines) {
if (ch == ' ') { // If the next char is - it will become a list
md_ += '\n';
chars_in_curr_line_ = 0;
} else if (chars_in_curr_line_ > 100) {
} else if (chars_in_curr_line_ > option.hardBreak) {
ReplacePreviousSpaceInLineByNewline();
}
}
Expand Down

0 comments on commit e9d3bee

Please sign in to comment.